mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-29 13:29:28 +00:00
use these to add support for C++ static ctors/dtors to the Orc-lazy JIT in LLI. Replace the trivial_retval_1 regression test - the new 'hello' test is covering strictly more code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233885 91177308-0d34-0410-b5e6-96231b3b80d8
70 lines
2.3 KiB
C++
70 lines
2.3 KiB
C++
//===------ 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"
|
|
#include "llvm/Support/DynamicLibrary.h"
|
|
|
|
using namespace llvm;
|
|
|
|
OrcLazyJIT::CallbackManagerBuilder
|
|
OrcLazyJIT::createCallbackManagerBuilder(Triple T) {
|
|
switch (T.getArch()) {
|
|
default: return nullptr;
|
|
|
|
case Triple::x86_64: {
|
|
typedef orc::JITCompileCallbackManager<CompileLayerT,
|
|
orc::OrcX86_64> CCMgrT;
|
|
return [](CompileLayerT &CompileLayer, RuntimeDyld::MemoryManager &MemMgr,
|
|
LLVMContext &Context) {
|
|
return make_unique<CCMgrT>(CompileLayer, MemMgr, Context, 0, 64);
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) {
|
|
// Add the program's symbols into the JIT's search space.
|
|
if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) {
|
|
errs() << "Error loading program symbols.\n";
|
|
return 1;
|
|
}
|
|
|
|
// Grab a target machine and try to build a factory function for the
|
|
// target-specific Orc callback manager.
|
|
auto TM = std::unique_ptr<TargetMachine>(EngineBuilder().selectTarget());
|
|
auto &Context = getGlobalContext();
|
|
auto CallbackMgrBuilder =
|
|
OrcLazyJIT::createCallbackManagerBuilder(Triple(TM->getTargetTriple()));
|
|
|
|
// If we couldn't build the factory function then there must not be a callback
|
|
// manager for this target. Bail out.
|
|
if (!CallbackMgrBuilder) {
|
|
errs() << "No callback manager available for target '"
|
|
<< TM->getTargetTriple() << "'.\n";
|
|
return 1;
|
|
}
|
|
|
|
// Everything looks good. Build the JIT.
|
|
OrcLazyJIT J(std::move(TM), Context, CallbackMgrBuilder);
|
|
|
|
// Add the module, look up main and run it.
|
|
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 = OrcLazyJIT::fromTargetAddress<MainFnPtr>(MainSym.getAddress());
|
|
return Main(ArgC, ArgV);
|
|
}
|