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