Generalize abstract interpreter interface to allow linking in an arbitrary number...
[oota-llvm.git] / tools / bugpoint / CodeGeneratorBug.cpp
index be5f3ea77c6934f13f6271b3252083795a61c94e..b7757097019d083c83f904b451e8bf0664af0844 100644 (file)
@@ -5,7 +5,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "BugDriver.h"
-#include "SystemUtils.h"
 #include "ListReducer.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -23,6 +22,7 @@
 #include "Support/CommandLine.h"
 #include "Support/Debug.h"
 #include "Support/StringExtras.h"
+#include "Support/FileUtilities.h"
 #include <algorithm>
 #include <set>
 
@@ -225,8 +225,7 @@ bool ReduceMisCodegenFunctions::TestFuncs(const std::vector<Function*> &Funcs,
   }
 
   // Make a shared library
-  std::string SharedObject;
-  BD.compileSharedObject(SafeModuleBC, SharedObject);
+  std::string SharedObject = compileSharedObject(SafeModuleBC);
 
   delete SafeModule;
   delete TestModule;
@@ -236,17 +235,15 @@ bool ReduceMisCodegenFunctions::TestFuncs(const std::vector<Function*> &Funcs,
   int Result = BD.diffProgram(TestModuleBC, SharedObject, false);
 
   if (Result)
-    std::cerr << ": Still failing!\n";
+    std::cerr << ": still failing!\n";
   else
     std::cerr << ": didn't fail.\n";
     
-
   if (KeepFiles) {
     std::cout << "You can reproduce the problem with the command line: \n";
     if (BD.isExecutingJIT()) {
       std::cout << "  lli -load " << SharedObject << " " << TestModuleBC;
     } else {
-      //<< (BD.isExecutingJIT() ? "lli" : "llc")
       std::cout << "  llc " << TestModuleBC << " -o " << TestModuleBC << ".s\n";
       std::cout << "  gcc " << SharedObject << " " << TestModuleBC
                 << ".s -o " << TestModuleBC << ".exe\n";
@@ -255,8 +252,15 @@ bool ReduceMisCodegenFunctions::TestFuncs(const std::vector<Function*> &Funcs,
     for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
       std::cout << " " << InputArgv[i];
     std::cout << "\n";
-    std::cout << "The shared object " << SharedObject << " was created from "
-              << SafeModuleBC << ", using `dis -c'.\n";
+    std::cout << "The shared object was created with:\n  llvm-dis -c "
+              << SafeModuleBC << " -o temporary.c\n"
+              << "  gcc -xc temporary.c -O2 -o " << SharedObject
+#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
+              << " -G"            // Compile a shared library, `-G' for Sparc
+#else
+              << " -shared"       // `-shared' for Linux/X86, maybe others
+#endif
+              << "\n";
   } else {
     removeFile(TestModuleBC);
     removeFile(SafeModuleBC);
@@ -350,7 +354,7 @@ bool BugDriver::debugCodeGenerator() {
     Function *oldMain = Program->getNamedFunction("main");
     assert(oldMain && "`main' function not found in program!");
     // Rename it
-    oldMain->setName("old_main");
+    oldMain->setName("llvm_old_main");
     // Create a NEW `main' function with same type
     Function *newMain = new Function(oldMain->getFunctionType(), 
                                      GlobalValue::ExternalLinkage,
@@ -358,8 +362,11 @@ bool BugDriver::debugCodeGenerator() {
     // Call the old main function and return its result
     BasicBlock *BB = new BasicBlock("entry", newMain);
     std::vector<Value*> args;
-    for (Function::aiterator I=newMain->abegin(), E=newMain->aend(); I!=E; ++I)
+    for (Function::aiterator I = newMain->abegin(), E = newMain->aend(),
+           OI = oldMain->abegin(); I != E; ++I, ++OI) {
+      I->setName(OI->getName());    // Copy argument names from oldMain
       args.push_back(I);
+    }
     CallInst *call = new CallInst(oldMain, args);
     BB->getInstList().push_back(call);