Add const to some methods and change TestMergedProgram to return the merged

module and take a const BugDriver.

llvm-svn: 109951
This commit is contained in:
Rafael Espindola 2010-07-31 14:34:49 +00:00
parent 779e4b15f1
commit e490460fc8
3 changed files with 32 additions and 23 deletions

View File

@ -179,7 +179,7 @@ public:
std::string Bitcode, std::string Bitcode,
const std::string &SharedObjects, const std::string &SharedObjects,
AbstractInterpreter *AI, AbstractInterpreter *AI,
std::string *Error); std::string *Error) const;
/// executeProgramSafely - Used to create reference output with the "safe" /// executeProgramSafely - Used to create reference output with the "safe"
/// backend, if reference output is not provided. If there is a problem with /// backend, if reference output is not provided. If there is a problem with
@ -187,7 +187,8 @@ public:
/// Error. /// Error.
/// ///
std::string executeProgramSafely(const Module *Program, std::string executeProgramSafely(const Module *Program,
std::string OutputFile, std::string *Error); std::string OutputFile,
std::string *Error) const;
/// createReferenceFile - calls compileProgram and then records the output /// createReferenceFile - calls compileProgram and then records the output
/// into ReferenceOutputFile. Returns true if reference file created, false /// into ReferenceOutputFile. Returns true if reference file created, false
@ -206,7 +207,7 @@ public:
const std::string &BitcodeFile = "", const std::string &BitcodeFile = "",
const std::string &SharedObj = "", const std::string &SharedObj = "",
bool RemoveBitcode = false, bool RemoveBitcode = false,
std::string *Error = 0); std::string *Error = 0) const;
/// EmitProgressBitcode - This function is used to output M to a file named /// EmitProgressBitcode - This function is used to output M to a file named
/// "bugpoint-ID.bc". /// "bugpoint-ID.bc".

View File

@ -325,7 +325,7 @@ std::string BugDriver::executeProgram(const Module *Program,
std::string BitcodeFile, std::string BitcodeFile,
const std::string &SharedObj, const std::string &SharedObj,
AbstractInterpreter *AI, AbstractInterpreter *AI,
std::string *Error) { std::string *Error) const {
if (AI == 0) AI = Interpreter; if (AI == 0) AI = Interpreter;
assert(AI && "Interpreter should have been created already!"); assert(AI && "Interpreter should have been created already!");
bool CreatedBitcode = false; bool CreatedBitcode = false;
@ -402,7 +402,7 @@ std::string BugDriver::executeProgram(const Module *Program,
/// ///
std::string BugDriver::executeProgramSafely(const Module *Program, std::string BugDriver::executeProgramSafely(const Module *Program,
std::string OutputFile, std::string OutputFile,
std::string *Error) { std::string *Error) const {
return executeProgram(Program, OutputFile, "", "", SafeInterpreter, Error); return executeProgram(Program, OutputFile, "", "", SafeInterpreter, Error);
} }
@ -466,7 +466,7 @@ bool BugDriver::diffProgram(const Module *Program,
const std::string &BitcodeFile, const std::string &BitcodeFile,
const std::string &SharedObject, const std::string &SharedObject,
bool RemoveBitcode, bool RemoveBitcode,
std::string *ErrMsg) { std::string *ErrMsg) const {
// Execute the program, generating an output file... // Execute the program, generating an output file...
sys::Path Output(executeProgram(Program, "", BitcodeFile, SharedObject, 0, sys::Path Output(executeProgram(Program, "", BitcodeFile, SharedObject, 0,
ErrMsg)); ErrMsg));

View File

@ -204,13 +204,15 @@ namespace {
} }
/// TestMergedProgram - Given two modules, link them together and run the /// TestMergedProgram - Given two modules, link them together and run the
/// program, checking to see if the program matches the diff. If the diff /// program, checking to see if the program matches the diff. If there is
/// matches, return false, otherwise return true. If the DeleteInputs argument /// an error, return NULL. If not, return the merged module. The Broken argument
/// is set to true then this function deletes both input modules before it /// will be set to true if the output is different. If the DeleteInputs
/// returns. /// argument is set to true then this function deletes both input
/// modules before it returns.
/// ///
static bool TestMergedProgram(BugDriver &BD, Module *M1, Module *M2, static Module *TestMergedProgram(const BugDriver &BD, Module *M1, Module *M2,
bool DeleteInputs, std::string &Error) { bool DeleteInputs, std::string &Error,
bool &Broken) {
// Link the two portions of the program back to together. // Link the two portions of the program back to together.
std::string ErrorMsg; std::string ErrorMsg;
if (!DeleteInputs) { if (!DeleteInputs) {
@ -224,16 +226,14 @@ static bool TestMergedProgram(BugDriver &BD, Module *M1, Module *M2,
} }
delete M2; // We are done with this module. delete M2; // We are done with this module.
// Execute the program. If it does not match the expected output, we must // Execute the program.
// return true. Broken = BD.diffProgram(M1, "", "", false, &Error);
bool Broken = BD.diffProgram(M1, "", "", false, &Error);
if (!Error.empty()) { if (!Error.empty()) {
// Delete the linked module // Delete the linked module
delete M1; delete M1;
return NULL;
} }
// Delete the original and set the new program. return M1;
delete BD.swapProgramIn(M1);
return Broken;
} }
/// TestFuncs - split functions in a Module into two groups: those that are /// TestFuncs - split functions in a Module into two groups: those that are
@ -329,10 +329,13 @@ static bool ExtractLoops(BugDriver &BD,
// has broken. If something broke, then we'll inform the user and stop // has broken. If something broke, then we'll inform the user and stop
// extraction. // extraction.
AbstractInterpreter *AI = BD.switchToSafeInterpreter(); AbstractInterpreter *AI = BD.switchToSafeInterpreter();
bool Failure = TestMergedProgram(BD, ToOptimizeLoopExtracted, ToNotOptimize, bool Failure;
false, Error); Module *New = TestMergedProgram(BD, ToOptimizeLoopExtracted, ToNotOptimize,
if (!Error.empty()) false, Error, Failure);
if (!New)
return false; return false;
// Delete the original and set the new program.
delete BD.swapProgramIn(New);
if (Failure) { if (Failure) {
BD.switchToInterpreter(AI); BD.switchToInterpreter(AI);
@ -695,8 +698,13 @@ static bool TestOptimizer(BugDriver &BD, Module *Test, Module *Safe,
delete Test; delete Test;
outs() << " Checking to see if the merged program executes correctly: "; outs() << " Checking to see if the merged program executes correctly: ";
bool Broken = TestMergedProgram(BD, Optimized, Safe, true, Error); bool Broken;
if (Error.empty()) outs() << (Broken ? " nope.\n" : " yup.\n"); Module *New = TestMergedProgram(BD, Optimized, Safe, true, Error, Broken);
if (New) {
outs() << (Broken ? " nope.\n" : " yup.\n");
// Delete the original and set the new program.
delete BD.swapProgramIn(New);
}
return Broken; return Broken;
} }