blob: 93135efb81559bd8daa147e3efdf09c56056106c [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 Lattnercd6f46e2006-11-09 05:57:53 +000031 AutoPick, RunLLI, RunJIT, RunLLC, RunCBE, CBE_bug, LLC_Safe
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 Lattnercd6f46e2006-11-09 05:57:53 +000050 clEnumValN(LLC_Safe, "llc-safe", "Use LLC for all"),
Chris Lattner4d143ee2004-07-16 00:08:28 +000051 clEnumValEnd),
Brian Gaekeb5ee5092003-10-21 17:41:35 +000052 cl::init(AutoPick));
Chris Lattner3c053a02003-04-23 20:31:37 +000053
Brian Gaekec5cad212004-02-11 18:37:32 +000054 cl::opt<bool>
55 CheckProgramExitCode("check-exit-code",
Misha Brukmaneed80e22004-07-23 01:30:49 +000056 cl::desc("Assume nonzero exit code is failure (default on)"),
Brian Gaekec5cad212004-02-11 18:37:32 +000057 cl::init(true));
58
Chris Lattner3c053a02003-04-23 20:31:37 +000059 cl::opt<std::string>
60 InputFile("input", cl::init("/dev/null"),
61 cl::desc("Filename to pipe in as stdin (default: /dev/null)"));
Chris Lattner7dac6582003-10-14 22:24:31 +000062
63 cl::list<std::string>
64 AdditionalSOs("additional-so",
65 cl::desc("Additional shared objects to load "
66 "into executing programs"));
Chris Lattner7d91e492004-07-24 07:53:26 +000067
Reid Spencer51ab5c82006-06-06 00:00:42 +000068 cl::list<std::string>
69 AdditionalLinkerArgs("Xlinker",
70 cl::desc("Additional arguments to pass to the linker"));
Chris Lattner4a106452002-12-23 23:50:16 +000071}
72
Brian Gaeked0fde302003-11-11 22:41:34 +000073namespace llvm {
Chris Lattnerfa761832004-01-14 03:38:37 +000074 // Anything specified after the --args option are taken as arguments to the
75 // program being debugged.
76 cl::list<std::string>
77 InputArgv("args", cl::Positional, cl::desc("<program arguments>..."),
Chris Lattner60083e22004-05-06 22:05:35 +000078 cl::ZeroOrMore, cl::PositionalEatsArgs);
Brian Gaeke636df3d2004-05-04 21:09:16 +000079
80 cl::list<std::string>
81 ToolArgv("tool-args", cl::Positional, cl::desc("<tool arguments>..."),
Chris Lattner60083e22004-05-06 22:05:35 +000082 cl::ZeroOrMore, cl::PositionalEatsArgs);
Chris Lattnerfa761832004-01-14 03:38:37 +000083}
Misha Brukman9d679cb2003-07-30 20:15:44 +000084
Chris Lattner4a106452002-12-23 23:50:16 +000085//===----------------------------------------------------------------------===//
86// BugDriver method implementation
87//
88
89/// initializeExecutionEnvironment - This method is used to set up the
90/// environment for executing LLVM programs.
91///
92bool BugDriver::initializeExecutionEnvironment() {
93 std::cout << "Initializing execution environment: ";
94
Misha Brukman41485562003-09-29 22:40:52 +000095 // Create an instance of the AbstractInterpreter interface as specified on
96 // the command line
Chris Lattner7bb11542004-02-18 20:52:02 +000097 cbe = 0;
Chris Lattner4a106452002-12-23 23:50:16 +000098 std::string Message;
Brian Gaeke636df3d2004-05-04 21:09:16 +000099
Chris Lattnercc876a72003-05-03 03:19:41 +0000100 switch (InterpreterSel) {
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000101 case AutoPick:
102 InterpreterSel = RunCBE;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000103 Interpreter = cbe = AbstractInterpreter::createCBE(getToolName(), Message,
104 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000105 if (!Interpreter) {
106 InterpreterSel = RunJIT;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000107 Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
108 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000109 }
110 if (!Interpreter) {
111 InterpreterSel = RunLLC;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000112 Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
113 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000114 }
115 if (!Interpreter) {
116 InterpreterSel = RunLLI;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000117 Interpreter = AbstractInterpreter::createLLI(getToolName(), Message,
118 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000119 }
120 if (!Interpreter) {
121 InterpreterSel = AutoPick;
122 Message = "Sorry, I can't automatically select an interpreter!\n";
123 }
124 break;
Chris Lattner769f1fe2003-10-14 21:59:36 +0000125 case RunLLI:
Brian Gaeke636df3d2004-05-04 21:09:16 +0000126 Interpreter = AbstractInterpreter::createLLI(getToolName(), Message,
127 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000128 break;
129 case RunLLC:
Brian Gaeke636df3d2004-05-04 21:09:16 +0000130 Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
131 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000132 break;
133 case RunJIT:
Brian Gaeke636df3d2004-05-04 21:09:16 +0000134 Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
135 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000136 break;
Chris Lattnercd6f46e2006-11-09 05:57:53 +0000137 case LLC_Safe:
138 Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
139 &ToolArgv);
140 break;
Chris Lattner769f1fe2003-10-14 21:59:36 +0000141 case RunCBE:
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000142 case CBE_bug:
143 Interpreter = AbstractInterpreter::createCBE(getToolName(), Message,
144 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000145 break;
Chris Lattnercc876a72003-05-03 03:19:41 +0000146 default:
Misha Brukman41485562003-09-29 22:40:52 +0000147 Message = "Sorry, this back-end is not supported by bugpoint right now!\n";
Chris Lattnercc876a72003-05-03 03:19:41 +0000148 break;
Chris Lattner4a106452002-12-23 23:50:16 +0000149 }
Misha Brukman41485562003-09-29 22:40:52 +0000150 std::cerr << Message;
Chris Lattner4a106452002-12-23 23:50:16 +0000151
Misha Brukmana259c9b2003-07-24 21:59:10 +0000152 // Initialize auxiliary tools for debugging
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000153 if (InterpreterSel == RunCBE) {
154 // We already created a CBE, reuse it.
155 cbe = Interpreter;
Chris Lattnercd6f46e2006-11-09 05:57:53 +0000156 } else if (InterpreterSel == CBE_bug || InterpreterSel == LLC_Safe) {
157 // We want to debug the CBE itself or LLC is known-good. Use LLC as the
158 // 'known-good' compiler.
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000159 std::vector<std::string> ToolArgs;
160 ToolArgs.push_back("--relocation-model=pic");
161 cbe = AbstractInterpreter::createLLC(getToolName(), Message, &ToolArgs);
162 } else {
Brian Gaeke636df3d2004-05-04 21:09:16 +0000163 cbe = AbstractInterpreter::createCBE(getToolName(), Message, &ToolArgv);
Chris Lattner7bb11542004-02-18 20:52:02 +0000164 }
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000165 if (!cbe) { std::cout << Message << "\nExiting.\n"; exit(1); }
166
Chris Lattner769f1fe2003-10-14 21:59:36 +0000167 gcc = GCC::create(getToolName(), Message);
Misha Brukmana259c9b2003-07-24 21:59:10 +0000168 if (!gcc) { std::cout << Message << "\nExiting.\n"; exit(1); }
169
Chris Lattner4a106452002-12-23 23:50:16 +0000170 // If there was an error creating the selected interpreter, quit with error.
171 return Interpreter == 0;
172}
173
Chris Lattnerea9212c2004-02-18 23:25:22 +0000174/// compileProgram - Try to compile the specified module, throwing an exception
175/// if an error occurs, or returning normally if not. This is used for code
176/// generation crash testing.
177///
178void BugDriver::compileProgram(Module *M) {
179 // Emit the program to a bytecode file...
Reid Spencer97182982004-12-15 01:53:08 +0000180 sys::Path BytecodeFile ("bugpoint-test-program.bc");
Reid Spencer51c5a282006-08-23 20:34:57 +0000181 std::string ErrMsg;
182 if (BytecodeFile.makeUnique(true,&ErrMsg)) {
183 std::cerr << ToolName << ": Error making unique filename: " << ErrMsg
184 << "\n";
185 exit(1);
186 }
Reid Spencer97182982004-12-15 01:53:08 +0000187 if (writeProgramToFile(BytecodeFile.toString(), M)) {
Chris Lattnerea9212c2004-02-18 23:25:22 +0000188 std::cerr << ToolName << ": Error emitting bytecode to file '"
189 << BytecodeFile << "'!\n";
190 exit(1);
191 }
192
193 // Remove the temporary bytecode file when we are done.
Reid Spencer5f767602004-12-16 23:04:20 +0000194 FileRemover BytecodeFileRemover(BytecodeFile);
Chris Lattnerea9212c2004-02-18 23:25:22 +0000195
196 // Actually compile the program!
Reid Spencer97182982004-12-15 01:53:08 +0000197 Interpreter->compileProgram(BytecodeFile.toString());
Chris Lattnerea9212c2004-02-18 23:25:22 +0000198}
199
Chris Lattner4a106452002-12-23 23:50:16 +0000200
201/// executeProgram - This method runs "Program", capturing the output of the
202/// program to a file, returning the filename of the file. A recommended
203/// filename may be optionally specified.
204///
205std::string BugDriver::executeProgram(std::string OutputFile,
Misha Brukman50733362003-07-24 18:17:43 +0000206 std::string BytecodeFile,
Chris Lattner769f1fe2003-10-14 21:59:36 +0000207 const std::string &SharedObj,
Brian Gaekec5cad212004-02-11 18:37:32 +0000208 AbstractInterpreter *AI,
209 bool *ProgramExitedNonzero) {
Chris Lattner769f1fe2003-10-14 21:59:36 +0000210 if (AI == 0) AI = Interpreter;
211 assert(AI && "Interpreter should have been created already!");
Chris Lattner4a106452002-12-23 23:50:16 +0000212 bool CreatedBytecode = false;
Reid Spencer51c5a282006-08-23 20:34:57 +0000213 std::string ErrMsg;
Chris Lattner4a106452002-12-23 23:50:16 +0000214 if (BytecodeFile.empty()) {
215 // Emit the program to a bytecode file...
Reid Spencer97182982004-12-15 01:53:08 +0000216 sys::Path uniqueFilename("bugpoint-test-program.bc");
Reid Spencer51c5a282006-08-23 20:34:57 +0000217 if (uniqueFilename.makeUnique(true, &ErrMsg)) {
218 std::cerr << ToolName << ": Error making unique filename: "
219 << ErrMsg << "!\n";
220 exit(1);
221 }
Reid Spencer97182982004-12-15 01:53:08 +0000222 BytecodeFile = uniqueFilename.toString();
Chris Lattner4a106452002-12-23 23:50:16 +0000223
224 if (writeProgramToFile(BytecodeFile, Program)) {
225 std::cerr << ToolName << ": Error emitting bytecode to file '"
Misha Brukman50733362003-07-24 18:17:43 +0000226 << BytecodeFile << "'!\n";
Chris Lattner4a106452002-12-23 23:50:16 +0000227 exit(1);
228 }
229 CreatedBytecode = true;
230 }
231
Chris Lattner97092722004-02-18 22:01:21 +0000232 // Remove the temporary bytecode file when we are done.
Brian Gaeke06c375b2004-12-22 22:33:33 +0000233 sys::Path BytecodePath (BytecodeFile);
234 FileRemover BytecodeFileRemover(BytecodePath, CreatedBytecode);
Chris Lattner97092722004-02-18 22:01:21 +0000235
Chris Lattner4a106452002-12-23 23:50:16 +0000236 if (OutputFile.empty()) OutputFile = "bugpoint-execution-output";
Misha Brukman50733362003-07-24 18:17:43 +0000237
Chris Lattner4a106452002-12-23 23:50:16 +0000238 // Check to see if this is a valid output filename...
Reid Spencer97182982004-12-15 01:53:08 +0000239 sys::Path uniqueFile(OutputFile);
Reid Spencer51c5a282006-08-23 20:34:57 +0000240 if (uniqueFile.makeUnique(true, &ErrMsg)) {
241 std::cerr << ToolName << ": Error making unique filename: "
242 << ErrMsg << "\n";
243 exit(1);
244 }
Reid Spencer97182982004-12-15 01:53:08 +0000245 OutputFile = uniqueFile.toString();
Chris Lattner4a106452002-12-23 23:50:16 +0000246
Chris Lattner769f1fe2003-10-14 21:59:36 +0000247 // Figure out which shared objects to run, if any.
Chris Lattner7dac6582003-10-14 22:24:31 +0000248 std::vector<std::string> SharedObjs(AdditionalSOs);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000249 if (!SharedObj.empty())
250 SharedObjs.push_back(SharedObj);
251
Reid Spencer51ab5c82006-06-06 00:00:42 +0000252
253 // If this is an LLC or CBE run, then the GCC compiler might get run to
254 // compile the program. If so, we should pass the user's -Xlinker options
255 // as the GCCArgs.
256 int RetVal = 0;
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000257 if (InterpreterSel == RunLLC || InterpreterSel == RunCBE ||
258 InterpreterSel == CBE_bug)
Reid Spencer51ab5c82006-06-06 00:00:42 +0000259 RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
260 OutputFile, AdditionalLinkerArgs, SharedObjs,
Chris Lattner9686ae72006-06-13 03:10:48 +0000261 Timeout);
Reid Spencer51ab5c82006-06-06 00:00:42 +0000262 else
263 RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
264 OutputFile, std::vector<std::string>(),
Chris Lattner9686ae72006-06-13 03:10:48 +0000265 SharedObjs, Timeout);
Chris Lattner7d91e492004-07-24 07:53:26 +0000266
267 if (RetVal == -1) {
268 std::cerr << "<timeout>";
269 static bool FirstTimeout = true;
270 if (FirstTimeout) {
271 std::cout << "\n"
272 "*** Program execution timed out! This mechanism is designed to handle\n"
273 " programs stuck in infinite loops gracefully. The -timeout option\n"
274 " can be used to change the timeout threshold or disable it completely\n"
275 " (with -timeout=0). This message is only displayed once.\n";
276 FirstTimeout = false;
277 }
278 }
Chris Lattner769f1fe2003-10-14 21:59:36 +0000279
Brian Gaekec5cad212004-02-11 18:37:32 +0000280 if (ProgramExitedNonzero != 0)
281 *ProgramExitedNonzero = (RetVal != 0);
Chris Lattner4a106452002-12-23 23:50:16 +0000282
Chris Lattner4a106452002-12-23 23:50:16 +0000283 // Return the filename we captured the output to.
284 return OutputFile;
285}
286
Brian Gaekec5cad212004-02-11 18:37:32 +0000287/// executeProgramWithCBE - Used to create reference output with the C
288/// backend, if reference output is not provided.
289///
290std::string BugDriver::executeProgramWithCBE(std::string OutputFile) {
291 bool ProgramExitedNonzero;
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000292 std::string outFN = executeProgram(OutputFile, "", "", cbe,
Brian Gaekec5cad212004-02-11 18:37:32 +0000293 &ProgramExitedNonzero);
294 if (ProgramExitedNonzero) {
295 std::cerr
296 << "Warning: While generating reference output, program exited with\n"
297 << "non-zero exit code. This will NOT be treated as a failure.\n";
298 CheckProgramExitCode = false;
299 }
300 return outFN;
301}
Misha Brukman50733362003-07-24 18:17:43 +0000302
Chris Lattnera0f5b152003-10-14 21:09:11 +0000303std::string BugDriver::compileSharedObject(const std::string &BytecodeFile) {
Misha Brukman50733362003-07-24 18:17:43 +0000304 assert(Interpreter && "Interpreter should have been created already!");
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000305 sys::Path OutputFile;
Misha Brukman50733362003-07-24 18:17:43 +0000306
307 // Using CBE
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000308 GCC::FileType FT = cbe->OutputCode(BytecodeFile, OutputFile);
Misha Brukman50733362003-07-24 18:17:43 +0000309
Chris Lattnera0f5b152003-10-14 21:09:11 +0000310 std::string SharedObjectFile;
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000311 if (gcc->MakeSharedObject(OutputFile.toString(), FT,
Chris Lattner130e2a32006-06-27 20:35:36 +0000312 SharedObjectFile, AdditionalLinkerArgs))
Chris Lattnera0f5b152003-10-14 21:09:11 +0000313 exit(1);
Misha Brukman50733362003-07-24 18:17:43 +0000314
315 // Remove the intermediate C file
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000316 OutputFile.eraseFromDisk();
Misha Brukman50733362003-07-24 18:17:43 +0000317
Chris Lattner6ebe44d2003-10-19 21:54:13 +0000318 return "./" + SharedObjectFile;
Misha Brukman50733362003-07-24 18:17:43 +0000319}
320
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000321/// createReferenceFile - calls compileProgram and then records the output
322/// into ReferenceOutputFile. Returns true if reference file created, false
323/// otherwise. Note: initializeExecutionEnvironment should be called BEFORE
324/// this function.
325///
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000326bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000327 try {
328 compileProgram(Program);
Jeff Cohend41b30d2006-11-05 19:31:28 +0000329 } catch (ToolExecutionError &) {
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000330 return false;
331 }
332 try {
333 ReferenceOutputFile = executeProgramWithCBE(Filename);
334 std::cout << "Reference output is: " << ReferenceOutputFile << "\n\n";
335 } catch (ToolExecutionError &TEE) {
336 std::cerr << TEE.what();
337 if (Interpreter != cbe) {
338 std::cerr << "*** There is a bug running the C backend. Either debug"
339 << " it (use the -run-cbe bugpoint option), or fix the error"
340 << " some other way.\n";
341 }
342 return false;
343 }
344 return true;
345}
Misha Brukman50733362003-07-24 18:17:43 +0000346
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000347/// diffProgram - This method executes the specified module and diffs the
348/// output against the file specified by ReferenceOutputFile. If the output
349/// is different, true is returned. If there is a problem with the code
350/// generator (e.g., llc crashes), this will throw an exception.
Chris Lattner4a106452002-12-23 23:50:16 +0000351///
Misha Brukman50733362003-07-24 18:17:43 +0000352bool BugDriver::diffProgram(const std::string &BytecodeFile,
353 const std::string &SharedObject,
Chris Lattner640f22e2003-04-24 17:02:17 +0000354 bool RemoveBytecode) {
Brian Gaekec5cad212004-02-11 18:37:32 +0000355 bool ProgramExitedNonzero;
356
Chris Lattner4a106452002-12-23 23:50:16 +0000357 // Execute the program, generating an output file...
Chris Lattner130e2a32006-06-27 20:35:36 +0000358 sys::Path Output(executeProgram("", BytecodeFile, SharedObject, 0,
Reid Spencer5f767602004-12-16 23:04:20 +0000359 &ProgramExitedNonzero));
Brian Gaekec5cad212004-02-11 18:37:32 +0000360
361 // If we're checking the program exit code, assume anything nonzero is bad.
Chris Lattner58d84ce2004-04-02 05:33:06 +0000362 if (CheckProgramExitCode && ProgramExitedNonzero) {
Reid Spencera229c5c2005-07-08 03:08:58 +0000363 Output.eraseFromDisk();
Misha Brukman3da94ae2005-04-22 00:00:37 +0000364 if (RemoveBytecode)
Reid Spencera229c5c2005-07-08 03:08:58 +0000365 sys::Path(BytecodeFile).eraseFromDisk();
Brian Gaekec5cad212004-02-11 18:37:32 +0000366 return true;
Chris Lattner58d84ce2004-04-02 05:33:06 +0000367 }
Chris Lattner4a106452002-12-23 23:50:16 +0000368
Chris Lattner65f62792003-08-01 20:29:45 +0000369 std::string Error;
Chris Lattner4a106452002-12-23 23:50:16 +0000370 bool FilesDifferent = false;
Chris Lattnera328c512005-01-23 03:45:26 +0000371 if (int Diff = DiffFilesWithTolerance(sys::Path(ReferenceOutputFile),
372 sys::Path(Output.toString()),
373 AbsTolerance, RelTolerance, &Error)) {
374 if (Diff == 2) {
Misha Brukmaneed80e22004-07-23 01:30:49 +0000375 std::cerr << "While diffing output: " << Error << '\n';
Chris Lattner65f62792003-08-01 20:29:45 +0000376 exit(1);
377 }
378 FilesDifferent = true;
379 }
Misha Brukman3da94ae2005-04-22 00:00:37 +0000380
Chris Lattner1a28a2b2003-10-18 21:02:51 +0000381 // Remove the generated output.
Reid Spencera229c5c2005-07-08 03:08:58 +0000382 Output.eraseFromDisk();
Chris Lattner4a106452002-12-23 23:50:16 +0000383
Chris Lattner1a28a2b2003-10-18 21:02:51 +0000384 // Remove the bytecode file if we are supposed to.
Jeff Cohen00b168892005-07-27 06:12:32 +0000385 if (RemoveBytecode)
Reid Spencera229c5c2005-07-08 03:08:58 +0000386 sys::Path(BytecodeFile).eraseFromDisk();
Chris Lattner4a106452002-12-23 23:50:16 +0000387 return FilesDifferent;
388}
Misha Brukman91eabc12003-07-28 19:16:14 +0000389
390bool BugDriver::isExecutingJIT() {
391 return InterpreterSel == RunJIT;
392}
Brian Gaeked0fde302003-11-11 22:41:34 +0000393