aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lli/OrcLazyJIT.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lli/OrcLazyJIT.cpp')
-rw-r--r--tools/lli/OrcLazyJIT.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/lli/OrcLazyJIT.cpp b/tools/lli/OrcLazyJIT.cpp
new file mode 100644
index 0000000..4a8d3b9
--- /dev/null
+++ b/tools/lli/OrcLazyJIT.cpp
@@ -0,0 +1,53 @@
+//===------ OrcLazyJIT.cpp - Basic Orc-based JIT for lazy execution -------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "OrcLazyJIT.h"
+#include "llvm/ExecutionEngine/Orc/OrcTargetSupport.h"
+
+using namespace llvm;
+
+std::unique_ptr<OrcLazyJIT::CompileCallbackMgr>
+OrcLazyJIT::createCallbackMgr(Triple T, LLVMContext &Context) {
+ switch (T.getArch()) {
+ default:
+ // Flag error.
+ Error = true;
+ return nullptr;
+
+ case Triple::x86_64: {
+ typedef orc::JITCompileCallbackManager<CompileLayerT,
+ orc::OrcX86_64> CCMgrT;
+ return make_unique<CCMgrT>(CompileLayer, Context, 0, 64);
+ }
+ }
+}
+
+int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) {
+ OrcLazyJIT J(std::unique_ptr<TargetMachine>(EngineBuilder().selectTarget()),
+ getGlobalContext());
+
+ if (!J.Ok()) {
+ errs() << "Could not construct JIT.\n";
+ return 1;
+ }
+
+ auto MainHandle = J.addModule(std::move(M));
+ auto MainSym = J.findSymbolIn(MainHandle, "main");
+
+ if (!MainSym) {
+ errs() << "Could not find main function.\n";
+ return 1;
+ }
+
+ typedef int (*MainFnPtr)(int, char*[]);
+ auto Main = reinterpret_cast<MainFnPtr>(
+ static_cast<uintptr_t>(MainSym.getAddress()));
+
+ return Main(ArgC, ArgV);
+}