4bf26d5a16f7ddb934d1d12c13ee96a5df37387a
[oota-llvm.git] / tools / llc / llc.cpp
1 // $Id$
2 //***************************************************************************
3 // File:
4 //      llc.cpp
5 // 
6 // Purpose:
7 //      Driver for llc compiler.
8 // 
9 // History:
10 //      7/15/01  -  Vikram Adve  -  Created
11 // 
12 //**************************************************************************/
13
14 #include "llvm/Module.h"
15 #include "llvm/Method.h"
16 #include "llvm/Bytecode/Reader.h"
17 #include "llvm/Bytecode/Writer.h"
18 #include "llvm/CodeGen/InstrSelection.h"
19 #include "llvm/LLC/CompileContext.h"
20 #include "llvm/CodeGen/Sparc.h"
21 #include "LLCOptions.h"
22
23 CompileContext::~CompileContext() { delete targetMachine; }
24
25 static bool CompileModule(Module *module, CompileContext& ccontext,
26                           LLCOptions &Options) {
27   bool failed = false;
28   
29   for (Module::MethodListType::const_iterator
30          methodIter = module->getMethodList().begin();
31        methodIter != module->getMethodList().end();
32        ++methodIter)
33     {
34       Method* method = *methodIter;
35       
36       if (SelectInstructionsForMethod(method, ccontext, 
37                            Options.IntOptionValue(DEBUG_INSTR_SELECT_OPT)))
38         {
39           failed = true;
40           cerr << "Instruction selection failed for method "
41                << method->getName() << "\n\n";
42         }
43     }
44   
45   return failed;
46 }
47
48
49 //---------------------------------------------------------------------------
50 // Function main()
51 // 
52 // Entry point for the driver.
53 //---------------------------------------------------------------------------
54
55 int main(int argc, const char** argv, const char** envp) {
56   LLCOptions Options(argc, argv, envp);
57   CompileContext compileContext(new UltraSparc());
58   
59   Module *module = ParseBytecodeFile(Options.getInputFileName());
60   if (module == 0) {
61     cerr << "bytecode didn't read correctly.\n";
62     return 1;
63   }
64   
65   bool failure = CompileModule(module, compileContext, Options);
66   
67   if (failure) {
68       cerr << "Error compiling "
69            << Options.getInputFileName() << "!\n";
70       delete module;
71       return 1;
72     }
73   
74   // Okay, we're done now... write out result...
75   // WriteBytecodeToFile(module, 
76   //                  compileContext.getOptions().getOutputFileName);
77   
78   // Clean up and exit
79   delete module;
80   return 0;
81 }