CommandLine library cleanup. No longer use getValue/setValue, instead, just treat...
[oota-llvm.git] / tools / llc / llc.cpp
index 4bf26d5a16f7ddb934d1d12c13ee96a5df37387a..a3312967d64942c85e79c5410aba57d9c646d737 100644 (file)
 #include "llvm/Module.h"
 #include "llvm/Method.h"
 #include "llvm/Bytecode/Reader.h"
-#include "llvm/Bytecode/Writer.h"
 #include "llvm/CodeGen/InstrSelection.h"
-#include "llvm/LLC/CompileContext.h"
 #include "llvm/CodeGen/Sparc.h"
-#include "LLCOptions.h"
+#include "llvm/Support/CommandLine.h"
 
-CompileContext::~CompileContext() { delete targetMachine; }
+cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
+cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
 
-static bool CompileModule(Module *module, CompileContext& ccontext,
-                         LLCOptions &Options) {
+static bool CompileModule(Module *M, TargetMachine &Target) {
   bool failed = false;
   
-  for (Module::MethodListType::const_iterator
-        methodIter = module->getMethodList().begin();
-       methodIter != module->getMethodList().end();
-       ++methodIter)
-    {
-      Method* method = *methodIter;
+  for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
+    Method * method = *MI;
       
-      if (SelectInstructionsForMethod(method, ccontext, 
-                          Options.IntOptionValue(DEBUG_INSTR_SELECT_OPT)))
-       {
-         failed = true;
-         cerr << "Instruction selection failed for method "
-              << method->getName() << "\n\n";
-       }
+    if (SelectInstructionsForMethod(method, Target)) {
+      failed = true;
+      cerr << "Instruction selection failed for method "
+          << method->getName() << "\n\n";
     }
+  }
   
   return failed;
 }
@@ -52,28 +44,21 @@ static bool CompileModule(Module *module, CompileContext& ccontext,
 // Entry point for the driver.
 //---------------------------------------------------------------------------
 
-int main(int argc, const char** argv, const char** envp) {
-  LLCOptions Options(argc, argv, envp);
-  CompileContext compileContext(new UltraSparc());
-  
-  Module *module = ParseBytecodeFile(Options.getInputFileName());
+int main(int argc, char** argv) {
+  cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
+  UltraSparc Target;
+
+  Module *module = ParseBytecodeFile(InputFilename);
   if (module == 0) {
     cerr << "bytecode didn't read correctly.\n";
     return 1;
   }
   
-  bool failure = CompileModule(module, compileContext, Options);
-  
-  if (failure) {
-      cerr << "Error compiling "
-          << Options.getInputFileName() << "!\n";
-      delete module;
-      return 1;
-    }
-  
-  // Okay, we're done now... write out result...
-  // WriteBytecodeToFile(module, 
-  //                 compileContext.getOptions().getOutputFileName);
+  if (CompileModule(module, Target)) {
+    cerr << "Error compiling " << InputFilename << "!\n";
+    delete module;
+    return 1;
+  }
   
   // Clean up and exit
   delete module;