Minor changes.
[oota-llvm.git] / tools / llc / llc.cpp
index 6ac3175f2b253fde5272ae88d888fb3b9549c986..73298edadee2fde3c6b28ff4b57b5de5e34e9086 100644 (file)
-// $Id$
-//***************************************************************************
-// File:
-//     llc.cpp
-// 
-// Purpose:
-//     Driver for llc compiler.
-// 
-// History:
-//     7/15/01  -  Vikram Adve  -  Created
-// 
-//**************************************************************************/
-
-//************************** System Include Files **************************/
-
-//*************************** User Include Files ***************************/
+//===-- llc.cpp - Implement the LLVM Compiler ----------------------------===//
+//
+// This is the llc compiler driver.
+//
+//===---------------------------------------------------------------------===//
 
+#include "llvm/Bytecode/Reader.h"
+#include "llvm/Optimizations/Normalize.h"
+#include "llvm/Target/Sparc.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
-#include "llvm/Bytecode/Reader.h"
-#include "llvm/Bytecode/Writer.h"
-#include "llvm/CodeGen/InstrForest.h"
-#include "llvm/CodeGen/InstrSelection.h"
-#include "llvm/LLC/LLCOptions.h"
-#include "llvm/LLC/CompileContext.h"
-
-//************************** Forward Declarations **************************/
 
-class Module;
-class CompileContext;
+cl::String InputFilename ("", "Input filename", cl::NoFlags, "-");
+cl::String OutputFilename("o", "Output filename", cl::NoFlags, "");
 
 
-static bool    CompileModule   (Module *module,
-                                CompileContext& compileContext);
+//-------------------------- Internal Functions -----------------------------//
 
-int DebugInstrSelectLevel = DEBUG_INSTR_TREES;
+static void
+NormalizeMethod(Method* method)
+{
+  NormalizePhiConstantArgs(method);
+}
 
 
-//---------------------------------------------------------------------------
+//===---------------------------------------------------------------------===//
 // Function main()
 // 
-// Entry point for the driver.
-//---------------------------------------------------------------------------
-
+// Entry point for the llc compiler.
+//===---------------------------------------------------------------------===//
 
 int
-main(int argc, const char** argv, const char** envp)
+main(int argc, char** argv)
 {
-  CompileContext compileContext(argc, argv, envp);
-  
-  Module *module =
-    ParseBytecodeFile(compileContext.getOptions().getInputFileName());
+  cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
+  TargetMachine *Target = allocateSparcTargetMachine();
   
-  if (module == 0) {
-    cerr << "bytecode didn't read correctly.\n";
-    return 1;
-  }
-  
-  bool failure = CompileModule(module, compileContext);
-  
-  if (failure)
+  Module *M = ParseBytecodeFile(InputFilename);
+  if (M == 0)
     {
-      cerr << "Error compiling "
-          << compileContext.getOptions().getInputFileName() << "!\n";
-      delete module;
+      cerr << "bytecode didn't read correctly.\n";
+      delete Target;
       return 1;
     }
-  
-  // Okay, we're done now... write out result...
-  // WriteBytecodeToFile(module, 
-  //                 compileContext.getOptions().getOutputFileName);
-  
-  // Clean up and exit
-  delete module;
-  return 0;
-}
 
-
-static bool
-CompileModule(Module *module,
-             CompileContext& ccontext)
-{
-  bool failed = false;
-  
-  for (Module::MethodListType::const_iterator
-        methodIter = module->getMethodList().begin();
-       methodIter != module->getMethodList().end();
-       ++methodIter)
+  bool Failed = false;
+  for (Module::const_iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
     {
-      Method* method = *methodIter;
-      
-      if (SelectInstructionsForMethod(method, ccontext))
+      Method *Meth = *MI;
+    
+      NormalizeMethod(Meth);
+    
+      if (Target->compileMethod(Meth))
        {
-         failed = true;
-         cerr << "Instruction selection failed for method "
-              << (method->hasName()? method->getName() : "")
-              << endl << endl;
+         cerr << "Error compiling " << InputFilename << "!\n";
+         Failed = true;
+         break;
        }
     }
   
-  return failed;
+  // Clean up and exit
+  delete M;
+  delete Target;
+  return Failed;
 }
 
+