Fix typo 'ompress' => 'compress'.
[oota-llvm.git] / tools / gccas / gccas.cpp
index 3fa0cfa7dd4d1bed214501da4bbfde681faa7721..deb9397fecf48306ed6a06f68cf2e512ce47d6ca 100644 (file)
@@ -48,10 +48,15 @@ namespace {
                        cl::desc("Do not run any optimization passes"));
 
   cl::opt<bool>
-  DisableDSE("disable-dse", cl::desc("Do not run dead store elimination"));
+  StripDebug("strip-debug",
+             cl::desc("Strip debugger symbol info from translation unit"));
+
   cl::opt<bool> 
   NoCompress("disable-compression", cl::init(false),
-             cl::desc("Don't ompress the generated bytecode"));
+             cl::desc("Don't compress the generated bytecode"));
+
+  cl::opt<bool> TF("traditional-format", cl::Hidden,
+    cl::desc("Compatibility option: ignored"));
 }
 
 
@@ -66,9 +71,14 @@ static inline void addPass(PassManager &PM, Pass *P) {
 
 void AddConfiguredTransformationPasses(PassManager &PM) {
   PM.add(createVerifierPass());                  // Verify that input is correct
+
   addPass(PM, createLowerSetJmpPass());          // Lower llvm.setjmp/.longjmp
   addPass(PM, createFunctionResolvingPass());    // Resolve (...) functions
 
+  // If the -strip-debug command line option was specified, do it.
+  if (StripDebug)
+    addPass(PM, createStripSymbolsPass(true));
+
   if (DisableOptimizations) return;
 
   addPass(PM, createRaiseAllocationsPass());     // call %malloc -> malloc inst
@@ -109,8 +119,7 @@ void AddConfiguredTransformationPasses(PassManager &PM) {
   // Run instcombine after redundancy elimination to exploit opportunities
   // opened up by them.
   addPass(PM, createInstructionCombiningPass());
-  if (!DisableDSE)
-    addPass(PM, createDeadStoreEliminationPass()); // Delete dead stores
+  addPass(PM, createDeadStoreEliminationPass()); // Delete dead stores
   addPass(PM, createAggressiveDCEPass());        // SSA based 'Aggressive DCE'
   addPass(PM, createCFGSimplificationPass());    // Merge & remove BBs
   addPass(PM, createDeadTypeEliminationPass());  // Eliminate dead types
@@ -119,77 +128,85 @@ void AddConfiguredTransformationPasses(PassManager &PM) {
 
 
 int main(int argc, char **argv) {
-  cl::ParseCommandLineOptions(argc, argv, " llvm .s -> .o assembler for GCC\n");
-  sys::PrintStackTraceOnErrorSignal();
-
-  std::auto_ptr<Module> M;
   try {
-    // Parse the file now...
-    M.reset(ParseAssemblyFile(InputFilename));
-  } catch (const ParseException &E) {
-    std::cerr << argv[0] << ": " << E.getMessage() << "\n";
-    return 1;
-  }
+    cl::ParseCommandLineOptions(argc, argv, 
+                                " llvm .s -> .o assembler for GCC\n");
+    sys::PrintStackTraceOnErrorSignal();
+
+    std::auto_ptr<Module> M;
+    try {
+      // Parse the file now...
+      M.reset(ParseAssemblyFile(InputFilename));
+    } catch (const ParseException &E) {
+      std::cerr << argv[0] << ": " << E.getMessage() << "\n";
+      return 1;
+    }
 
-  if (M.get() == 0) {
-    std::cerr << argv[0] << ": assembly didn't read correctly.\n";
-    return 1;
-  }
+    if (M.get() == 0) {
+      std::cerr << argv[0] << ": assembly didn't read correctly.\n";
+      return 1;
+    }
 
-  std::ostream *Out = 0;
-  if (OutputFilename == "") {   // Didn't specify an output filename?
-    if (InputFilename == "-") {
-      OutputFilename = "-";
-    } else {
-      std::string IFN = InputFilename;
-      int Len = IFN.length();
-      if (IFN[Len-2] == '.' && IFN[Len-1] == 's') {   // Source ends in .s?
-        OutputFilename = std::string(IFN.begin(), IFN.end()-2);
+    std::ostream *Out = 0;
+    if (OutputFilename == "") {   // Didn't specify an output filename?
+      if (InputFilename == "-") {
+        OutputFilename = "-";
       } else {
-        OutputFilename = IFN;   // Append a .o to it
+        std::string IFN = InputFilename;
+        int Len = IFN.length();
+        if (IFN[Len-2] == '.' && IFN[Len-1] == 's') {   // Source ends in .s?
+          OutputFilename = std::string(IFN.begin(), IFN.end()-2);
+        } else {
+          OutputFilename = IFN;   // Append a .o to it
+        }
+        OutputFilename += ".o";
       }
-      OutputFilename += ".o";
     }
-  }
 
-  if (OutputFilename == "-")
-    Out = &std::cout;
-  else {
-    Out = new std::ofstream(OutputFilename.c_str(), std::ios::out);
+    if (OutputFilename == "-")
+      Out = &std::cout;
+    else {
+      Out = new std::ofstream(OutputFilename.c_str(), std::ios::out);
 
-    // Make sure that the Out file gets unlinked from the disk if we get a
-    // signal
-    sys::RemoveFileOnSignal(OutputFilename);
-  }
+      // Make sure that the Out file gets unlinked from the disk if we get a
+      // signal
+      sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+    }
 
-  
-  if (!Out->good()) {
-    std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
-    return 1;
-  }
+    
+    if (!Out->good()) {
+      std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
+      return 1;
+    }
 
-  // In addition to just parsing the input from GCC, we also want to spiff it up
-  // a little bit.  Do this now.
-  //
-  PassManager Passes;
+    // In addition to just parsing the input from GCC, we also want to spiff it up
+    // a little bit.  Do this now.
+    //
+    PassManager Passes;
 
-  // Add an appropriate TargetData instance for this module...
-  Passes.add(new TargetData("gccas", M.get()));
+    // Add an appropriate TargetData instance for this module...
+    Passes.add(new TargetData("gccas", M.get()));
 
-  // Add all of the transformation passes to the pass manager to do the cleanup
-  // and optimization of the GCC output.
-  //
-  AddConfiguredTransformationPasses(Passes);
+    // Add all of the transformation passes to the pass manager to do the cleanup
+    // and optimization of the GCC output.
+    //
+    AddConfiguredTransformationPasses(Passes);
 
-  // Make sure everything is still good.
-  Passes.add(createVerifierPass());
+    // Make sure everything is still good.
+    Passes.add(createVerifierPass());
 
-  // Write bytecode to file...
-  Passes.add(new WriteBytecodePass(Out,false,!NoCompress));
+    // Write bytecode to file...
+    Passes.add(new WriteBytecodePass(Out,false,!NoCompress));
 
-  // Run our queue of passes all at once now, efficiently.
-  Passes.run(*M.get());
+    // Run our queue of passes all at once now, efficiently.
+    Passes.run(*M.get());
 
-  if (Out != &std::cout) delete Out;
-  return 0;
+    if (Out != &std::cout) delete Out;
+    return 0;
+  } catch (const std::string& msg) {
+    std::cerr << argv[0] << ": " << msg << "\n";
+  } catch (...) {
+    std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
+  }
+  return 1;
 }