2002-12-24 00:50:16 +01:00
|
|
|
//===- ExecutionDriver.cpp - Allow execution of LLVM program --------------===//
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2003-10-20 19:47:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2003-10-20 19:47:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-24 00:50:16 +01:00
|
|
|
//
|
|
|
|
// This file contains code used to execute the program utilizing one of the
|
|
|
|
// various ways of running LLVM bytecode.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "BugDriver.h"
|
2006-06-07 00:30:59 +02:00
|
|
|
#include "ToolRunner.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/FileUtilities.h"
|
|
|
|
#include "llvm/Support/SystemUtils.h"
|
2002-12-24 00:50:16 +01:00
|
|
|
#include <fstream>
|
2006-01-22 23:53:40 +01:00
|
|
|
#include <iostream>
|
2006-06-06 02:00:42 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2002-12-24 00:50:16 +01:00
|
|
|
namespace {
|
|
|
|
// OutputType - Allow the user to specify the way code should be run, to test
|
|
|
|
// for miscompilation.
|
|
|
|
//
|
|
|
|
enum OutputType {
|
2006-11-09 06:57:53 +01:00
|
|
|
AutoPick, RunLLI, RunJIT, RunLLC, RunCBE, CBE_bug, LLC_Safe
|
2002-12-24 00:50:16 +01:00
|
|
|
};
|
2003-09-30 00:40:52 +02:00
|
|
|
|
2005-01-23 04:45:26 +01:00
|
|
|
cl::opt<double>
|
|
|
|
AbsTolerance("abs-tolerance", cl::desc("Absolute error tolerated"),
|
|
|
|
cl::init(0.0));
|
|
|
|
cl::opt<double>
|
|
|
|
RelTolerance("rel-tolerance", cl::desc("Relative error tolerated"),
|
|
|
|
cl::init(0.0));
|
|
|
|
|
2002-12-24 00:50:16 +01:00
|
|
|
cl::opt<OutputType>
|
|
|
|
InterpreterSel(cl::desc("Specify how LLVM code should be executed:"),
|
2003-10-21 19:41:35 +02:00
|
|
|
cl::values(clEnumValN(AutoPick, "auto", "Use best guess"),
|
2004-04-19 05:12:35 +02:00
|
|
|
clEnumValN(RunLLI, "run-int",
|
|
|
|
"Execute with the interpreter"),
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
clEnumValN(RunJIT, "run-jit", "Execute with JIT"),
|
|
|
|
clEnumValN(RunLLC, "run-llc", "Compile with LLC"),
|
|
|
|
clEnumValN(RunCBE, "run-cbe", "Compile with CBE"),
|
2006-09-15 23:29:15 +02:00
|
|
|
clEnumValN(CBE_bug,"cbe-bug", "Find CBE bugs"),
|
2006-11-09 06:57:53 +01:00
|
|
|
clEnumValN(LLC_Safe, "llc-safe", "Use LLC for all"),
|
2004-07-16 02:08:28 +02:00
|
|
|
clEnumValEnd),
|
2003-10-21 19:41:35 +02:00
|
|
|
cl::init(AutoPick));
|
2003-04-23 22:31:37 +02:00
|
|
|
|
2004-02-11 19:37:32 +01:00
|
|
|
cl::opt<bool>
|
|
|
|
CheckProgramExitCode("check-exit-code",
|
2004-07-23 03:30:49 +02:00
|
|
|
cl::desc("Assume nonzero exit code is failure (default on)"),
|
2004-02-11 19:37:32 +01:00
|
|
|
cl::init(true));
|
|
|
|
|
2006-11-28 08:04:10 +01:00
|
|
|
cl::opt<bool>
|
|
|
|
AppendProgramExitCode("append-exit-code",
|
|
|
|
cl::desc("Append the exit code to the output so it gets diff'd too"),
|
|
|
|
cl::init(false));
|
|
|
|
|
2003-04-23 22:31:37 +02:00
|
|
|
cl::opt<std::string>
|
|
|
|
InputFile("input", cl::init("/dev/null"),
|
|
|
|
cl::desc("Filename to pipe in as stdin (default: /dev/null)"));
|
2003-10-15 00:24:31 +02:00
|
|
|
|
|
|
|
cl::list<std::string>
|
|
|
|
AdditionalSOs("additional-so",
|
|
|
|
cl::desc("Additional shared objects to load "
|
|
|
|
"into executing programs"));
|
2004-07-24 09:53:26 +02:00
|
|
|
|
2006-06-06 02:00:42 +02:00
|
|
|
cl::list<std::string>
|
|
|
|
AdditionalLinkerArgs("Xlinker",
|
|
|
|
cl::desc("Additional arguments to pass to the linker"));
|
2002-12-24 00:50:16 +01:00
|
|
|
}
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
2004-01-14 04:38:37 +01:00
|
|
|
// Anything specified after the --args option are taken as arguments to the
|
|
|
|
// program being debugged.
|
|
|
|
cl::list<std::string>
|
|
|
|
InputArgv("args", cl::Positional, cl::desc("<program arguments>..."),
|
2004-05-07 00:05:35 +02:00
|
|
|
cl::ZeroOrMore, cl::PositionalEatsArgs);
|
2004-05-04 23:09:16 +02:00
|
|
|
|
|
|
|
cl::list<std::string>
|
|
|
|
ToolArgv("tool-args", cl::Positional, cl::desc("<tool arguments>..."),
|
2004-05-07 00:05:35 +02:00
|
|
|
cl::ZeroOrMore, cl::PositionalEatsArgs);
|
2004-01-14 04:38:37 +01:00
|
|
|
}
|
2003-07-30 22:15:44 +02:00
|
|
|
|
2002-12-24 00:50:16 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BugDriver method implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
/// initializeExecutionEnvironment - This method is used to set up the
|
|
|
|
/// environment for executing LLVM programs.
|
|
|
|
///
|
|
|
|
bool BugDriver::initializeExecutionEnvironment() {
|
|
|
|
std::cout << "Initializing execution environment: ";
|
|
|
|
|
2003-09-30 00:40:52 +02:00
|
|
|
// Create an instance of the AbstractInterpreter interface as specified on
|
|
|
|
// the command line
|
2004-02-18 21:52:02 +01:00
|
|
|
cbe = 0;
|
2002-12-24 00:50:16 +01:00
|
|
|
std::string Message;
|
2004-05-04 23:09:16 +02:00
|
|
|
|
2003-05-03 05:19:41 +02:00
|
|
|
switch (InterpreterSel) {
|
2003-10-21 19:41:35 +02:00
|
|
|
case AutoPick:
|
|
|
|
InterpreterSel = RunCBE;
|
2004-05-04 23:09:16 +02:00
|
|
|
Interpreter = cbe = AbstractInterpreter::createCBE(getToolName(), Message,
|
|
|
|
&ToolArgv);
|
2003-10-21 19:41:35 +02:00
|
|
|
if (!Interpreter) {
|
|
|
|
InterpreterSel = RunJIT;
|
2004-05-04 23:09:16 +02:00
|
|
|
Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
|
|
|
|
&ToolArgv);
|
2003-10-21 19:41:35 +02:00
|
|
|
}
|
|
|
|
if (!Interpreter) {
|
|
|
|
InterpreterSel = RunLLC;
|
2004-05-04 23:09:16 +02:00
|
|
|
Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
|
|
|
|
&ToolArgv);
|
2003-10-21 19:41:35 +02:00
|
|
|
}
|
|
|
|
if (!Interpreter) {
|
|
|
|
InterpreterSel = RunLLI;
|
2004-05-04 23:09:16 +02:00
|
|
|
Interpreter = AbstractInterpreter::createLLI(getToolName(), Message,
|
|
|
|
&ToolArgv);
|
2003-10-21 19:41:35 +02:00
|
|
|
}
|
|
|
|
if (!Interpreter) {
|
|
|
|
InterpreterSel = AutoPick;
|
|
|
|
Message = "Sorry, I can't automatically select an interpreter!\n";
|
|
|
|
}
|
|
|
|
break;
|
2003-10-14 23:59:36 +02:00
|
|
|
case RunLLI:
|
2004-05-04 23:09:16 +02:00
|
|
|
Interpreter = AbstractInterpreter::createLLI(getToolName(), Message,
|
|
|
|
&ToolArgv);
|
2003-10-14 23:59:36 +02:00
|
|
|
break;
|
|
|
|
case RunLLC:
|
2004-05-04 23:09:16 +02:00
|
|
|
Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
|
|
|
|
&ToolArgv);
|
2003-10-14 23:59:36 +02:00
|
|
|
break;
|
|
|
|
case RunJIT:
|
2004-05-04 23:09:16 +02:00
|
|
|
Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
|
|
|
|
&ToolArgv);
|
2003-10-14 23:59:36 +02:00
|
|
|
break;
|
2006-11-09 06:57:53 +01:00
|
|
|
case LLC_Safe:
|
|
|
|
Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
|
|
|
|
&ToolArgv);
|
|
|
|
break;
|
2003-10-14 23:59:36 +02:00
|
|
|
case RunCBE:
|
2006-09-15 23:29:15 +02:00
|
|
|
case CBE_bug:
|
|
|
|
Interpreter = AbstractInterpreter::createCBE(getToolName(), Message,
|
|
|
|
&ToolArgv);
|
2003-10-14 23:59:36 +02:00
|
|
|
break;
|
2003-05-03 05:19:41 +02:00
|
|
|
default:
|
2003-09-30 00:40:52 +02:00
|
|
|
Message = "Sorry, this back-end is not supported by bugpoint right now!\n";
|
2003-05-03 05:19:41 +02:00
|
|
|
break;
|
2002-12-24 00:50:16 +01:00
|
|
|
}
|
2003-09-30 00:40:52 +02:00
|
|
|
std::cerr << Message;
|
2002-12-24 00:50:16 +01:00
|
|
|
|
2003-07-24 23:59:10 +02:00
|
|
|
// Initialize auxiliary tools for debugging
|
2006-09-15 23:29:15 +02:00
|
|
|
if (InterpreterSel == RunCBE) {
|
|
|
|
// We already created a CBE, reuse it.
|
|
|
|
cbe = Interpreter;
|
2006-11-09 06:57:53 +01:00
|
|
|
} else if (InterpreterSel == CBE_bug || InterpreterSel == LLC_Safe) {
|
|
|
|
// We want to debug the CBE itself or LLC is known-good. Use LLC as the
|
|
|
|
// 'known-good' compiler.
|
2006-09-15 23:29:15 +02:00
|
|
|
std::vector<std::string> ToolArgs;
|
|
|
|
ToolArgs.push_back("--relocation-model=pic");
|
|
|
|
cbe = AbstractInterpreter::createLLC(getToolName(), Message, &ToolArgs);
|
|
|
|
} else {
|
2004-05-04 23:09:16 +02:00
|
|
|
cbe = AbstractInterpreter::createCBE(getToolName(), Message, &ToolArgv);
|
2004-02-18 21:52:02 +01:00
|
|
|
}
|
2006-09-15 23:29:15 +02:00
|
|
|
if (!cbe) { std::cout << Message << "\nExiting.\n"; exit(1); }
|
|
|
|
|
2003-10-14 23:59:36 +02:00
|
|
|
gcc = GCC::create(getToolName(), Message);
|
2003-07-24 23:59:10 +02:00
|
|
|
if (!gcc) { std::cout << Message << "\nExiting.\n"; exit(1); }
|
|
|
|
|
2002-12-24 00:50:16 +01:00
|
|
|
// If there was an error creating the selected interpreter, quit with error.
|
|
|
|
return Interpreter == 0;
|
|
|
|
}
|
|
|
|
|
2004-02-19 00:25:22 +01:00
|
|
|
/// compileProgram - Try to compile the specified module, throwing an exception
|
|
|
|
/// if an error occurs, or returning normally if not. This is used for code
|
|
|
|
/// generation crash testing.
|
|
|
|
///
|
|
|
|
void BugDriver::compileProgram(Module *M) {
|
|
|
|
// Emit the program to a bytecode file...
|
2004-12-15 02:53:08 +01:00
|
|
|
sys::Path BytecodeFile ("bugpoint-test-program.bc");
|
2006-08-23 22:34:57 +02:00
|
|
|
std::string ErrMsg;
|
|
|
|
if (BytecodeFile.makeUnique(true,&ErrMsg)) {
|
|
|
|
std::cerr << ToolName << ": Error making unique filename: " << ErrMsg
|
|
|
|
<< "\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-12-15 02:53:08 +01:00
|
|
|
if (writeProgramToFile(BytecodeFile.toString(), M)) {
|
2004-02-19 00:25:22 +01:00
|
|
|
std::cerr << ToolName << ": Error emitting bytecode to file '"
|
|
|
|
<< BytecodeFile << "'!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the temporary bytecode file when we are done.
|
2004-12-17 00:04:20 +01:00
|
|
|
FileRemover BytecodeFileRemover(BytecodeFile);
|
2004-02-19 00:25:22 +01:00
|
|
|
|
|
|
|
// Actually compile the program!
|
2004-12-15 02:53:08 +01:00
|
|
|
Interpreter->compileProgram(BytecodeFile.toString());
|
2004-02-19 00:25:22 +01:00
|
|
|
}
|
|
|
|
|
2002-12-24 00:50:16 +01:00
|
|
|
|
|
|
|
/// executeProgram - This method runs "Program", capturing the output of the
|
|
|
|
/// program to a file, returning the filename of the file. A recommended
|
|
|
|
/// filename may be optionally specified.
|
|
|
|
///
|
|
|
|
std::string BugDriver::executeProgram(std::string OutputFile,
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
std::string BytecodeFile,
|
2003-10-14 23:59:36 +02:00
|
|
|
const std::string &SharedObj,
|
2004-02-11 19:37:32 +01:00
|
|
|
AbstractInterpreter *AI,
|
|
|
|
bool *ProgramExitedNonzero) {
|
2003-10-14 23:59:36 +02:00
|
|
|
if (AI == 0) AI = Interpreter;
|
|
|
|
assert(AI && "Interpreter should have been created already!");
|
2002-12-24 00:50:16 +01:00
|
|
|
bool CreatedBytecode = false;
|
2006-08-23 22:34:57 +02:00
|
|
|
std::string ErrMsg;
|
2002-12-24 00:50:16 +01:00
|
|
|
if (BytecodeFile.empty()) {
|
|
|
|
// Emit the program to a bytecode file...
|
2004-12-15 02:53:08 +01:00
|
|
|
sys::Path uniqueFilename("bugpoint-test-program.bc");
|
2006-08-23 22:34:57 +02:00
|
|
|
if (uniqueFilename.makeUnique(true, &ErrMsg)) {
|
|
|
|
std::cerr << ToolName << ": Error making unique filename: "
|
|
|
|
<< ErrMsg << "!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-12-15 02:53:08 +01:00
|
|
|
BytecodeFile = uniqueFilename.toString();
|
2002-12-24 00:50:16 +01:00
|
|
|
|
|
|
|
if (writeProgramToFile(BytecodeFile, Program)) {
|
|
|
|
std::cerr << ToolName << ": Error emitting bytecode to file '"
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
<< BytecodeFile << "'!\n";
|
2002-12-24 00:50:16 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
CreatedBytecode = true;
|
|
|
|
}
|
|
|
|
|
2004-02-18 23:01:21 +01:00
|
|
|
// Remove the temporary bytecode file when we are done.
|
2004-12-22 23:33:33 +01:00
|
|
|
sys::Path BytecodePath (BytecodeFile);
|
|
|
|
FileRemover BytecodeFileRemover(BytecodePath, CreatedBytecode);
|
2004-02-18 23:01:21 +01:00
|
|
|
|
2002-12-24 00:50:16 +01:00
|
|
|
if (OutputFile.empty()) OutputFile = "bugpoint-execution-output";
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
|
2002-12-24 00:50:16 +01:00
|
|
|
// Check to see if this is a valid output filename...
|
2004-12-15 02:53:08 +01:00
|
|
|
sys::Path uniqueFile(OutputFile);
|
2006-08-23 22:34:57 +02:00
|
|
|
if (uniqueFile.makeUnique(true, &ErrMsg)) {
|
|
|
|
std::cerr << ToolName << ": Error making unique filename: "
|
|
|
|
<< ErrMsg << "\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-12-15 02:53:08 +01:00
|
|
|
OutputFile = uniqueFile.toString();
|
2002-12-24 00:50:16 +01:00
|
|
|
|
2003-10-14 23:59:36 +02:00
|
|
|
// Figure out which shared objects to run, if any.
|
2003-10-15 00:24:31 +02:00
|
|
|
std::vector<std::string> SharedObjs(AdditionalSOs);
|
2003-10-14 23:59:36 +02:00
|
|
|
if (!SharedObj.empty())
|
|
|
|
SharedObjs.push_back(SharedObj);
|
|
|
|
|
2006-06-06 02:00:42 +02:00
|
|
|
|
|
|
|
// If this is an LLC or CBE run, then the GCC compiler might get run to
|
|
|
|
// compile the program. If so, we should pass the user's -Xlinker options
|
|
|
|
// as the GCCArgs.
|
|
|
|
int RetVal = 0;
|
2006-09-15 23:29:15 +02:00
|
|
|
if (InterpreterSel == RunLLC || InterpreterSel == RunCBE ||
|
|
|
|
InterpreterSel == CBE_bug)
|
2006-06-06 02:00:42 +02:00
|
|
|
RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
|
|
|
|
OutputFile, AdditionalLinkerArgs, SharedObjs,
|
2007-02-16 20:11:07 +01:00
|
|
|
Timeout, MemoryLimit);
|
2006-06-06 02:00:42 +02:00
|
|
|
else
|
|
|
|
RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
|
|
|
|
OutputFile, std::vector<std::string>(),
|
2007-02-16 20:11:07 +01:00
|
|
|
SharedObjs, Timeout, MemoryLimit);
|
2004-07-24 09:53:26 +02:00
|
|
|
|
|
|
|
if (RetVal == -1) {
|
|
|
|
std::cerr << "<timeout>";
|
|
|
|
static bool FirstTimeout = true;
|
|
|
|
if (FirstTimeout) {
|
|
|
|
std::cout << "\n"
|
|
|
|
"*** Program execution timed out! This mechanism is designed to handle\n"
|
|
|
|
" programs stuck in infinite loops gracefully. The -timeout option\n"
|
|
|
|
" can be used to change the timeout threshold or disable it completely\n"
|
|
|
|
" (with -timeout=0). This message is only displayed once.\n";
|
|
|
|
FirstTimeout = false;
|
|
|
|
}
|
|
|
|
}
|
2003-10-14 23:59:36 +02:00
|
|
|
|
2006-11-28 08:04:10 +01:00
|
|
|
if (AppendProgramExitCode) {
|
|
|
|
std::ofstream outFile(OutputFile.c_str(), std::ios_base::app);
|
|
|
|
outFile << "exit " << RetVal << '\n';
|
|
|
|
outFile.close();
|
|
|
|
}
|
|
|
|
|
2004-02-11 19:37:32 +01:00
|
|
|
if (ProgramExitedNonzero != 0)
|
|
|
|
*ProgramExitedNonzero = (RetVal != 0);
|
2002-12-24 00:50:16 +01:00
|
|
|
|
|
|
|
// Return the filename we captured the output to.
|
|
|
|
return OutputFile;
|
|
|
|
}
|
|
|
|
|
2004-02-11 19:37:32 +01:00
|
|
|
/// executeProgramWithCBE - Used to create reference output with the C
|
|
|
|
/// backend, if reference output is not provided.
|
|
|
|
///
|
|
|
|
std::string BugDriver::executeProgramWithCBE(std::string OutputFile) {
|
|
|
|
bool ProgramExitedNonzero;
|
2006-09-15 23:29:15 +02:00
|
|
|
std::string outFN = executeProgram(OutputFile, "", "", cbe,
|
2004-02-11 19:37:32 +01:00
|
|
|
&ProgramExitedNonzero);
|
|
|
|
if (ProgramExitedNonzero) {
|
|
|
|
std::cerr
|
|
|
|
<< "Warning: While generating reference output, program exited with\n"
|
|
|
|
<< "non-zero exit code. This will NOT be treated as a failure.\n";
|
|
|
|
CheckProgramExitCode = false;
|
|
|
|
}
|
|
|
|
return outFN;
|
|
|
|
}
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
|
2003-10-14 23:09:11 +02:00
|
|
|
std::string BugDriver::compileSharedObject(const std::string &BytecodeFile) {
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
assert(Interpreter && "Interpreter should have been created already!");
|
2006-09-15 23:29:15 +02:00
|
|
|
sys::Path OutputFile;
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
|
|
|
|
// Using CBE
|
2006-09-15 23:29:15 +02:00
|
|
|
GCC::FileType FT = cbe->OutputCode(BytecodeFile, OutputFile);
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
|
2003-10-14 23:09:11 +02:00
|
|
|
std::string SharedObjectFile;
|
2006-09-15 23:29:15 +02:00
|
|
|
if (gcc->MakeSharedObject(OutputFile.toString(), FT,
|
2006-06-27 22:35:36 +02:00
|
|
|
SharedObjectFile, AdditionalLinkerArgs))
|
2003-10-14 23:09:11 +02:00
|
|
|
exit(1);
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
|
|
|
|
// Remove the intermediate C file
|
2006-09-15 23:29:15 +02:00
|
|
|
OutputFile.eraseFromDisk();
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
|
2003-10-19 23:54:13 +02:00
|
|
|
return "./" + SharedObjectFile;
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
}
|
|
|
|
|
2006-08-15 18:40:49 +02:00
|
|
|
/// createReferenceFile - calls compileProgram and then records the output
|
|
|
|
/// into ReferenceOutputFile. Returns true if reference file created, false
|
|
|
|
/// otherwise. Note: initializeExecutionEnvironment should be called BEFORE
|
|
|
|
/// this function.
|
|
|
|
///
|
2006-09-15 23:29:15 +02:00
|
|
|
bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
|
2006-08-15 18:40:49 +02:00
|
|
|
try {
|
|
|
|
compileProgram(Program);
|
2006-11-05 20:31:28 +01:00
|
|
|
} catch (ToolExecutionError &) {
|
2006-08-15 18:40:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
ReferenceOutputFile = executeProgramWithCBE(Filename);
|
|
|
|
std::cout << "Reference output is: " << ReferenceOutputFile << "\n\n";
|
|
|
|
} catch (ToolExecutionError &TEE) {
|
|
|
|
std::cerr << TEE.what();
|
|
|
|
if (Interpreter != cbe) {
|
|
|
|
std::cerr << "*** There is a bug running the C backend. Either debug"
|
|
|
|
<< " it (use the -run-cbe bugpoint option), or fix the error"
|
|
|
|
<< " some other way.\n";
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
|
2006-08-15 18:40:49 +02:00
|
|
|
/// diffProgram - This method executes the specified module and diffs the
|
|
|
|
/// output against the file specified by ReferenceOutputFile. If the output
|
|
|
|
/// is different, true is returned. If there is a problem with the code
|
|
|
|
/// generator (e.g., llc crashes), this will throw an exception.
|
2002-12-24 00:50:16 +01:00
|
|
|
///
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-24 20:17:43 +02:00
|
|
|
bool BugDriver::diffProgram(const std::string &BytecodeFile,
|
|
|
|
const std::string &SharedObject,
|
2003-04-24 19:02:17 +02:00
|
|
|
bool RemoveBytecode) {
|
2004-02-11 19:37:32 +01:00
|
|
|
bool ProgramExitedNonzero;
|
|
|
|
|
2002-12-24 00:50:16 +01:00
|
|
|
// Execute the program, generating an output file...
|
2006-06-27 22:35:36 +02:00
|
|
|
sys::Path Output(executeProgram("", BytecodeFile, SharedObject, 0,
|
2004-12-17 00:04:20 +01:00
|
|
|
&ProgramExitedNonzero));
|
2004-02-11 19:37:32 +01:00
|
|
|
|
|
|
|
// If we're checking the program exit code, assume anything nonzero is bad.
|
2004-04-02 07:33:06 +02:00
|
|
|
if (CheckProgramExitCode && ProgramExitedNonzero) {
|
2005-07-08 05:08:58 +02:00
|
|
|
Output.eraseFromDisk();
|
2005-04-22 02:00:37 +02:00
|
|
|
if (RemoveBytecode)
|
2005-07-08 05:08:58 +02:00
|
|
|
sys::Path(BytecodeFile).eraseFromDisk();
|
2004-02-11 19:37:32 +01:00
|
|
|
return true;
|
2004-04-02 07:33:06 +02:00
|
|
|
}
|
2002-12-24 00:50:16 +01:00
|
|
|
|
2003-08-01 22:29:45 +02:00
|
|
|
std::string Error;
|
2002-12-24 00:50:16 +01:00
|
|
|
bool FilesDifferent = false;
|
2005-01-23 04:45:26 +01:00
|
|
|
if (int Diff = DiffFilesWithTolerance(sys::Path(ReferenceOutputFile),
|
|
|
|
sys::Path(Output.toString()),
|
|
|
|
AbsTolerance, RelTolerance, &Error)) {
|
|
|
|
if (Diff == 2) {
|
2004-07-23 03:30:49 +02:00
|
|
|
std::cerr << "While diffing output: " << Error << '\n';
|
2003-08-01 22:29:45 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
FilesDifferent = true;
|
|
|
|
}
|
2005-04-22 02:00:37 +02:00
|
|
|
|
2003-10-18 23:02:51 +02:00
|
|
|
// Remove the generated output.
|
2005-07-08 05:08:58 +02:00
|
|
|
Output.eraseFromDisk();
|
2002-12-24 00:50:16 +01:00
|
|
|
|
2003-10-18 23:02:51 +02:00
|
|
|
// Remove the bytecode file if we are supposed to.
|
2005-07-27 08:12:32 +02:00
|
|
|
if (RemoveBytecode)
|
2005-07-08 05:08:58 +02:00
|
|
|
sys::Path(BytecodeFile).eraseFromDisk();
|
2002-12-24 00:50:16 +01:00
|
|
|
return FilesDifferent;
|
|
|
|
}
|
2003-07-28 21:16:14 +02:00
|
|
|
|
|
|
|
bool BugDriver::isExecutingJIT() {
|
|
|
|
return InterpreterSel == RunJIT;
|
|
|
|
}
|
2003-11-11 23:41:34 +01:00
|
|
|
|