"expr -i" now performs the required transforms to
prepare the IR for JIT compilation. We still need
to do the JIT compilation and move the arguments
in/out of target memory.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@108279 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangExpression.cpp b/source/Expression/ClangExpression.cpp
index 2383fae..1403366 100644
--- a/source/Expression/ClangExpression.cpp
+++ b/source/Expression/ClangExpression.cpp
@@ -50,6 +50,7 @@
#include "llvm/System/DynamicLibrary.h"
#include "llvm/System/Host.h"
#include "llvm/System/Signals.h"
+#include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetSelect.h"
// Project includes
@@ -240,6 +241,9 @@
m_clang_ap->getLangOpts().CPlusPlus = true;
m_clang_ap->getLangOpts().ObjC1 = true;
m_clang_ap->getLangOpts().ThreadsafeStatics = false;
+
+ // Set CodeGen options
+ m_clang_ap->getCodeGenOpts().EmitDeclMetadata = true;
// Disable some warnings.
m_clang_ap->getDiagnosticOpts().Warnings.push_back("no-unused-value");
@@ -250,7 +254,6 @@
// 3. Set up various important bits of infrastructure.
m_clang_ap->createDiagnostics(0, 0);
- m_clang_ap->getLangOpts().CPlusPlus = true;
// Create the target instance.
m_clang_ap->setTarget(TargetInfo::CreateTargetInfo(m_clang_ap->getDiagnostics(),
@@ -294,7 +297,7 @@
{
// HACK: for now we have to make a function body around our expression
// since there is no way to parse a single expression line in LLVM/Clang.
- std::string func_expr("extern \"C\" void ___clang_expr()\n{\n\t");
+ std::string func_expr("extern \"C\" void ___clang_expr(void *___clang_arg)\n{\n\t");
func_expr.append(expr_text);
func_expr.append(";\n}");
return ParseBareExpression (func_expr, stream, add_result_var);
@@ -513,7 +516,23 @@
return 1;
}
- IRForTarget ir_for_target("IR for target", m_decl_map);
+ llvm::Triple target_triple = m_clang_ap->getTarget().getTriple();
+
+ std::string err;
+
+ const llvm::Target *target = llvm::TargetRegistry::lookupTarget(m_target_triple, err);
+
+ if (!target)
+ {
+ if (log)
+ log->Printf("Couldn't find a target for %s", m_target_triple.c_str());
+
+ return 1;
+ }
+
+ std::auto_ptr<llvm::TargetMachine> target_machine(target->createTargetMachine(m_target_triple, ""));
+
+ IRForTarget ir_for_target("IR for target", m_decl_map, target_machine->getTargetData());
return ir_for_target.runOnModule(*module);
}