Return 0 instead of 1 for correct execution. Makes automated testing happy.
[oota-llvm.git] / tools / jello / jello.cpp
1 //===-- jello.cpp - LLVM Just in Time Compiler ----------------------------===//
2 //
3 // This tool implements a just-in-time compiler for LLVM, allowing direct
4 // execution of LLVM bytecode in an efficient manner.
5 //
6 // FIXME: This code will get more object oriented as we get the call back
7 // intercept stuff implemented.
8 //
9 //===----------------------------------------------------------------------===//
10
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"
18
19 namespace {
20   cl::opt<std::string>
21   InputFile(cl::desc("<input bytecode>"), cl::Positional, cl::init("-"));
22
23   cl::opt<std::string>
24   MainFunction("f", cl::desc("Function to execute"), cl::init("main"),
25                cl::value_desc("function name"));
26 }
27
28 //===----------------------------------------------------------------------===//
29 // main Driver function
30 //
31 int main(int argc, char **argv) {
32   cl::ParseCommandLineOptions(argc, argv, " llvm just in time compiler\n");
33
34   // Allocate a target... in the future this will be controllable on the
35   // command line.
36   std::auto_ptr<TargetMachine> target(allocateX86TargetMachine());
37   assert(target.get() && "Could not allocate target machine!");
38
39   TargetMachine &Target = *target.get();
40
41   // Parse the input bytecode file...
42   std::string ErrorMsg;
43   std::auto_ptr<Module> M(ParseBytecodeFile(InputFile, &ErrorMsg));
44   if (M.get() == 0) {
45     std::cerr << argv[0] << ": bytecode '" << InputFile
46               << "' didn't read correctly: << " << ErrorMsg << "\n";
47     return 1;
48   }
49
50   PassManager Passes;
51   if (Target.addPassesToJITCompile(Passes)) {
52     std::cerr << argv[0] << ": target '" << Target.getName()
53               << "' doesn't support JIT compilation!\n";
54     return 1;
55   }
56
57   // JIT all of the methods in the module.  Eventually this will JIT functions
58   // on demand.
59   Passes.run(*M.get());
60   
61   return 0;
62 }
63