Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 1 | //===- ExecutionDriver.cpp - Allow execution of LLVM program --------------===// |
John Criswell | 7c0e022 | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // 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. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 9 | // |
| 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 Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 15 | #include "BugDriver.h" |
Misha Brukman | b687d82 | 2004-04-19 03:12:35 +0000 | [diff] [blame] | 16 | #include "llvm/Support/ToolRunner.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 17 | #include "llvm/Support/CommandLine.h" |
| 18 | #include "llvm/Support/Debug.h" |
| 19 | #include "llvm/Support/FileUtilities.h" |
| 20 | #include "llvm/Support/SystemUtils.h" |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 21 | #include <fstream> |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 24 | namespace { |
| 25 | // OutputType - Allow the user to specify the way code should be run, to test |
| 26 | // for miscompilation. |
| 27 | // |
| 28 | enum OutputType { |
Brian Gaeke | b5ee509 | 2003-10-21 17:41:35 +0000 | [diff] [blame] | 29 | AutoPick, RunLLI, RunJIT, RunLLC, RunCBE |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 30 | }; |
Misha Brukman | 4148556 | 2003-09-29 22:40:52 +0000 | [diff] [blame] | 31 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 32 | cl::opt<OutputType> |
| 33 | InterpreterSel(cl::desc("Specify how LLVM code should be executed:"), |
Brian Gaeke | b5ee509 | 2003-10-21 17:41:35 +0000 | [diff] [blame] | 34 | cl::values(clEnumValN(AutoPick, "auto", "Use best guess"), |
Misha Brukman | b687d82 | 2004-04-19 03:12:35 +0000 | [diff] [blame] | 35 | clEnumValN(RunLLI, "run-int", |
| 36 | "Execute with the interpreter"), |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 37 | clEnumValN(RunJIT, "run-jit", "Execute with JIT"), |
| 38 | clEnumValN(RunLLC, "run-llc", "Compile with LLC"), |
| 39 | clEnumValN(RunCBE, "run-cbe", "Compile with CBE"), |
Chris Lattner | 4d143ee | 2004-07-16 00:08:28 +0000 | [diff] [blame] | 40 | clEnumValEnd), |
Brian Gaeke | b5ee509 | 2003-10-21 17:41:35 +0000 | [diff] [blame] | 41 | cl::init(AutoPick)); |
Chris Lattner | 3c053a0 | 2003-04-23 20:31:37 +0000 | [diff] [blame] | 42 | |
Brian Gaeke | c5cad21 | 2004-02-11 18:37:32 +0000 | [diff] [blame] | 43 | cl::opt<bool> |
| 44 | CheckProgramExitCode("check-exit-code", |
Misha Brukman | eed80e2 | 2004-07-23 01:30:49 +0000 | [diff] [blame] | 45 | cl::desc("Assume nonzero exit code is failure (default on)"), |
Brian Gaeke | c5cad21 | 2004-02-11 18:37:32 +0000 | [diff] [blame] | 46 | cl::init(true)); |
| 47 | |
Chris Lattner | 3c053a0 | 2003-04-23 20:31:37 +0000 | [diff] [blame] | 48 | cl::opt<std::string> |
| 49 | InputFile("input", cl::init("/dev/null"), |
| 50 | cl::desc("Filename to pipe in as stdin (default: /dev/null)")); |
Chris Lattner | 7dac658 | 2003-10-14 22:24:31 +0000 | [diff] [blame] | 51 | |
| 52 | cl::list<std::string> |
| 53 | AdditionalSOs("additional-so", |
| 54 | cl::desc("Additional shared objects to load " |
| 55 | "into executing programs")); |
Chris Lattner | 7d91e49 | 2004-07-24 07:53:26 +0000 | [diff] [blame] | 56 | |
| 57 | cl::opt<unsigned> |
| 58 | TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"), |
| 59 | cl::desc("Number of seconds program is allowed to run before it " |
| 60 | "is killed (default is 300s), 0 disables timeout")); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 63 | namespace llvm { |
Chris Lattner | fa76183 | 2004-01-14 03:38:37 +0000 | [diff] [blame] | 64 | // Anything specified after the --args option are taken as arguments to the |
| 65 | // program being debugged. |
| 66 | cl::list<std::string> |
| 67 | InputArgv("args", cl::Positional, cl::desc("<program arguments>..."), |
Chris Lattner | 60083e2 | 2004-05-06 22:05:35 +0000 | [diff] [blame] | 68 | cl::ZeroOrMore, cl::PositionalEatsArgs); |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 69 | |
| 70 | cl::list<std::string> |
| 71 | ToolArgv("tool-args", cl::Positional, cl::desc("<tool arguments>..."), |
Chris Lattner | 60083e2 | 2004-05-06 22:05:35 +0000 | [diff] [blame] | 72 | cl::ZeroOrMore, cl::PositionalEatsArgs); |
Chris Lattner | fa76183 | 2004-01-14 03:38:37 +0000 | [diff] [blame] | 73 | } |
Misha Brukman | 9d679cb | 2003-07-30 20:15:44 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 75 | //===----------------------------------------------------------------------===// |
| 76 | // BugDriver method implementation |
| 77 | // |
| 78 | |
| 79 | /// initializeExecutionEnvironment - This method is used to set up the |
| 80 | /// environment for executing LLVM programs. |
| 81 | /// |
| 82 | bool BugDriver::initializeExecutionEnvironment() { |
| 83 | std::cout << "Initializing execution environment: "; |
| 84 | |
Misha Brukman | 4148556 | 2003-09-29 22:40:52 +0000 | [diff] [blame] | 85 | // Create an instance of the AbstractInterpreter interface as specified on |
| 86 | // the command line |
Chris Lattner | 7bb1154 | 2004-02-18 20:52:02 +0000 | [diff] [blame] | 87 | cbe = 0; |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 88 | std::string Message; |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 89 | |
Chris Lattner | cc876a7 | 2003-05-03 03:19:41 +0000 | [diff] [blame] | 90 | switch (InterpreterSel) { |
Brian Gaeke | b5ee509 | 2003-10-21 17:41:35 +0000 | [diff] [blame] | 91 | case AutoPick: |
| 92 | InterpreterSel = RunCBE; |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 93 | Interpreter = cbe = AbstractInterpreter::createCBE(getToolName(), Message, |
| 94 | &ToolArgv); |
Brian Gaeke | b5ee509 | 2003-10-21 17:41:35 +0000 | [diff] [blame] | 95 | if (!Interpreter) { |
| 96 | InterpreterSel = RunJIT; |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 97 | Interpreter = AbstractInterpreter::createJIT(getToolName(), Message, |
| 98 | &ToolArgv); |
Brian Gaeke | b5ee509 | 2003-10-21 17:41:35 +0000 | [diff] [blame] | 99 | } |
| 100 | if (!Interpreter) { |
| 101 | InterpreterSel = RunLLC; |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 102 | Interpreter = AbstractInterpreter::createLLC(getToolName(), Message, |
| 103 | &ToolArgv); |
Brian Gaeke | b5ee509 | 2003-10-21 17:41:35 +0000 | [diff] [blame] | 104 | } |
| 105 | if (!Interpreter) { |
| 106 | InterpreterSel = RunLLI; |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 107 | Interpreter = AbstractInterpreter::createLLI(getToolName(), Message, |
| 108 | &ToolArgv); |
Brian Gaeke | b5ee509 | 2003-10-21 17:41:35 +0000 | [diff] [blame] | 109 | } |
| 110 | if (!Interpreter) { |
| 111 | InterpreterSel = AutoPick; |
| 112 | Message = "Sorry, I can't automatically select an interpreter!\n"; |
| 113 | } |
| 114 | break; |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 115 | case RunLLI: |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 116 | Interpreter = AbstractInterpreter::createLLI(getToolName(), Message, |
| 117 | &ToolArgv); |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 118 | break; |
| 119 | case RunLLC: |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 120 | Interpreter = AbstractInterpreter::createLLC(getToolName(), Message, |
| 121 | &ToolArgv); |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 122 | break; |
| 123 | case RunJIT: |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 124 | Interpreter = AbstractInterpreter::createJIT(getToolName(), Message, |
| 125 | &ToolArgv); |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 126 | break; |
| 127 | case RunCBE: |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 128 | Interpreter = cbe = AbstractInterpreter::createCBE(getToolName(), Message, |
| 129 | &ToolArgv); |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 130 | break; |
Chris Lattner | cc876a7 | 2003-05-03 03:19:41 +0000 | [diff] [blame] | 131 | default: |
Misha Brukman | 4148556 | 2003-09-29 22:40:52 +0000 | [diff] [blame] | 132 | Message = "Sorry, this back-end is not supported by bugpoint right now!\n"; |
Chris Lattner | cc876a7 | 2003-05-03 03:19:41 +0000 | [diff] [blame] | 133 | break; |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 134 | } |
Misha Brukman | 4148556 | 2003-09-29 22:40:52 +0000 | [diff] [blame] | 135 | std::cerr << Message; |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 136 | |
Misha Brukman | a259c9b | 2003-07-24 21:59:10 +0000 | [diff] [blame] | 137 | // Initialize auxiliary tools for debugging |
Chris Lattner | 7bb1154 | 2004-02-18 20:52:02 +0000 | [diff] [blame] | 138 | if (!cbe) { |
Brian Gaeke | 636df3d | 2004-05-04 21:09:16 +0000 | [diff] [blame] | 139 | cbe = AbstractInterpreter::createCBE(getToolName(), Message, &ToolArgv); |
Chris Lattner | 7bb1154 | 2004-02-18 20:52:02 +0000 | [diff] [blame] | 140 | if (!cbe) { std::cout << Message << "\nExiting.\n"; exit(1); } |
| 141 | } |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 142 | gcc = GCC::create(getToolName(), Message); |
Misha Brukman | a259c9b | 2003-07-24 21:59:10 +0000 | [diff] [blame] | 143 | if (!gcc) { std::cout << Message << "\nExiting.\n"; exit(1); } |
| 144 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 145 | // If there was an error creating the selected interpreter, quit with error. |
| 146 | return Interpreter == 0; |
| 147 | } |
| 148 | |
Chris Lattner | ea9212c | 2004-02-18 23:25:22 +0000 | [diff] [blame] | 149 | /// compileProgram - Try to compile the specified module, throwing an exception |
| 150 | /// if an error occurs, or returning normally if not. This is used for code |
| 151 | /// generation crash testing. |
| 152 | /// |
| 153 | void BugDriver::compileProgram(Module *M) { |
| 154 | // Emit the program to a bytecode file... |
Reid Spencer | 9718298 | 2004-12-15 01:53:08 +0000 | [diff] [blame] | 155 | sys::Path BytecodeFile ("bugpoint-test-program.bc"); |
| 156 | BytecodeFile.makeUnique(); |
| 157 | if (writeProgramToFile(BytecodeFile.toString(), M)) { |
Chris Lattner | ea9212c | 2004-02-18 23:25:22 +0000 | [diff] [blame] | 158 | std::cerr << ToolName << ": Error emitting bytecode to file '" |
| 159 | << BytecodeFile << "'!\n"; |
| 160 | exit(1); |
| 161 | } |
| 162 | |
| 163 | // Remove the temporary bytecode file when we are done. |
Reid Spencer | 5f76760 | 2004-12-16 23:04:20 +0000 | [diff] [blame] | 164 | FileRemover BytecodeFileRemover(BytecodeFile); |
Chris Lattner | ea9212c | 2004-02-18 23:25:22 +0000 | [diff] [blame] | 165 | |
| 166 | // Actually compile the program! |
Reid Spencer | 9718298 | 2004-12-15 01:53:08 +0000 | [diff] [blame] | 167 | Interpreter->compileProgram(BytecodeFile.toString()); |
Chris Lattner | ea9212c | 2004-02-18 23:25:22 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 170 | |
| 171 | /// executeProgram - This method runs "Program", capturing the output of the |
| 172 | /// program to a file, returning the filename of the file. A recommended |
| 173 | /// filename may be optionally specified. |
| 174 | /// |
| 175 | std::string BugDriver::executeProgram(std::string OutputFile, |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 176 | std::string BytecodeFile, |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 177 | const std::string &SharedObj, |
Brian Gaeke | c5cad21 | 2004-02-11 18:37:32 +0000 | [diff] [blame] | 178 | AbstractInterpreter *AI, |
| 179 | bool *ProgramExitedNonzero) { |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 180 | if (AI == 0) AI = Interpreter; |
| 181 | assert(AI && "Interpreter should have been created already!"); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 182 | bool CreatedBytecode = false; |
| 183 | if (BytecodeFile.empty()) { |
| 184 | // Emit the program to a bytecode file... |
Reid Spencer | 9718298 | 2004-12-15 01:53:08 +0000 | [diff] [blame] | 185 | sys::Path uniqueFilename("bugpoint-test-program.bc"); |
| 186 | uniqueFilename.makeUnique(); |
| 187 | BytecodeFile = uniqueFilename.toString(); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 188 | |
| 189 | if (writeProgramToFile(BytecodeFile, Program)) { |
| 190 | std::cerr << ToolName << ": Error emitting bytecode to file '" |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 191 | << BytecodeFile << "'!\n"; |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 192 | exit(1); |
| 193 | } |
| 194 | CreatedBytecode = true; |
| 195 | } |
| 196 | |
Chris Lattner | 9709272 | 2004-02-18 22:01:21 +0000 | [diff] [blame] | 197 | // Remove the temporary bytecode file when we are done. |
Brian Gaeke | 06c375b | 2004-12-22 22:33:33 +0000 | [diff] [blame^] | 198 | sys::Path BytecodePath (BytecodeFile); |
| 199 | FileRemover BytecodeFileRemover(BytecodePath, CreatedBytecode); |
Chris Lattner | 9709272 | 2004-02-18 22:01:21 +0000 | [diff] [blame] | 200 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 201 | if (OutputFile.empty()) OutputFile = "bugpoint-execution-output"; |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 202 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 203 | // Check to see if this is a valid output filename... |
Reid Spencer | 9718298 | 2004-12-15 01:53:08 +0000 | [diff] [blame] | 204 | sys::Path uniqueFile(OutputFile); |
| 205 | uniqueFile.makeUnique(); |
| 206 | OutputFile = uniqueFile.toString(); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 207 | |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 208 | // Figure out which shared objects to run, if any. |
Chris Lattner | 7dac658 | 2003-10-14 22:24:31 +0000 | [diff] [blame] | 209 | std::vector<std::string> SharedObjs(AdditionalSOs); |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 210 | if (!SharedObj.empty()) |
| 211 | SharedObjs.push_back(SharedObj); |
| 212 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 213 | // Actually execute the program! |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 214 | int RetVal = AI->ExecuteProgram(BytecodeFile, InputArgv, InputFile, |
Chris Lattner | 7d91e49 | 2004-07-24 07:53:26 +0000 | [diff] [blame] | 215 | OutputFile, SharedObjs, TimeoutValue); |
| 216 | |
| 217 | if (RetVal == -1) { |
| 218 | std::cerr << "<timeout>"; |
| 219 | static bool FirstTimeout = true; |
| 220 | if (FirstTimeout) { |
| 221 | std::cout << "\n" |
| 222 | "*** Program execution timed out! This mechanism is designed to handle\n" |
| 223 | " programs stuck in infinite loops gracefully. The -timeout option\n" |
| 224 | " can be used to change the timeout threshold or disable it completely\n" |
| 225 | " (with -timeout=0). This message is only displayed once.\n"; |
| 226 | FirstTimeout = false; |
| 227 | } |
| 228 | } |
Chris Lattner | 769f1fe | 2003-10-14 21:59:36 +0000 | [diff] [blame] | 229 | |
Brian Gaeke | c5cad21 | 2004-02-11 18:37:32 +0000 | [diff] [blame] | 230 | if (ProgramExitedNonzero != 0) |
| 231 | *ProgramExitedNonzero = (RetVal != 0); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 232 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 233 | // Return the filename we captured the output to. |
| 234 | return OutputFile; |
| 235 | } |
| 236 | |
Brian Gaeke | c5cad21 | 2004-02-11 18:37:32 +0000 | [diff] [blame] | 237 | /// executeProgramWithCBE - Used to create reference output with the C |
| 238 | /// backend, if reference output is not provided. |
| 239 | /// |
| 240 | std::string BugDriver::executeProgramWithCBE(std::string OutputFile) { |
| 241 | bool ProgramExitedNonzero; |
| 242 | std::string outFN = executeProgram(OutputFile, "", "", |
| 243 | (AbstractInterpreter*)cbe, |
| 244 | &ProgramExitedNonzero); |
| 245 | if (ProgramExitedNonzero) { |
| 246 | std::cerr |
| 247 | << "Warning: While generating reference output, program exited with\n" |
| 248 | << "non-zero exit code. This will NOT be treated as a failure.\n"; |
| 249 | CheckProgramExitCode = false; |
| 250 | } |
| 251 | return outFN; |
| 252 | } |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 253 | |
Chris Lattner | a0f5b15 | 2003-10-14 21:09:11 +0000 | [diff] [blame] | 254 | std::string BugDriver::compileSharedObject(const std::string &BytecodeFile) { |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 255 | assert(Interpreter && "Interpreter should have been created already!"); |
Reid Spencer | 5f76760 | 2004-12-16 23:04:20 +0000 | [diff] [blame] | 256 | sys::Path OutputCFile; |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 257 | |
| 258 | // Using CBE |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 259 | cbe->OutputC(BytecodeFile, OutputCFile); |
| 260 | |
| 261 | #if 0 /* This is an alternative, as yet unimplemented */ |
| 262 | // Using LLC |
Chris Lattner | a0f5b15 | 2003-10-14 21:09:11 +0000 | [diff] [blame] | 263 | std::string Message; |
Misha Brukman | 4148556 | 2003-09-29 22:40:52 +0000 | [diff] [blame] | 264 | LLC *llc = createLLCtool(Message); |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 265 | if (llc->OutputAsm(BytecodeFile, OutputFile)) { |
| 266 | std::cerr << "Could not generate asm code with `llc', exiting.\n"; |
| 267 | exit(1); |
| 268 | } |
| 269 | #endif |
| 270 | |
Chris Lattner | a0f5b15 | 2003-10-14 21:09:11 +0000 | [diff] [blame] | 271 | std::string SharedObjectFile; |
Reid Spencer | 5f76760 | 2004-12-16 23:04:20 +0000 | [diff] [blame] | 272 | if (gcc->MakeSharedObject(OutputCFile.toString(), GCC::CFile, |
| 273 | SharedObjectFile)) |
Chris Lattner | a0f5b15 | 2003-10-14 21:09:11 +0000 | [diff] [blame] | 274 | exit(1); |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 275 | |
| 276 | // Remove the intermediate C file |
Reid Spencer | 5f76760 | 2004-12-16 23:04:20 +0000 | [diff] [blame] | 277 | OutputCFile.destroyFile(); |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 278 | |
Chris Lattner | 6ebe44d | 2003-10-19 21:54:13 +0000 | [diff] [blame] | 279 | return "./" + SharedObjectFile; |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 283 | /// diffProgram - This method executes the specified module and diffs the output |
| 284 | /// against the file specified by ReferenceOutputFile. If the output is |
| 285 | /// different, true is returned. |
| 286 | /// |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 287 | bool BugDriver::diffProgram(const std::string &BytecodeFile, |
| 288 | const std::string &SharedObject, |
Chris Lattner | 640f22e | 2003-04-24 17:02:17 +0000 | [diff] [blame] | 289 | bool RemoveBytecode) { |
Brian Gaeke | c5cad21 | 2004-02-11 18:37:32 +0000 | [diff] [blame] | 290 | bool ProgramExitedNonzero; |
| 291 | |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 292 | // Execute the program, generating an output file... |
Reid Spencer | 5f76760 | 2004-12-16 23:04:20 +0000 | [diff] [blame] | 293 | sys::Path Output (executeProgram("", BytecodeFile, SharedObject, 0, |
| 294 | &ProgramExitedNonzero)); |
Brian Gaeke | c5cad21 | 2004-02-11 18:37:32 +0000 | [diff] [blame] | 295 | |
| 296 | // If we're checking the program exit code, assume anything nonzero is bad. |
Chris Lattner | 58d84ce | 2004-04-02 05:33:06 +0000 | [diff] [blame] | 297 | if (CheckProgramExitCode && ProgramExitedNonzero) { |
Reid Spencer | 5f76760 | 2004-12-16 23:04:20 +0000 | [diff] [blame] | 298 | Output.destroyFile(); |
| 299 | if (RemoveBytecode) |
| 300 | sys::Path(BytecodeFile).destroyFile(); |
Brian Gaeke | c5cad21 | 2004-02-11 18:37:32 +0000 | [diff] [blame] | 301 | return true; |
Chris Lattner | 58d84ce | 2004-04-02 05:33:06 +0000 | [diff] [blame] | 302 | } |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 303 | |
Chris Lattner | 65f6279 | 2003-08-01 20:29:45 +0000 | [diff] [blame] | 304 | std::string Error; |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 305 | bool FilesDifferent = false; |
Reid Spencer | 5f76760 | 2004-12-16 23:04:20 +0000 | [diff] [blame] | 306 | if (DiffFiles(ReferenceOutputFile, Output.toString(), &Error)) { |
Chris Lattner | 65f6279 | 2003-08-01 20:29:45 +0000 | [diff] [blame] | 307 | if (!Error.empty()) { |
Misha Brukman | eed80e2 | 2004-07-23 01:30:49 +0000 | [diff] [blame] | 308 | std::cerr << "While diffing output: " << Error << '\n'; |
Chris Lattner | 65f6279 | 2003-08-01 20:29:45 +0000 | [diff] [blame] | 309 | exit(1); |
| 310 | } |
| 311 | FilesDifferent = true; |
| 312 | } |
Chris Lattner | 1a28a2b | 2003-10-18 21:02:51 +0000 | [diff] [blame] | 313 | |
| 314 | // Remove the generated output. |
Reid Spencer | 5f76760 | 2004-12-16 23:04:20 +0000 | [diff] [blame] | 315 | Output.destroyFile(); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 316 | |
Chris Lattner | 1a28a2b | 2003-10-18 21:02:51 +0000 | [diff] [blame] | 317 | // Remove the bytecode file if we are supposed to. |
Reid Spencer | 5f76760 | 2004-12-16 23:04:20 +0000 | [diff] [blame] | 318 | if (RemoveBytecode) sys::Path(BytecodeFile).destroyFile(); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 319 | return FilesDifferent; |
| 320 | } |
Misha Brukman | 91eabc1 | 2003-07-28 19:16:14 +0000 | [diff] [blame] | 321 | |
| 322 | bool BugDriver::isExecutingJIT() { |
| 323 | return InterpreterSel == RunJIT; |
| 324 | } |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 325 | |