diff options
author | Chris Lattner <sabre@nondot.org> | 2002-12-24 00:01:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-12-24 00:01:05 +0000 |
commit | bd199fb1148b9e16c4e6f3d0ee386c2505a55b71 (patch) | |
tree | 226f64cc95160ebd8da8d2ec4cfaf2babf7c3879 /lib/ExecutionEngine/JIT/JIT.cpp | |
parent | fe11a97fcde7c63109c3ad36570657807d0cd6ef (diff) |
Initial checkin of new LLI with JIT compiler
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5126 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/JIT/JIT.cpp')
-rw-r--r-- | lib/ExecutionEngine/JIT/JIT.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp new file mode 100644 index 0000000000..b2b56a63e5 --- /dev/null +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -0,0 +1,53 @@ +//===-- JIT.cpp - LLVM Just in Time Compiler ------------------------------===// +// +// This file implements the top-level support for creating a Just-In-Time +// compiler for the current architecture. +// +//===----------------------------------------------------------------------===// + +#include "VM.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetMachineImpls.h" +#include "llvm/Module.h" + + +/// createJIT - Create an return a new JIT compiler if there is one available +/// for the current target. Otherwise it returns null. +/// +ExecutionEngine *ExecutionEngine::createJIT(Module *M, unsigned Config) { + // FIXME: This should be controlled by which subdirectory gets linked in! +#if !defined(i386) && !defined(__i386__) && !defined(__x86__) + return 0; +#endif + // Allocate a target... in the future this will be controllable on the + // command line. + TargetMachine *Target = allocateX86TargetMachine(Config); + assert(Target && "Could not allocate X86 target machine!"); + + // Create the virtual machine object... + return new VM(M, Target); +} + +VM::VM(Module *M, TargetMachine *tm) : ExecutionEngine(M), TM(*tm) { + setTargetData(TM.getTargetData()); + MCE = createEmitter(*this); // Initialize MCE + setupPassManager(); + registerCallback(); +} + +int VM::run(const std::string &FnName, const std::vector<std::string> &Args) { + Function *F = getModule().getNamedFunction(FnName); + if (F == 0) { + std::cerr << "Could not find function '" << FnName <<"' in module!\n"; + return 1; + } + + int(*PF)(int, char**) = (int(*)(int, char**))getPointerToFunction(F); + assert(PF != 0 && "Null pointer to function?"); + + // Build an argv vector... + char **Argv = (char**)CreateArgv(Args); + + // Call the main function... + return PF(Args.size(), Argv); +} |