This checkin represents some cleanup of the backend, implementing the following things:
[oota-llvm.git] / tools / llc / llc.cpp
1 //===------------------------------------------------------------------------===
2 // LLVM 'LLC' UTILITY 
3 //
4 // This is the llc compiler driver.
5 //
6 //===------------------------------------------------------------------------===
7
8 #include "llvm/Bytecode/Reader.h"
9 #include "llvm/Optimizations/Normalize.h"
10 #include "llvm/CodeGen/Sparc.h"
11 #include "llvm/Support/CommandLine.h"
12 #include "llvm/Module.h"
13 #include "llvm/Method.h"
14
15 cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
16 cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
17
18 static void NormalizeMethod(Method* method) {
19   NormalizePhiConstantArgs(method);
20 }
21
22
23 static bool CompileModule(Module *M, TargetMachine &Target) {
24   for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
25     Method *Meth = *MI;
26       
27     NormalizeMethod(Meth);
28       
29     if (Target.compileMethod(Meth)) return true;
30   }
31   
32   return false;
33 }
34
35
36
37 //---------------------------------------------------------------------------
38 // Function main()
39 // 
40 // Entry point for the llc compiler.
41 //---------------------------------------------------------------------------
42
43 int main(int argc, char** argv) {
44   cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
45   UltraSparc Target;
46   
47   Module *module = ParseBytecodeFile(InputFilename);
48   if (module == 0) {
49     cerr << "bytecode didn't read correctly.\n";
50     return 1;
51   }
52
53   if (CompileModule(module, Target)) {
54     cerr << "Error compiling " << InputFilename << "!\n";
55     delete module;
56     return 1;
57   }
58   
59   // Clean up and exit
60   delete module;
61   return 0;
62 }
63