CommandLine library cleanup. No longer use getValue/setValue, instead, just treat...
[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/CodeGen/InstrSelection.h"
18 #include "llvm/CodeGen/Sparc.h"
19 #include "llvm/Support/CommandLine.h"
20
21 cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
22 cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
23
24 static bool CompileModule(Module *M, TargetMachine &Target) {
25   bool failed = false;
26   
27   for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
28     Method * method = *MI;
29       
30     if (SelectInstructionsForMethod(method, Target)) {
31       failed = true;
32       cerr << "Instruction selection failed for method "
33            << method->getName() << "\n\n";
34     }
35   }
36   
37   return failed;
38 }
39
40
41 //---------------------------------------------------------------------------
42 // Function main()
43 // 
44 // Entry point for the driver.
45 //---------------------------------------------------------------------------
46
47 int main(int argc, char** argv) {
48   cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
49   UltraSparc Target;
50
51   Module *module = ParseBytecodeFile(InputFilename);
52   if (module == 0) {
53     cerr << "bytecode didn't read correctly.\n";
54     return 1;
55   }
56   
57   if (CompileModule(module, Target)) {
58     cerr << "Error compiling " << InputFilename << "!\n";
59     delete module;
60     return 1;
61   }
62   
63   // Clean up and exit
64   delete module;
65   return 0;
66 }