Moved inline/llvm/Tools/* to include/llvm/Support/*
[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/CodeGen/Sparc.h"
20 #include "llvm/Support/CommandLine.h"
21
22 cl::String InputFilename ("", "Input filename", cl::NoFlags, "");
23 cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
24
25 static bool CompileModule(Module *module, TargetMachine &Target) {
26   bool failed = false;
27   
28   for (Module::MethodListType::const_iterator
29          methodIter = module->getMethodList().begin();
30        methodIter != module->getMethodList().end();
31        ++methodIter)
32     {
33       Method* method = *methodIter;
34       
35       if (SelectInstructionsForMethod(method, Target))
36         {
37           failed = true;
38           cerr << "Instruction selection failed for method "
39                << method->getName() << "\n\n";
40         }
41     }
42   
43   return failed;
44 }
45
46
47 //---------------------------------------------------------------------------
48 // Function main()
49 // 
50 // Entry point for the driver.
51 //---------------------------------------------------------------------------
52
53 int main(int argc, char** argv) {
54   cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
55   UltraSparc Target;
56
57   Module *module = ParseBytecodeFile(InputFilename.getValue());
58   if (module == 0) {
59     cerr << "bytecode didn't read correctly.\n";
60     return 1;
61   }
62   
63   bool failure = CompileModule(module, Target);
64   
65   if (failure) {
66       cerr << "Error compiling "
67            << InputFilename.getValue() << "!\n";
68       delete module;
69       return 1;
70     }
71   
72   // Okay, we're done now... write out result...
73   // WriteBytecodeToFile(module, 
74   //                  OutputFilename.getValue());
75   
76   // Clean up and exit
77   delete module;
78   return 0;
79 }