class DebugCrashes;
-class CBE;
class GCC;
extern bool DisableSimplifyCFG;
Module *Program; // The raw program, linked together
std::vector<const PassInfo*> PassesToRun;
AbstractInterpreter *Interpreter; // How to run the program
- CBE *cbe;
+ AbstractInterpreter *cbe;
GCC *gcc;
bool run_as_child;
bool run_find_bugs;
// for miscompilation.
//
enum OutputType {
- AutoPick, RunLLI, RunJIT, RunLLC, RunCBE
+ AutoPick, RunLLI, RunJIT, RunLLC, RunCBE, CBE_bug
};
cl::opt<double>
clEnumValN(RunJIT, "run-jit", "Execute with JIT"),
clEnumValN(RunLLC, "run-llc", "Compile with LLC"),
clEnumValN(RunCBE, "run-cbe", "Compile with CBE"),
+ clEnumValN(CBE_bug,"cbe-bug", "Find CBE bugs"),
clEnumValEnd),
cl::init(AutoPick));
&ToolArgv);
break;
case RunCBE:
- Interpreter = cbe = AbstractInterpreter::createCBE(getToolName(), Message,
- &ToolArgv);
+ case CBE_bug:
+ Interpreter = AbstractInterpreter::createCBE(getToolName(), Message,
+ &ToolArgv);
break;
default:
Message = "Sorry, this back-end is not supported by bugpoint right now!\n";
std::cerr << Message;
// Initialize auxiliary tools for debugging
- if (!cbe) {
+ if (InterpreterSel == RunCBE) {
+ // We already created a CBE, reuse it.
+ cbe = Interpreter;
+ } else if (InterpreterSel == CBE_bug) {
+ // We want to debug the CBE itself. Use LLC as the 'known-good' compiler.
+ std::vector<std::string> ToolArgs;
+ ToolArgs.push_back("--relocation-model=pic");
+ cbe = AbstractInterpreter::createLLC(getToolName(), Message, &ToolArgs);
+ } else {
cbe = AbstractInterpreter::createCBE(getToolName(), Message, &ToolArgv);
- if (!cbe) { std::cout << Message << "\nExiting.\n"; exit(1); }
}
+ if (!cbe) { std::cout << Message << "\nExiting.\n"; exit(1); }
+
gcc = GCC::create(getToolName(), Message);
if (!gcc) { std::cout << Message << "\nExiting.\n"; exit(1); }
// compile the program. If so, we should pass the user's -Xlinker options
// as the GCCArgs.
int RetVal = 0;
- if (InterpreterSel == RunLLC || InterpreterSel == RunCBE)
+ if (InterpreterSel == RunLLC || InterpreterSel == RunCBE ||
+ InterpreterSel == CBE_bug)
RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
OutputFile, AdditionalLinkerArgs, SharedObjs,
Timeout);
///
std::string BugDriver::executeProgramWithCBE(std::string OutputFile) {
bool ProgramExitedNonzero;
- std::string outFN = executeProgram(OutputFile, "", "",
- (AbstractInterpreter*)cbe,
+ std::string outFN = executeProgram(OutputFile, "", "", cbe,
&ProgramExitedNonzero);
if (ProgramExitedNonzero) {
std::cerr
std::string BugDriver::compileSharedObject(const std::string &BytecodeFile) {
assert(Interpreter && "Interpreter should have been created already!");
- sys::Path OutputCFile;
+ sys::Path OutputFile;
// Using CBE
- cbe->OutputC(BytecodeFile, OutputCFile);
-
-#if 0 /* This is an alternative, as yet unimplemented */
- // Using LLC
- std::string Message;
- LLC *llc = createLLCtool(Message);
- if (llc->OutputAsm(BytecodeFile, OutputFile)) {
- std::cerr << "Could not generate asm code with `llc', exiting.\n";
- exit(1);
- }
-#endif
+ GCC::FileType FT = cbe->OutputCode(BytecodeFile, OutputFile);
std::string SharedObjectFile;
- if (gcc->MakeSharedObject(OutputCFile.toString(), GCC::CFile,
+ if (gcc->MakeSharedObject(OutputFile.toString(), FT,
SharedObjectFile, AdditionalLinkerArgs))
exit(1);
// Remove the intermediate C file
- OutputCFile.eraseFromDisk();
+ OutputFile.eraseFromDisk();
return "./" + SharedObjectFile;
}
/// otherwise. Note: initializeExecutionEnvironment should be called BEFORE
/// this function.
///
-bool BugDriver::createReferenceFile(Module *M, const std::string &Filename){
+bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
try {
compileProgram(Program);
} catch (ToolExecutionError &TEE) {
redirects[0] = &StdInFile;
redirects[1] = &StdOutFile;
redirects[2] = &StdErrFile;
+
+{
+ std::cerr << "RUN:";
+ for (unsigned i = 0; Args[i]; ++i)
+ std::cerr << " " << Args[i];
+ std::cerr << "\n";
+}
return
sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects, NumSeconds);
//===----------------------------------------------------------------------===//
// LLC Implementation of AbstractIntepreter interface
//
-void LLC::OutputAsm(const std::string &Bytecode, sys::Path &OutputAsmFile) {
+GCC::FileType LLC::OutputCode(const std::string &Bytecode,
+ sys::Path &OutputAsmFile) {
sys::Path uniqueFile(Bytecode+".llc.s");
std::string ErrMsg;
if (uniqueFile.makeUnique(true, &ErrMsg)) {
if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0],
sys::Path(), sys::Path(), sys::Path()))
ProcessFailure(sys::Path(LLCPath), &LLCArgs[0]);
+
+ return GCC::AsmFile;
}
void LLC::compileProgram(const std::string &Bytecode) {
sys::Path OutputAsmFile;
- OutputAsm(Bytecode, OutputAsmFile);
+ OutputCode(Bytecode, OutputAsmFile);
OutputAsmFile.eraseFromDisk();
}
unsigned Timeout) {
sys::Path OutputAsmFile;
- OutputAsm(Bytecode, OutputAsmFile);
+ OutputCode(Bytecode, OutputAsmFile);
FileRemover OutFileRemover(OutputAsmFile);
std::vector<std::string> GCCArgs(ArgsForGCC);
return 0;
}
-void CBE::OutputC(const std::string &Bytecode, sys::Path& OutputCFile) {
+GCC::FileType CBE::OutputCode(const std::string &Bytecode,
+ sys::Path &OutputCFile) {
sys::Path uniqueFile(Bytecode+".cbe.c");
std::string ErrMsg;
if (uniqueFile.makeUnique(true, &ErrMsg)) {
if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(),
sys::Path()))
ProcessFailure(LLCPath, &LLCArgs[0]);
+ return GCC::CFile;
}
void CBE::compileProgram(const std::string &Bytecode) {
sys::Path OutputCFile;
- OutputC(Bytecode, OutputCFile);
+ OutputCode(Bytecode, OutputCFile);
OutputCFile.eraseFromDisk();
}
const std::vector<std::string> &SharedLibs,
unsigned Timeout) {
sys::Path OutputCFile;
- OutputC(Bytecode, OutputCFile);
+ OutputCode(Bytecode, OutputCFile);
FileRemover CFileRemove(OutputCFile);
/// thrown, otherwise, this function will just return.
virtual void compileProgram(const std::string &Bytecode) {}
+ /// OutputCode - Compile the specified program from bytecode to code
+ /// understood by the GCC driver (either C or asm). If the code generator
+ /// fails, an exception should be thrown, otherwise, this function returns the
+ /// type of code emitted.
+ virtual GCC::FileType OutputCode(const std::string &Bytecode,
+ sys::Path &OutFile) {
+ throw std::string("OutputCode not supported by this AbstractInterpreter!");
+ }
+
/// ExecuteProgram - Run the specified bytecode file, emitting output to the
/// specified filename. This returns the exit code of the program.
///
std::vector<std::string>(),
unsigned Timeout = 0);
- // Sometimes we just want to go half-way and only generate the .c file, not
- // necessarily compile it with GCC and run the program. This throws an
- // exception if LLC crashes.
- //
- virtual void OutputC(const std::string &Bytecode, sys::Path& OutputCFile);
+ /// OutputCode - Compile the specified program from bytecode to code
+ /// understood by the GCC driver (either C or asm). If the code generator
+ /// fails, an exception should be thrown, otherwise, this function returns the
+ /// type of code emitted.
+ virtual GCC::FileType OutputCode(const std::string &Bytecode,
+ sys::Path &OutFile);
};
std::vector<std::string>(),
unsigned Timeout = 0);
- // Sometimes we just want to go half-way and only generate the .s file,
- // not necessarily compile it all the way and run the program. This throws
- // an exception if execution of LLC fails.
- //
- void OutputAsm(const std::string &Bytecode, sys::Path &OutputAsmFile);
+ virtual GCC::FileType OutputCode(const std::string &Bytecode,
+ sys::Path &OutFile);
+
};
} // End llvm namespace