1 //===-- jello.cpp - LLVM Just in Time Compiler ----------------------------===//
3 // This tool implements a just-in-time compiler for LLVM, allowing direct
4 // execution of LLVM bytecode in an efficient manner.
6 // FIXME: This code will get more object oriented as we get the call back
7 // intercept stuff implemented.
9 //===----------------------------------------------------------------------===//
11 #include "llvm/Module.h"
12 #include "llvm/PassManager.h"
13 #include "llvm/Bytecode/Reader.h"
14 #include "llvm/Target/TargetMachine.h"
15 #include "llvm/Target/TargetMachineImpls.h"
16 #include "Support/CommandLine.h"
17 #include "Support/Statistic.h"
21 InputFile(cl::desc("<input bytecode>"), cl::Positional, cl::init("-"));
24 MainFunction("f", cl::desc("Function to execute"), cl::init("main"),
25 cl::value_desc("function name"));
28 //===----------------------------------------------------------------------===//
29 // main Driver function
31 int main(int argc, char **argv) {
32 cl::ParseCommandLineOptions(argc, argv, " llvm just in time compiler\n");
34 // Allocate a target... in the future this will be controllable on the
36 std::auto_ptr<TargetMachine> target(allocateX86TargetMachine());
37 assert(target.get() && "Could not allocate target machine!");
39 TargetMachine &Target = *target.get();
41 // Parse the input bytecode file...
43 std::auto_ptr<Module> M(ParseBytecodeFile(InputFile, &ErrorMsg));
45 std::cerr << argv[0] << ": bytecode '" << InputFile
46 << "' didn't read correctly: << " << ErrorMsg << "\n";
51 if (Target.addPassesToJITCompile(Passes)) {
52 std::cerr << argv[0] << ": target '" << Target.getName()
53 << "' doesn't support JIT compilation!\n";
57 // JIT all of the methods in the module. Eventually this will JIT functions