Oops. Pass -lgcc _only_ on ARM, not on everything except ARM.
[oota-llvm.git] / tools / bugpoint / BugDriver.cpp
index 0934206fde1bb9cd883df93dfeed8130d7493966..abf5d8ef7211b219ab5ccf4dfb695153f68f92d1 100644 (file)
 #include "llvm/Linker.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
-#include "llvm/Assembly/Parser.h"
-#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Support/IRReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/System/Host.h"
 #include <memory>
 using namespace llvm;
 
+namespace llvm {
+  Triple TargetTriple;
+}
+
 // Anonymous namespace to define command line options for debugging.
 //
 namespace {
@@ -77,17 +81,25 @@ BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs,
 ///
 Module *llvm::ParseInputFile(const std::string &Filename,
                              LLVMContext& Ctxt) {
-  std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(Filename));
-  Module *Result = 0;
-  if (Buffer.get())
-    Result = ParseBitcodeFile(Buffer.get(), Ctxt);
-  
   SMDiagnostic Err;
-  if (!Result && !(Result = ParseAssemblyFile(Filename, Err, Ctxt))) {
-    Err.Print("bugpoint", errs()); 
-    Result = 0;
+  Module *Result = ParseIRFile(Filename, Err, Ctxt);
+  if (!Result)
+    Err.Print("bugpoint", errs());
+
+  // If we don't have an override triple, use the first one to configure
+  // bugpoint, or use the host triple if none provided.
+  if (Result) {
+    if (TargetTriple.getTriple().empty()) {
+      Triple TheTriple(Result->getTargetTriple());
+
+      if (TheTriple.getTriple().empty())
+        TheTriple.setTriple(sys::getHostTriple());
+        
+      TargetTriple.setTriple(TheTriple.getTriple());
+    }
+
+    Result->setTargetTriple(TargetTriple.getTriple());  // override the triple
   }
-  
   return Result;
 }
 
@@ -196,7 +208,7 @@ bool BugDriver::run() {
   // Make sure the reference output file gets deleted on exit from this
   // function, if appropriate.
   sys::Path ROF(ReferenceOutputFile);
-  FileRemover RemoverInstance(ROF, CreatedOutput);
+  FileRemover RemoverInstance(ROF, CreatedOutput && !SaveTemps);
 
   // Diff the output of the raw program against the reference output.  If it
   // matches, then we assume there is a miscompilation bug and try to