blob: dedf91eb035b09497512250637072843d19bab64 [file] [log] [blame]
Chris Lattner4a106452002-12-23 23:50:16 +00001//===- ExecutionDriver.cpp - Allow execution of LLVM program --------------===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
John Criswell7c0e0222003-10-20 17:47:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
John Criswell7c0e0222003-10-20 17:47:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner4a106452002-12-23 23:50:16 +00009//
10// This file contains code used to execute the program utilizing one of the
11// various ways of running LLVM bytecode.
12//
13//===----------------------------------------------------------------------===//
14
Chris Lattner4a106452002-12-23 23:50:16 +000015#include "BugDriver.h"
Chris Lattnerf1b20d82006-06-06 22:30:59 +000016#include "ToolRunner.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000017#include "llvm/Support/CommandLine.h"
18#include "llvm/Support/Debug.h"
19#include "llvm/Support/FileUtilities.h"
20#include "llvm/Support/SystemUtils.h"
Chris Lattner4a106452002-12-23 23:50:16 +000021#include <fstream>
Chris Lattnere31a9cc2006-01-22 22:53:40 +000022#include <iostream>
Reid Spencer51ab5c82006-06-06 00:00:42 +000023
Brian Gaeked0fde302003-11-11 22:41:34 +000024using namespace llvm;
25
Chris Lattner4a106452002-12-23 23:50:16 +000026namespace {
27 // OutputType - Allow the user to specify the way code should be run, to test
28 // for miscompilation.
29 //
30 enum OutputType {
Chris Lattnerc600f3c2006-09-15 21:29:15 +000031 AutoPick, RunLLI, RunJIT, RunLLC, RunCBE, CBE_bug
Chris Lattner4a106452002-12-23 23:50:16 +000032 };
Misha Brukman41485562003-09-29 22:40:52 +000033
Chris Lattnera328c512005-01-23 03:45:26 +000034 cl::opt<double>
35 AbsTolerance("abs-tolerance", cl::desc("Absolute error tolerated"),
36 cl::init(0.0));
37 cl::opt<double>
38 RelTolerance("rel-tolerance", cl::desc("Relative error tolerated"),
39 cl::init(0.0));
40
Chris Lattner4a106452002-12-23 23:50:16 +000041 cl::opt<OutputType>
42 InterpreterSel(cl::desc("Specify how LLVM code should be executed:"),
Brian Gaekeb5ee5092003-10-21 17:41:35 +000043 cl::values(clEnumValN(AutoPick, "auto", "Use best guess"),
Misha Brukmanb687d822004-04-19 03:12:35 +000044 clEnumValN(RunLLI, "run-int",
45 "Execute with the interpreter"),
Misha Brukman50733362003-07-24 18:17:43 +000046 clEnumValN(RunJIT, "run-jit", "Execute with JIT"),
47 clEnumValN(RunLLC, "run-llc", "Compile with LLC"),
48 clEnumValN(RunCBE, "run-cbe", "Compile with CBE"),
Chris Lattnerc600f3c2006-09-15 21:29:15 +000049 clEnumValN(CBE_bug,"cbe-bug", "Find CBE bugs"),
Chris Lattner4d143ee2004-07-16 00:08:28 +000050 clEnumValEnd),
Brian Gaekeb5ee5092003-10-21 17:41:35 +000051 cl::init(AutoPick));
Chris Lattner3c053a02003-04-23 20:31:37 +000052
Brian Gaekec5cad212004-02-11 18:37:32 +000053 cl::opt<bool>
54 CheckProgramExitCode("check-exit-code",
Misha Brukmaneed80e22004-07-23 01:30:49 +000055 cl::desc("Assume nonzero exit code is failure (default on)"),
Brian Gaekec5cad212004-02-11 18:37:32 +000056 cl::init(true));
57
Chris Lattner3c053a02003-04-23 20:31:37 +000058 cl::opt<std::string>
59 InputFile("input", cl::init("/dev/null"),
60 cl::desc("Filename to pipe in as stdin (default: /dev/null)"));
Chris Lattner7dac6582003-10-14 22:24:31 +000061
62 cl::list<std::string>
63 AdditionalSOs("additional-so",
64 cl::desc("Additional shared objects to load "
65 "into executing programs"));
Chris Lattner7d91e492004-07-24 07:53:26 +000066
Reid Spencer51ab5c82006-06-06 00:00:42 +000067 cl::list<std::string>
68 AdditionalLinkerArgs("Xlinker",
69 cl::desc("Additional arguments to pass to the linker"));
Chris Lattner4a106452002-12-23 23:50:16 +000070}
71
Brian Gaeked0fde302003-11-11 22:41:34 +000072namespace llvm {
Chris Lattnerfa761832004-01-14 03:38:37 +000073 // Anything specified after the --args option are taken as arguments to the
74 // program being debugged.
75 cl::list<std::string>
76 InputArgv("args", cl::Positional, cl::desc("<program arguments>..."),
Chris Lattner60083e22004-05-06 22:05:35 +000077 cl::ZeroOrMore, cl::PositionalEatsArgs);
Brian Gaeke636df3d2004-05-04 21:09:16 +000078
79 cl::list<std::string>
80 ToolArgv("tool-args", cl::Positional, cl::desc("<tool arguments>..."),
Chris Lattner60083e22004-05-06 22:05:35 +000081 cl::ZeroOrMore, cl::PositionalEatsArgs);
Chris Lattnerfa761832004-01-14 03:38:37 +000082}
Misha Brukman9d679cb2003-07-30 20:15:44 +000083
Chris Lattner4a106452002-12-23 23:50:16 +000084//===----------------------------------------------------------------------===//
85// BugDriver method implementation
86//
87
88/// initializeExecutionEnvironment - This method is used to set up the
89/// environment for executing LLVM programs.
90///
91bool BugDriver::initializeExecutionEnvironment() {
92 std::cout << "Initializing execution environment: ";
93
Misha Brukman41485562003-09-29 22:40:52 +000094 // Create an instance of the AbstractInterpreter interface as specified on
95 // the command line
Chris Lattner7bb11542004-02-18 20:52:02 +000096 cbe = 0;
Chris Lattner4a106452002-12-23 23:50:16 +000097 std::string Message;
Brian Gaeke636df3d2004-05-04 21:09:16 +000098
Chris Lattnercc876a72003-05-03 03:19:41 +000099 switch (InterpreterSel) {
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000100 case AutoPick:
101 InterpreterSel = RunCBE;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000102 Interpreter = cbe = AbstractInterpreter::createCBE(getToolName(), Message,
103 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000104 if (!Interpreter) {
105 InterpreterSel = RunJIT;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000106 Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
107 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000108 }
109 if (!Interpreter) {
110 InterpreterSel = RunLLC;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000111 Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
112 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000113 }
114 if (!Interpreter) {
115 InterpreterSel = RunLLI;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000116 Interpreter = AbstractInterpreter::createLLI(getToolName(), Message,
117 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000118 }
119 if (!Interpreter) {
120 InterpreterSel = AutoPick;
121 Message = "Sorry, I can't automatically select an interpreter!\n";
122 }
123 break;
Chris Lattner769f1fe2003-10-14 21:59:36 +0000124 case RunLLI:
Brian Gaeke636df3d2004-05-04 21:09:16 +0000125 Interpreter = AbstractInterpreter::createLLI(getToolName(), Message,
126 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000127 break;
128 case RunLLC:
Brian Gaeke636df3d2004-05-04 21:09:16 +0000129 Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
130 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000131 break;
132 case RunJIT:
Brian Gaeke636df3d2004-05-04 21:09:16 +0000133 Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
134 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000135 break;
136 case RunCBE:
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000137 case CBE_bug:
138 Interpreter = AbstractInterpreter::createCBE(getToolName(), Message,
139 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000140 break;
Chris Lattnercc876a72003-05-03 03:19:41 +0000141 default:
Misha Brukman41485562003-09-29 22:40:52 +0000142 Message = "Sorry, this back-end is not supported by bugpoint right now!\n";
Chris Lattnercc876a72003-05-03 03:19:41 +0000143 break;
Chris Lattner4a106452002-12-23 23:50:16 +0000144 }
Misha Brukman41485562003-09-29 22:40:52 +0000145 std::cerr << Message;
Chris Lattner4a106452002-12-23 23:50:16 +0000146
Misha Brukmana259c9b2003-07-24 21:59:10 +0000147 // Initialize auxiliary tools for debugging
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000148 if (InterpreterSel == RunCBE) {
149 // We already created a CBE, reuse it.
150 cbe = Interpreter;
151 } else if (InterpreterSel == CBE_bug) {
152 // We want to debug the CBE itself. Use LLC as the 'known-good' compiler.
153 std::vector<std::string> ToolArgs;
154 ToolArgs.push_back("--relocation-model=pic");
155 cbe = AbstractInterpreter::createLLC(getToolName(), Message, &ToolArgs);
156 } else {
Brian Gaeke636df3d2004-05-04 21:09:16 +0000157 cbe = AbstractInterpreter::createCBE(getToolName(), Message, &ToolArgv);
Chris Lattner7bb11542004-02-18 20:52:02 +0000158 }
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000159 if (!cbe) { std::cout << Message << "\nExiting.\n"; exit(1); }
160
Chris Lattner769f1fe2003-10-14 21:59:36 +0000161 gcc = GCC::create(getToolName(), Message);
Misha Brukmana259c9b2003-07-24 21:59:10 +0000162 if (!gcc) { std::cout << Message << "\nExiting.\n"; exit(1); }
163
Chris Lattner4a106452002-12-23 23:50:16 +0000164 // If there was an error creating the selected interpreter, quit with error.
165 return Interpreter == 0;
166}
167
Chris Lattnerea9212c2004-02-18 23:25:22 +0000168/// compileProgram - Try to compile the specified module, throwing an exception
169/// if an error occurs, or returning normally if not. This is used for code
170/// generation crash testing.
171///
172void BugDriver::compileProgram(Module *M) {
173 // Emit the program to a bytecode file...
Reid Spencer97182982004-12-15 01:53:08 +0000174 sys::Path BytecodeFile ("bugpoint-test-program.bc");
Reid Spencer51c5a282006-08-23 20:34:57 +0000175 std::string ErrMsg;
176 if (BytecodeFile.makeUnique(true,&ErrMsg)) {
177 std::cerr << ToolName << ": Error making unique filename: " << ErrMsg
178 << "\n";
179 exit(1);
180 }
Reid Spencer97182982004-12-15 01:53:08 +0000181 if (writeProgramToFile(BytecodeFile.toString(), M)) {
Chris Lattnerea9212c2004-02-18 23:25:22 +0000182 std::cerr << ToolName << ": Error emitting bytecode to file '"
183 << BytecodeFile << "'!\n";
184 exit(1);
185 }
186
187 // Remove the temporary bytecode file when we are done.
Reid Spencer5f767602004-12-16 23:04:20 +0000188 FileRemover BytecodeFileRemover(BytecodeFile);
Chris Lattnerea9212c2004-02-18 23:25:22 +0000189
190 // Actually compile the program!
Reid Spencer97182982004-12-15 01:53:08 +0000191 Interpreter->compileProgram(BytecodeFile.toString());
Chris Lattnerea9212c2004-02-18 23:25:22 +0000192}
193
Chris Lattner4a106452002-12-23 23:50:16 +0000194
195/// executeProgram - This method runs "Program", capturing the output of the
196/// program to a file, returning the filename of the file. A recommended
197/// filename may be optionally specified.
198///
199std::string BugDriver::executeProgram(std::string OutputFile,
Misha Brukman50733362003-07-24 18:17:43 +0000200 std::string BytecodeFile,
Chris Lattner769f1fe2003-10-14 21:59:36 +0000201 const std::string &SharedObj,
Brian Gaekec5cad212004-02-11 18:37:32 +0000202 AbstractInterpreter *AI,
203 bool *ProgramExitedNonzero) {
Chris Lattner769f1fe2003-10-14 21:59:36 +0000204 if (AI == 0) AI = Interpreter;
205 assert(AI && "Interpreter should have been created already!");
Chris Lattner4a106452002-12-23 23:50:16 +0000206 bool CreatedBytecode = false;
Reid Spencer51c5a282006-08-23 20:34:57 +0000207 std::string ErrMsg;
Chris Lattner4a106452002-12-23 23:50:16 +0000208 if (BytecodeFile.empty()) {
209 // Emit the program to a bytecode file...
Reid Spencer97182982004-12-15 01:53:08 +0000210 sys::Path uniqueFilename("bugpoint-test-program.bc");
Reid Spencer51c5a282006-08-23 20:34:57 +0000211 if (uniqueFilename.makeUnique(true, &ErrMsg)) {
212 std::cerr << ToolName << ": Error making unique filename: "
213 << ErrMsg << "!\n";
214 exit(1);
215 }
Reid Spencer97182982004-12-15 01:53:08 +0000216 BytecodeFile = uniqueFilename.toString();
Chris Lattner4a106452002-12-23 23:50:16 +0000217
218 if (writeProgramToFile(BytecodeFile, Program)) {
219 std::cerr << ToolName << ": Error emitting bytecode to file '"
Misha Brukman50733362003-07-24 18:17:43 +0000220 << BytecodeFile << "'!\n";
Chris Lattner4a106452002-12-23 23:50:16 +0000221 exit(1);
222 }
223 CreatedBytecode = true;
224 }
225
Chris Lattner97092722004-02-18 22:01:21 +0000226 // Remove the temporary bytecode file when we are done.
Brian Gaeke06c375b2004-12-22 22:33:33 +0000227 sys::Path BytecodePath (BytecodeFile);
228 FileRemover BytecodeFileRemover(BytecodePath, CreatedBytecode);
Chris Lattner97092722004-02-18 22:01:21 +0000229
Chris Lattner4a106452002-12-23 23:50:16 +0000230 if (OutputFile.empty()) OutputFile = "bugpoint-execution-output";
Misha Brukman50733362003-07-24 18:17:43 +0000231
Chris Lattner4a106452002-12-23 23:50:16 +0000232 // Check to see if this is a valid output filename...
Reid Spencer97182982004-12-15 01:53:08 +0000233 sys::Path uniqueFile(OutputFile);
Reid Spencer51c5a282006-08-23 20:34:57 +0000234 if (uniqueFile.makeUnique(true, &ErrMsg)) {
235 std::cerr << ToolName << ": Error making unique filename: "
236 << ErrMsg << "\n";
237 exit(1);
238 }
Reid Spencer97182982004-12-15 01:53:08 +0000239 OutputFile = uniqueFile.toString();
Chris Lattner4a106452002-12-23 23:50:16 +0000240
Chris Lattner769f1fe2003-10-14 21:59:36 +0000241 // Figure out which shared objects to run, if any.
Chris Lattner7dac6582003-10-14 22:24:31 +0000242 std::vector<std::string> SharedObjs(AdditionalSOs);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000243 if (!SharedObj.empty())
244 SharedObjs.push_back(SharedObj);
245
Reid Spencer51ab5c82006-06-06 00:00:42 +0000246
247 // If this is an LLC or CBE run, then the GCC compiler might get run to
248 // compile the program. If so, we should pass the user's -Xlinker options
249 // as the GCCArgs.
250 int RetVal = 0;
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000251 if (InterpreterSel == RunLLC || InterpreterSel == RunCBE ||
252 InterpreterSel == CBE_bug)
Reid Spencer51ab5c82006-06-06 00:00:42 +0000253 RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
254 OutputFile, AdditionalLinkerArgs, SharedObjs,
Chris Lattner9686ae72006-06-13 03:10:48 +0000255 Timeout);
Reid Spencer51ab5c82006-06-06 00:00:42 +0000256 else
257 RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
258 OutputFile, std::vector<std::string>(),
Chris Lattner9686ae72006-06-13 03:10:48 +0000259 SharedObjs, Timeout);
Chris Lattner7d91e492004-07-24 07:53:26 +0000260
261 if (RetVal == -1) {
262 std::cerr << "<timeout>";
263 static bool FirstTimeout = true;
264 if (FirstTimeout) {
265 std::cout << "\n"
266 "*** Program execution timed out! This mechanism is designed to handle\n"
267 " programs stuck in infinite loops gracefully. The -timeout option\n"
268 " can be used to change the timeout threshold or disable it completely\n"
269 " (with -timeout=0). This message is only displayed once.\n";
270 FirstTimeout = false;
271 }
272 }
Chris Lattner769f1fe2003-10-14 21:59:36 +0000273
Brian Gaekec5cad212004-02-11 18:37:32 +0000274 if (ProgramExitedNonzero != 0)
275 *ProgramExitedNonzero = (RetVal != 0);
Chris Lattner4a106452002-12-23 23:50:16 +0000276
Chris Lattner4a106452002-12-23 23:50:16 +0000277 // Return the filename we captured the output to.
278 return OutputFile;
279}
280
Brian Gaekec5cad212004-02-11 18:37:32 +0000281/// executeProgramWithCBE - Used to create reference output with the C
282/// backend, if reference output is not provided.
283///
284std::string BugDriver::executeProgramWithCBE(std::string OutputFile) {
285 bool ProgramExitedNonzero;
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000286 std::string outFN = executeProgram(OutputFile, "", "", cbe,
Brian Gaekec5cad212004-02-11 18:37:32 +0000287 &ProgramExitedNonzero);
288 if (ProgramExitedNonzero) {
289 std::cerr
290 << "Warning: While generating reference output, program exited with\n"
291 << "non-zero exit code. This will NOT be treated as a failure.\n";
292 CheckProgramExitCode = false;
293 }
294 return outFN;
295}
Misha Brukman50733362003-07-24 18:17:43 +0000296
Chris Lattnera0f5b152003-10-14 21:09:11 +0000297std::string BugDriver::compileSharedObject(const std::string &BytecodeFile) {
Misha Brukman50733362003-07-24 18:17:43 +0000298 assert(Interpreter && "Interpreter should have been created already!");
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000299 sys::Path OutputFile;
Misha Brukman50733362003-07-24 18:17:43 +0000300
301 // Using CBE
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000302 GCC::FileType FT = cbe->OutputCode(BytecodeFile, OutputFile);
Misha Brukman50733362003-07-24 18:17:43 +0000303
Chris Lattnera0f5b152003-10-14 21:09:11 +0000304 std::string SharedObjectFile;
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000305 if (gcc->MakeSharedObject(OutputFile.toString(), FT,
Chris Lattner130e2a32006-06-27 20:35:36 +0000306 SharedObjectFile, AdditionalLinkerArgs))
Chris Lattnera0f5b152003-10-14 21:09:11 +0000307 exit(1);
Misha Brukman50733362003-07-24 18:17:43 +0000308
309 // Remove the intermediate C file
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000310 OutputFile.eraseFromDisk();
Misha Brukman50733362003-07-24 18:17:43 +0000311
Chris Lattner6ebe44d2003-10-19 21:54:13 +0000312 return "./" + SharedObjectFile;
Misha Brukman50733362003-07-24 18:17:43 +0000313}
314
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000315/// createReferenceFile - calls compileProgram and then records the output
316/// into ReferenceOutputFile. Returns true if reference file created, false
317/// otherwise. Note: initializeExecutionEnvironment should be called BEFORE
318/// this function.
319///
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000320bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000321 try {
322 compileProgram(Program);
Jeff Cohend41b30d2006-11-05 19:31:28 +0000323 } catch (ToolExecutionError &) {
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000324 return false;
325 }
326 try {
327 ReferenceOutputFile = executeProgramWithCBE(Filename);
328 std::cout << "Reference output is: " << ReferenceOutputFile << "\n\n";
329 } catch (ToolExecutionError &TEE) {
330 std::cerr << TEE.what();
331 if (Interpreter != cbe) {
332 std::cerr << "*** There is a bug running the C backend. Either debug"
333 << " it (use the -run-cbe bugpoint option), or fix the error"
334 << " some other way.\n";
335 }
336 return false;
337 }
338 return true;
339}
Misha Brukman50733362003-07-24 18:17:43 +0000340
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000341/// diffProgram - This method executes the specified module and diffs the
342/// output against the file specified by ReferenceOutputFile. If the output
343/// is different, true is returned. If there is a problem with the code
344/// generator (e.g., llc crashes), this will throw an exception.
Chris Lattner4a106452002-12-23 23:50:16 +0000345///
Misha Brukman50733362003-07-24 18:17:43 +0000346bool BugDriver::diffProgram(const std::string &BytecodeFile,
347 const std::string &SharedObject,
Chris Lattner640f22e2003-04-24 17:02:17 +0000348 bool RemoveBytecode) {
Brian Gaekec5cad212004-02-11 18:37:32 +0000349 bool ProgramExitedNonzero;
350
Chris Lattner4a106452002-12-23 23:50:16 +0000351 // Execute the program, generating an output file...
Chris Lattner130e2a32006-06-27 20:35:36 +0000352 sys::Path Output(executeProgram("", BytecodeFile, SharedObject, 0,
Reid Spencer5f767602004-12-16 23:04:20 +0000353 &ProgramExitedNonzero));
Brian Gaekec5cad212004-02-11 18:37:32 +0000354
355 // If we're checking the program exit code, assume anything nonzero is bad.
Chris Lattner58d84ce2004-04-02 05:33:06 +0000356 if (CheckProgramExitCode && ProgramExitedNonzero) {
Reid Spencera229c5c2005-07-08 03:08:58 +0000357 Output.eraseFromDisk();
Misha Brukman3da94ae2005-04-22 00:00:37 +0000358 if (RemoveBytecode)
Reid Spencera229c5c2005-07-08 03:08:58 +0000359 sys::Path(BytecodeFile).eraseFromDisk();
Brian Gaekec5cad212004-02-11 18:37:32 +0000360 return true;
Chris Lattner58d84ce2004-04-02 05:33:06 +0000361 }
Chris Lattner4a106452002-12-23 23:50:16 +0000362
Chris Lattner65f62792003-08-01 20:29:45 +0000363 std::string Error;
Chris Lattner4a106452002-12-23 23:50:16 +0000364 bool FilesDifferent = false;
Chris Lattnera328c512005-01-23 03:45:26 +0000365 if (int Diff = DiffFilesWithTolerance(sys::Path(ReferenceOutputFile),
366 sys::Path(Output.toString()),
367 AbsTolerance, RelTolerance, &Error)) {
368 if (Diff == 2) {
Misha Brukmaneed80e22004-07-23 01:30:49 +0000369 std::cerr << "While diffing output: " << Error << '\n';
Chris Lattner65f62792003-08-01 20:29:45 +0000370 exit(1);
371 }
372 FilesDifferent = true;
373 }
Misha Brukman3da94ae2005-04-22 00:00:37 +0000374
Chris Lattner1a28a2b2003-10-18 21:02:51 +0000375 // Remove the generated output.
Reid Spencera229c5c2005-07-08 03:08:58 +0000376 Output.eraseFromDisk();
Chris Lattner4a106452002-12-23 23:50:16 +0000377
Chris Lattner1a28a2b2003-10-18 21:02:51 +0000378 // Remove the bytecode file if we are supposed to.
Jeff Cohen00b168892005-07-27 06:12:32 +0000379 if (RemoveBytecode)
Reid Spencera229c5c2005-07-08 03:08:58 +0000380 sys::Path(BytecodeFile).eraseFromDisk();
Chris Lattner4a106452002-12-23 23:50:16 +0000381 return FilesDifferent;
382}
Misha Brukman91eabc12003-07-28 19:16:14 +0000383
384bool BugDriver::isExecutingJIT() {
385 return InterpreterSel == RunJIT;
386}
Brian Gaeked0fde302003-11-11 22:41:34 +0000387