C++ gives us auto_ptr's, so we might as well use them. :)
[oota-llvm.git] / tools / llc / llc.cpp
1 //===-- llc.cpp - Implement the LLVM Compiler ----------------------------===//
2 //
3 // This is the llc compiler driver.
4 //
5 //===---------------------------------------------------------------------===//
6
7 #include "llvm/Bytecode/Reader.h"
8 #include "llvm/Optimizations/Normalize.h"
9 #include "llvm/Target/Sparc.h"
10 #include "llvm/Target/TargetMachine.h"
11 #include "llvm/Support/CommandLine.h"
12 #include "llvm/Module.h"
13 #include "llvm/Method.h"
14 #include <memory>
15
16 cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
17 cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
18
19
20 //-------------------------- Internal Functions -----------------------------//
21
22 static void NormalizeMethod(Method* method) {
23   NormalizePhiConstantArgs(method);
24 }
25
26
27 //===---------------------------------------------------------------------===//
28 // Function main()
29 // 
30 // Entry point for the llc compiler.
31 //===---------------------------------------------------------------------===//
32
33 int main(int argc, char **argv) {
34   // Parse command line options...
35   cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
36
37   // Allocate a target... in the future this will be controllable on the
38   // command line.
39   auto_ptr<TargetMachine> Target(allocateSparcTargetMachine());
40
41   // Load the module to be compiled...
42   auto_ptr<Module> M(ParseBytecodeFile(InputFilename));
43   if (M.get() == 0) {
44     cerr << "bytecode didn't read correctly.\n";
45     return 1;
46   }
47
48   // Loop over all of the methods in the module, compiling them.
49   for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
50     Method *Meth = *MI;
51     
52     NormalizeMethod(Meth);
53     
54     if (Target.get()->compileMethod(Meth)) {
55       cerr << "Error compiling " << InputFilename << "!\n";
56       return 1;
57     }
58   }
59   
60   return 0;
61 }
62
63