1 //===-- JIT.cpp - LLVM Just in Time Compiler ------------------------------===//
3 // This file implements the top-level support for creating a Just-In-Time
4 // compiler for the current architecture.
6 //===----------------------------------------------------------------------===//
9 #include "llvm/Target/TargetMachine.h"
10 #include "llvm/Target/TargetMachineImpls.h"
11 #include "llvm/Module.h"
14 /// createJIT - Create an return a new JIT compiler if there is one available
15 /// for the current target. Otherwise it returns null.
17 ExecutionEngine *ExecutionEngine::createJIT(Module *M, unsigned Config) {
18 // FIXME: This should be controlled by which subdirectory gets linked in!
19 #if !defined(i386) && !defined(__i386__) && !defined(__x86__)
22 // Allocate a target... in the future this will be controllable on the
24 TargetMachine *Target = allocateX86TargetMachine(Config);
25 assert(Target && "Could not allocate X86 target machine!");
27 // Create the virtual machine object...
28 return new VM(M, Target);
31 VM::VM(Module *M, TargetMachine *tm) : ExecutionEngine(M), TM(*tm) {
32 setTargetData(TM.getTargetData());
33 MCE = createEmitter(*this); // Initialize MCE
38 int VM::run(const std::string &FnName, const std::vector<std::string> &Args) {
39 Function *F = getModule().getNamedFunction(FnName);
41 std::cerr << "Could not find function '" << FnName <<"' in module!\n";
45 int(*PF)(int, char**) = (int(*)(int, char**))getPointerToFunction(F);
46 assert(PF != 0 && "Null pointer to function?");
48 // Build an argv vector...
49 char **Argv = (char**)CreateArgv(Args);
51 // Call the main function...
52 return PF(Args.size(), Argv);