blob: 9a670c950c0c15eb6f540c1e500076e98d89e2a6 [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
Reid Spencer5e1452c2006-11-28 07:04:10 +000059 cl::opt<bool>
60 AppendProgramExitCode("append-exit-code",
61 cl::desc("Append the exit code to the output so it gets diff'd too"),
62 cl::init(false));
63
Chris Lattner3c053a02003-04-23 20:31:37 +000064 cl::opt<std::string>
65 InputFile("input", cl::init("/dev/null"),
66 cl::desc("Filename to pipe in as stdin (default: /dev/null)"));
Chris Lattner7dac6582003-10-14 22:24:31 +000067
68 cl::list<std::string>
69 AdditionalSOs("additional-so",
70 cl::desc("Additional shared objects to load "
71 "into executing programs"));
Chris Lattner7d91e492004-07-24 07:53:26 +000072
Reid Spencer51ab5c82006-06-06 00:00:42 +000073 cl::list<std::string>
74 AdditionalLinkerArgs("Xlinker",
75 cl::desc("Additional arguments to pass to the linker"));
Chris Lattner4a106452002-12-23 23:50:16 +000076}
77
Brian Gaeked0fde302003-11-11 22:41:34 +000078namespace llvm {
Chris Lattnerfa761832004-01-14 03:38:37 +000079 // Anything specified after the --args option are taken as arguments to the
80 // program being debugged.
81 cl::list<std::string>
82 InputArgv("args", cl::Positional, cl::desc("<program arguments>..."),
Chris Lattner60083e22004-05-06 22:05:35 +000083 cl::ZeroOrMore, cl::PositionalEatsArgs);
Brian Gaeke636df3d2004-05-04 21:09:16 +000084
85 cl::list<std::string>
86 ToolArgv("tool-args", cl::Positional, cl::desc("<tool arguments>..."),
Chris Lattner60083e22004-05-06 22:05:35 +000087 cl::ZeroOrMore, cl::PositionalEatsArgs);
Chris Lattnerfa761832004-01-14 03:38:37 +000088}
Misha Brukman9d679cb2003-07-30 20:15:44 +000089
Chris Lattner4a106452002-12-23 23:50:16 +000090//===----------------------------------------------------------------------===//
91// BugDriver method implementation
92//
93
94/// initializeExecutionEnvironment - This method is used to set up the
95/// environment for executing LLVM programs.
96///
97bool BugDriver::initializeExecutionEnvironment() {
98 std::cout << "Initializing execution environment: ";
99
Misha Brukman41485562003-09-29 22:40:52 +0000100 // Create an instance of the AbstractInterpreter interface as specified on
101 // the command line
Chris Lattner7bb11542004-02-18 20:52:02 +0000102 cbe = 0;
Chris Lattner4a106452002-12-23 23:50:16 +0000103 std::string Message;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000104
Chris Lattnercc876a72003-05-03 03:19:41 +0000105 switch (InterpreterSel) {
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000106 case AutoPick:
107 InterpreterSel = RunCBE;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000108 Interpreter = cbe = AbstractInterpreter::createCBE(getToolName(), Message,
109 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000110 if (!Interpreter) {
111 InterpreterSel = RunJIT;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000112 Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
113 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000114 }
115 if (!Interpreter) {
116 InterpreterSel = RunLLC;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000117 Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
118 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000119 }
120 if (!Interpreter) {
121 InterpreterSel = RunLLI;
Brian Gaeke636df3d2004-05-04 21:09:16 +0000122 Interpreter = AbstractInterpreter::createLLI(getToolName(), Message,
123 &ToolArgv);
Brian Gaekeb5ee5092003-10-21 17:41:35 +0000124 }
125 if (!Interpreter) {
126 InterpreterSel = AutoPick;
127 Message = "Sorry, I can't automatically select an interpreter!\n";
128 }
129 break;
Chris Lattner769f1fe2003-10-14 21:59:36 +0000130 case RunLLI:
Brian Gaeke636df3d2004-05-04 21:09:16 +0000131 Interpreter = AbstractInterpreter::createLLI(getToolName(), Message,
132 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000133 break;
134 case RunLLC:
Brian Gaeke636df3d2004-05-04 21:09:16 +0000135 Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
136 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000137 break;
138 case RunJIT:
Brian Gaeke636df3d2004-05-04 21:09:16 +0000139 Interpreter = AbstractInterpreter::createJIT(getToolName(), Message,
140 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000141 break;
Chris Lattnercd6f46e2006-11-09 05:57:53 +0000142 case LLC_Safe:
143 Interpreter = AbstractInterpreter::createLLC(getToolName(), Message,
144 &ToolArgv);
145 break;
Chris Lattner769f1fe2003-10-14 21:59:36 +0000146 case RunCBE:
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000147 case CBE_bug:
148 Interpreter = AbstractInterpreter::createCBE(getToolName(), Message,
149 &ToolArgv);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000150 break;
Chris Lattnercc876a72003-05-03 03:19:41 +0000151 default:
Misha Brukman41485562003-09-29 22:40:52 +0000152 Message = "Sorry, this back-end is not supported by bugpoint right now!\n";
Chris Lattnercc876a72003-05-03 03:19:41 +0000153 break;
Chris Lattner4a106452002-12-23 23:50:16 +0000154 }
Misha Brukman41485562003-09-29 22:40:52 +0000155 std::cerr << Message;
Chris Lattner4a106452002-12-23 23:50:16 +0000156
Misha Brukmana259c9b2003-07-24 21:59:10 +0000157 // Initialize auxiliary tools for debugging
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000158 if (InterpreterSel == RunCBE) {
159 // We already created a CBE, reuse it.
160 cbe = Interpreter;
Chris Lattnercd6f46e2006-11-09 05:57:53 +0000161 } else if (InterpreterSel == CBE_bug || InterpreterSel == LLC_Safe) {
162 // We want to debug the CBE itself or LLC is known-good. Use LLC as the
163 // 'known-good' compiler.
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000164 std::vector<std::string> ToolArgs;
165 ToolArgs.push_back("--relocation-model=pic");
166 cbe = AbstractInterpreter::createLLC(getToolName(), Message, &ToolArgs);
167 } else {
Brian Gaeke636df3d2004-05-04 21:09:16 +0000168 cbe = AbstractInterpreter::createCBE(getToolName(), Message, &ToolArgv);
Chris Lattner7bb11542004-02-18 20:52:02 +0000169 }
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000170 if (!cbe) { std::cout << Message << "\nExiting.\n"; exit(1); }
171
Chris Lattner769f1fe2003-10-14 21:59:36 +0000172 gcc = GCC::create(getToolName(), Message);
Misha Brukmana259c9b2003-07-24 21:59:10 +0000173 if (!gcc) { std::cout << Message << "\nExiting.\n"; exit(1); }
174
Chris Lattner4a106452002-12-23 23:50:16 +0000175 // If there was an error creating the selected interpreter, quit with error.
176 return Interpreter == 0;
177}
178
Chris Lattnerea9212c2004-02-18 23:25:22 +0000179/// compileProgram - Try to compile the specified module, throwing an exception
180/// if an error occurs, or returning normally if not. This is used for code
181/// generation crash testing.
182///
183void BugDriver::compileProgram(Module *M) {
184 // Emit the program to a bytecode file...
Reid Spencer97182982004-12-15 01:53:08 +0000185 sys::Path BytecodeFile ("bugpoint-test-program.bc");
Reid Spencer51c5a282006-08-23 20:34:57 +0000186 std::string ErrMsg;
187 if (BytecodeFile.makeUnique(true,&ErrMsg)) {
188 std::cerr << ToolName << ": Error making unique filename: " << ErrMsg
189 << "\n";
190 exit(1);
191 }
Reid Spencer97182982004-12-15 01:53:08 +0000192 if (writeProgramToFile(BytecodeFile.toString(), M)) {
Chris Lattnerea9212c2004-02-18 23:25:22 +0000193 std::cerr << ToolName << ": Error emitting bytecode to file '"
194 << BytecodeFile << "'!\n";
195 exit(1);
196 }
197
198 // Remove the temporary bytecode file when we are done.
Reid Spencer5f767602004-12-16 23:04:20 +0000199 FileRemover BytecodeFileRemover(BytecodeFile);
Chris Lattnerea9212c2004-02-18 23:25:22 +0000200
201 // Actually compile the program!
Reid Spencer97182982004-12-15 01:53:08 +0000202 Interpreter->compileProgram(BytecodeFile.toString());
Chris Lattnerea9212c2004-02-18 23:25:22 +0000203}
204
Chris Lattner4a106452002-12-23 23:50:16 +0000205
206/// executeProgram - This method runs "Program", capturing the output of the
207/// program to a file, returning the filename of the file. A recommended
208/// filename may be optionally specified.
209///
210std::string BugDriver::executeProgram(std::string OutputFile,
Misha Brukman50733362003-07-24 18:17:43 +0000211 std::string BytecodeFile,
Chris Lattner769f1fe2003-10-14 21:59:36 +0000212 const std::string &SharedObj,
Brian Gaekec5cad212004-02-11 18:37:32 +0000213 AbstractInterpreter *AI,
214 bool *ProgramExitedNonzero) {
Chris Lattner769f1fe2003-10-14 21:59:36 +0000215 if (AI == 0) AI = Interpreter;
216 assert(AI && "Interpreter should have been created already!");
Chris Lattner4a106452002-12-23 23:50:16 +0000217 bool CreatedBytecode = false;
Reid Spencer51c5a282006-08-23 20:34:57 +0000218 std::string ErrMsg;
Chris Lattner4a106452002-12-23 23:50:16 +0000219 if (BytecodeFile.empty()) {
220 // Emit the program to a bytecode file...
Reid Spencer97182982004-12-15 01:53:08 +0000221 sys::Path uniqueFilename("bugpoint-test-program.bc");
Reid Spencer51c5a282006-08-23 20:34:57 +0000222 if (uniqueFilename.makeUnique(true, &ErrMsg)) {
223 std::cerr << ToolName << ": Error making unique filename: "
224 << ErrMsg << "!\n";
225 exit(1);
226 }
Reid Spencer97182982004-12-15 01:53:08 +0000227 BytecodeFile = uniqueFilename.toString();
Chris Lattner4a106452002-12-23 23:50:16 +0000228
229 if (writeProgramToFile(BytecodeFile, Program)) {
230 std::cerr << ToolName << ": Error emitting bytecode to file '"
Misha Brukman50733362003-07-24 18:17:43 +0000231 << BytecodeFile << "'!\n";
Chris Lattner4a106452002-12-23 23:50:16 +0000232 exit(1);
233 }
234 CreatedBytecode = true;
235 }
236
Chris Lattner97092722004-02-18 22:01:21 +0000237 // Remove the temporary bytecode file when we are done.
Brian Gaeke06c375b2004-12-22 22:33:33 +0000238 sys::Path BytecodePath (BytecodeFile);
239 FileRemover BytecodeFileRemover(BytecodePath, CreatedBytecode);
Chris Lattner97092722004-02-18 22:01:21 +0000240
Chris Lattner4a106452002-12-23 23:50:16 +0000241 if (OutputFile.empty()) OutputFile = "bugpoint-execution-output";
Misha Brukman50733362003-07-24 18:17:43 +0000242
Chris Lattner4a106452002-12-23 23:50:16 +0000243 // Check to see if this is a valid output filename...
Reid Spencer97182982004-12-15 01:53:08 +0000244 sys::Path uniqueFile(OutputFile);
Reid Spencer51c5a282006-08-23 20:34:57 +0000245 if (uniqueFile.makeUnique(true, &ErrMsg)) {
246 std::cerr << ToolName << ": Error making unique filename: "
247 << ErrMsg << "\n";
248 exit(1);
249 }
Reid Spencer97182982004-12-15 01:53:08 +0000250 OutputFile = uniqueFile.toString();
Chris Lattner4a106452002-12-23 23:50:16 +0000251
Chris Lattner769f1fe2003-10-14 21:59:36 +0000252 // Figure out which shared objects to run, if any.
Chris Lattner7dac6582003-10-14 22:24:31 +0000253 std::vector<std::string> SharedObjs(AdditionalSOs);
Chris Lattner769f1fe2003-10-14 21:59:36 +0000254 if (!SharedObj.empty())
255 SharedObjs.push_back(SharedObj);
256
Reid Spencer51ab5c82006-06-06 00:00:42 +0000257
258 // If this is an LLC or CBE run, then the GCC compiler might get run to
259 // compile the program. If so, we should pass the user's -Xlinker options
260 // as the GCCArgs.
261 int RetVal = 0;
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000262 if (InterpreterSel == RunLLC || InterpreterSel == RunCBE ||
Lauro Ramos Venancio497391a2007-06-06 23:10:56 +0000263 InterpreterSel == CBE_bug || InterpreterSel == LLC_Safe)
Reid Spencer51ab5c82006-06-06 00:00:42 +0000264 RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
265 OutputFile, AdditionalLinkerArgs, SharedObjs,
Anton Korobeynikov9ba8a762007-02-16 19:11:07 +0000266 Timeout, MemoryLimit);
Reid Spencer51ab5c82006-06-06 00:00:42 +0000267 else
268 RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile,
269 OutputFile, std::vector<std::string>(),
Anton Korobeynikov9ba8a762007-02-16 19:11:07 +0000270 SharedObjs, Timeout, MemoryLimit);
Chris Lattner7d91e492004-07-24 07:53:26 +0000271
272 if (RetVal == -1) {
273 std::cerr << "<timeout>";
274 static bool FirstTimeout = true;
275 if (FirstTimeout) {
276 std::cout << "\n"
277 "*** Program execution timed out! This mechanism is designed to handle\n"
278 " programs stuck in infinite loops gracefully. The -timeout option\n"
279 " can be used to change the timeout threshold or disable it completely\n"
280 " (with -timeout=0). This message is only displayed once.\n";
281 FirstTimeout = false;
282 }
283 }
Chris Lattner769f1fe2003-10-14 21:59:36 +0000284
Reid Spencer5e1452c2006-11-28 07:04:10 +0000285 if (AppendProgramExitCode) {
286 std::ofstream outFile(OutputFile.c_str(), std::ios_base::app);
287 outFile << "exit " << RetVal << '\n';
288 outFile.close();
289 }
290
Brian Gaekec5cad212004-02-11 18:37:32 +0000291 if (ProgramExitedNonzero != 0)
292 *ProgramExitedNonzero = (RetVal != 0);
Chris Lattner4a106452002-12-23 23:50:16 +0000293
Chris Lattner4a106452002-12-23 23:50:16 +0000294 // Return the filename we captured the output to.
295 return OutputFile;
296}
297
Brian Gaekec5cad212004-02-11 18:37:32 +0000298/// executeProgramWithCBE - Used to create reference output with the C
299/// backend, if reference output is not provided.
300///
301std::string BugDriver::executeProgramWithCBE(std::string OutputFile) {
302 bool ProgramExitedNonzero;
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000303 std::string outFN = executeProgram(OutputFile, "", "", cbe,
Brian Gaekec5cad212004-02-11 18:37:32 +0000304 &ProgramExitedNonzero);
305 if (ProgramExitedNonzero) {
306 std::cerr
307 << "Warning: While generating reference output, program exited with\n"
308 << "non-zero exit code. This will NOT be treated as a failure.\n";
309 CheckProgramExitCode = false;
310 }
311 return outFN;
312}
Misha Brukman50733362003-07-24 18:17:43 +0000313
Chris Lattnera0f5b152003-10-14 21:09:11 +0000314std::string BugDriver::compileSharedObject(const std::string &BytecodeFile) {
Misha Brukman50733362003-07-24 18:17:43 +0000315 assert(Interpreter && "Interpreter should have been created already!");
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000316 sys::Path OutputFile;
Misha Brukman50733362003-07-24 18:17:43 +0000317
318 // Using CBE
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000319 GCC::FileType FT = cbe->OutputCode(BytecodeFile, OutputFile);
Misha Brukman50733362003-07-24 18:17:43 +0000320
Chris Lattnera0f5b152003-10-14 21:09:11 +0000321 std::string SharedObjectFile;
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000322 if (gcc->MakeSharedObject(OutputFile.toString(), FT,
Chris Lattner130e2a32006-06-27 20:35:36 +0000323 SharedObjectFile, AdditionalLinkerArgs))
Chris Lattnera0f5b152003-10-14 21:09:11 +0000324 exit(1);
Misha Brukman50733362003-07-24 18:17:43 +0000325
326 // Remove the intermediate C file
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000327 OutputFile.eraseFromDisk();
Misha Brukman50733362003-07-24 18:17:43 +0000328
Chris Lattner6ebe44d2003-10-19 21:54:13 +0000329 return "./" + SharedObjectFile;
Misha Brukman50733362003-07-24 18:17:43 +0000330}
331
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000332/// createReferenceFile - calls compileProgram and then records the output
333/// into ReferenceOutputFile. Returns true if reference file created, false
334/// otherwise. Note: initializeExecutionEnvironment should be called BEFORE
335/// this function.
336///
Chris Lattnerc600f3c2006-09-15 21:29:15 +0000337bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000338 try {
339 compileProgram(Program);
Jeff Cohend41b30d2006-11-05 19:31:28 +0000340 } catch (ToolExecutionError &) {
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000341 return false;
342 }
343 try {
344 ReferenceOutputFile = executeProgramWithCBE(Filename);
345 std::cout << "Reference output is: " << ReferenceOutputFile << "\n\n";
346 } catch (ToolExecutionError &TEE) {
347 std::cerr << TEE.what();
348 if (Interpreter != cbe) {
349 std::cerr << "*** There is a bug running the C backend. Either debug"
350 << " it (use the -run-cbe bugpoint option), or fix the error"
351 << " some other way.\n";
352 }
353 return false;
354 }
355 return true;
356}
Misha Brukman50733362003-07-24 18:17:43 +0000357
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +0000358/// diffProgram - This method executes the specified module and diffs the
359/// output against the file specified by ReferenceOutputFile. If the output
360/// is different, true is returned. If there is a problem with the code
361/// generator (e.g., llc crashes), this will throw an exception.
Chris Lattner4a106452002-12-23 23:50:16 +0000362///
Misha Brukman50733362003-07-24 18:17:43 +0000363bool BugDriver::diffProgram(const std::string &BytecodeFile,
364 const std::string &SharedObject,
Chris Lattner640f22e2003-04-24 17:02:17 +0000365 bool RemoveBytecode) {
Brian Gaekec5cad212004-02-11 18:37:32 +0000366 bool ProgramExitedNonzero;
367
Chris Lattner4a106452002-12-23 23:50:16 +0000368 // Execute the program, generating an output file...
Chris Lattner130e2a32006-06-27 20:35:36 +0000369 sys::Path Output(executeProgram("", BytecodeFile, SharedObject, 0,
Reid Spencer5f767602004-12-16 23:04:20 +0000370 &ProgramExitedNonzero));
Brian Gaekec5cad212004-02-11 18:37:32 +0000371
372 // If we're checking the program exit code, assume anything nonzero is bad.
Chris Lattner58d84ce2004-04-02 05:33:06 +0000373 if (CheckProgramExitCode && ProgramExitedNonzero) {
Reid Spencera229c5c2005-07-08 03:08:58 +0000374 Output.eraseFromDisk();
Misha Brukman3da94ae2005-04-22 00:00:37 +0000375 if (RemoveBytecode)
Reid Spencera229c5c2005-07-08 03:08:58 +0000376 sys::Path(BytecodeFile).eraseFromDisk();
Brian Gaekec5cad212004-02-11 18:37:32 +0000377 return true;
Chris Lattner58d84ce2004-04-02 05:33:06 +0000378 }
Chris Lattner4a106452002-12-23 23:50:16 +0000379
Chris Lattner65f62792003-08-01 20:29:45 +0000380 std::string Error;
Chris Lattner4a106452002-12-23 23:50:16 +0000381 bool FilesDifferent = false;
Chris Lattnera328c512005-01-23 03:45:26 +0000382 if (int Diff = DiffFilesWithTolerance(sys::Path(ReferenceOutputFile),
383 sys::Path(Output.toString()),
384 AbsTolerance, RelTolerance, &Error)) {
385 if (Diff == 2) {
Misha Brukmaneed80e22004-07-23 01:30:49 +0000386 std::cerr << "While diffing output: " << Error << '\n';
Chris Lattner65f62792003-08-01 20:29:45 +0000387 exit(1);
388 }
389 FilesDifferent = true;
390 }
Misha Brukman3da94ae2005-04-22 00:00:37 +0000391
Chris Lattner1a28a2b2003-10-18 21:02:51 +0000392 // Remove the generated output.
Reid Spencera229c5c2005-07-08 03:08:58 +0000393 Output.eraseFromDisk();
Chris Lattner4a106452002-12-23 23:50:16 +0000394
Chris Lattner1a28a2b2003-10-18 21:02:51 +0000395 // Remove the bytecode file if we are supposed to.
Jeff Cohen00b168892005-07-27 06:12:32 +0000396 if (RemoveBytecode)
Reid Spencera229c5c2005-07-08 03:08:58 +0000397 sys::Path(BytecodeFile).eraseFromDisk();
Chris Lattner4a106452002-12-23 23:50:16 +0000398 return FilesDifferent;
399}
Misha Brukman91eabc12003-07-28 19:16:14 +0000400
401bool BugDriver::isExecutingJIT() {
402 return InterpreterSel == RunJIT;
403}
Brian Gaeked0fde302003-11-11 22:41:34 +0000404