Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 1 | //===-- ToolRunner.cpp ----------------------------------------------------===// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 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. |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file implements the interfaces described in the ToolRunner.h file. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 0b1fe84 | 2003-10-19 02:27:40 +0000 | [diff] [blame] | 14 | #define DEBUG_TYPE "toolrunner" |
Misha Brukman | 6873450 | 2003-10-06 18:37:24 +0000 | [diff] [blame] | 15 | #include "llvm/Support/ToolRunner.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 16 | #include "llvm/Config/config.h" // for HAVE_LINK_R |
Chris Lattner | 45495c5 | 2005-02-13 23:13:47 +0000 | [diff] [blame] | 17 | #include "llvm/System/Program.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Debug.h" |
| 19 | #include "llvm/Support/FileUtilities.h" |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 20 | #include <fstream> |
Chris Lattner | 89bf9ea | 2004-02-18 20:38:00 +0000 | [diff] [blame] | 21 | #include <sstream> |
Chris Lattner | 86a5484 | 2006-01-22 22:53:01 +0000 | [diff] [blame] | 22 | #include <iostream> |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 23 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 24 | |
Alkis Evlogimenos | 1d29a6d | 2004-02-19 07:39:26 +0000 | [diff] [blame] | 25 | ToolExecutionError::~ToolExecutionError() throw() { } |
| 26 | |
Chris Lattner | 45495c5 | 2005-02-13 23:13:47 +0000 | [diff] [blame] | 27 | /// RunProgramWithTimeout - This function provides an alternate interface to the |
| 28 | /// sys::Program::ExecuteAndWait interface. |
| 29 | /// @see sys:Program::ExecuteAndWait |
| 30 | static int RunProgramWithTimeout(const sys::Path &ProgramPath, |
| 31 | const char **Args, |
| 32 | const sys::Path &StdInFile, |
| 33 | const sys::Path &StdOutFile, |
| 34 | const sys::Path &StdErrFile, |
| 35 | unsigned NumSeconds = 0) { |
| 36 | const sys::Path* redirects[3]; |
| 37 | redirects[0] = &StdInFile; |
| 38 | redirects[1] = &StdOutFile; |
| 39 | redirects[2] = &StdErrFile; |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 40 | |
| 41 | return |
Chris Lattner | 45495c5 | 2005-02-13 23:13:47 +0000 | [diff] [blame] | 42 | sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects, NumSeconds); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 47 | static void ProcessFailure(sys::Path ProgPath, const char** Args) { |
Chris Lattner | 89bf9ea | 2004-02-18 20:38:00 +0000 | [diff] [blame] | 48 | std::ostringstream OS; |
Chris Lattner | a3de117 | 2004-02-18 20:58:00 +0000 | [diff] [blame] | 49 | OS << "\nError running tool:\n "; |
Chris Lattner | 89bf9ea | 2004-02-18 20:38:00 +0000 | [diff] [blame] | 50 | for (const char **Arg = Args; *Arg; ++Arg) |
| 51 | OS << " " << *Arg; |
| 52 | OS << "\n"; |
| 53 | |
| 54 | // Rerun the compiler, capturing any error messages to print them. |
Reid Spencer | cda985e | 2004-12-15 01:51:56 +0000 | [diff] [blame] | 55 | sys::Path ErrorFilename("error_messages"); |
| 56 | ErrorFilename.makeUnique(); |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 57 | RunProgramWithTimeout(ProgPath, Args, sys::Path(""), ErrorFilename, |
| 58 | ErrorFilename); |
Chris Lattner | 89bf9ea | 2004-02-18 20:38:00 +0000 | [diff] [blame] | 59 | |
| 60 | // Print out the error messages generated by GCC if possible... |
| 61 | std::ifstream ErrorFile(ErrorFilename.c_str()); |
| 62 | if (ErrorFile) { |
| 63 | std::copy(std::istreambuf_iterator<char>(ErrorFile), |
| 64 | std::istreambuf_iterator<char>(), |
| 65 | std::ostreambuf_iterator<char>(OS)); |
| 66 | ErrorFile.close(); |
| 67 | } |
| 68 | |
Reid Spencer | a229c5c | 2005-07-08 03:08:58 +0000 | [diff] [blame] | 69 | ErrorFilename.eraseFromDisk(); |
Chris Lattner | 89bf9ea | 2004-02-18 20:38:00 +0000 | [diff] [blame] | 70 | throw ToolExecutionError(OS.str()); |
| 71 | } |
| 72 | |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 73 | //===---------------------------------------------------------------------===// |
| 74 | // LLI Implementation of AbstractIntepreter interface |
| 75 | // |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 76 | namespace { |
| 77 | class LLI : public AbstractInterpreter { |
| 78 | std::string LLIPath; // The path to the LLI executable |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 79 | std::vector<std::string> ToolArgs; // Args to pass to LLI |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 80 | public: |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 81 | LLI(const std::string &Path, const std::vector<std::string> *Args) |
| 82 | : LLIPath(Path) { |
| 83 | ToolArgs.clear (); |
Brian Gaeke | 48b008d | 2004-05-04 22:02:41 +0000 | [diff] [blame] | 84 | if (Args) { ToolArgs = *Args; } |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 85 | } |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 87 | virtual int ExecuteProgram(const std::string &Bytecode, |
| 88 | const std::vector<std::string> &Args, |
| 89 | const std::string &InputFile, |
| 90 | const std::string &OutputFile, |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 91 | const std::vector<std::string> &GCCArgs, |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 92 | const std::vector<std::string> &SharedLibs = |
Chris Lattner | e96b2ed | 2004-07-24 07:49:11 +0000 | [diff] [blame] | 93 | std::vector<std::string>(), |
| 94 | unsigned Timeout = 0); |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 95 | }; |
| 96 | } |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 97 | |
| 98 | int LLI::ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 99 | const std::vector<std::string> &Args, |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 100 | const std::string &InputFile, |
| 101 | const std::string &OutputFile, |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 102 | const std::vector<std::string> &GCCArgs, |
Chris Lattner | e96b2ed | 2004-07-24 07:49:11 +0000 | [diff] [blame] | 103 | const std::vector<std::string> &SharedLibs, |
| 104 | unsigned Timeout) { |
Chris Lattner | 8c56be5 | 2004-02-18 20:21:57 +0000 | [diff] [blame] | 105 | if (!SharedLibs.empty()) |
| 106 | throw ToolExecutionError("LLI currently does not support " |
| 107 | "loading shared libraries."); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 108 | |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 109 | if (!GCCArgs.empty()) |
| 110 | throw ToolExecutionError("LLI currently does not support " |
| 111 | "GCC Arguments."); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 112 | std::vector<const char*> LLIArgs; |
| 113 | LLIArgs.push_back(LLIPath.c_str()); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 114 | LLIArgs.push_back("-force-interpreter=true"); |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 115 | |
| 116 | // Add any extra LLI args. |
| 117 | for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i) |
| 118 | LLIArgs.push_back(ToolArgs[i].c_str()); |
| 119 | |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 120 | LLIArgs.push_back(Bytecode.c_str()); |
| 121 | // Add optional parameters to the running program from Argv |
| 122 | for (unsigned i=0, e = Args.size(); i != e; ++i) |
| 123 | LLIArgs.push_back(Args[i].c_str()); |
| 124 | LLIArgs.push_back(0); |
| 125 | |
| 126 | std::cout << "<lli>" << std::flush; |
Chris Lattner | 0b1fe84 | 2003-10-19 02:27:40 +0000 | [diff] [blame] | 127 | DEBUG(std::cerr << "\nAbout to run:\t"; |
Chris Lattner | 7b2ccff | 2003-10-19 02:14:58 +0000 | [diff] [blame] | 128 | for (unsigned i=0, e = LLIArgs.size()-1; i != e; ++i) |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 129 | std::cerr << " " << LLIArgs[i]; |
| 130 | std::cerr << "\n"; |
| 131 | ); |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 132 | return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0], |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 133 | sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 134 | Timeout); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // LLI create method - Try to find the LLI executable |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 138 | AbstractInterpreter *AbstractInterpreter::createLLI(const std::string &ProgPath, |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 139 | std::string &Message, |
| 140 | const std::vector<std::string> *ToolArgs) { |
Reid Spencer | 51ab8ec | 2004-12-13 23:43:44 +0000 | [diff] [blame] | 141 | std::string LLIPath = FindExecutable("lli", ProgPath).toString(); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 142 | if (!LLIPath.empty()) { |
| 143 | Message = "Found lli: " + LLIPath + "\n"; |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 144 | return new LLI(LLIPath, ToolArgs); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | Message = "Cannot find `lli' in executable directory or PATH!\n"; |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | //===----------------------------------------------------------------------===// |
| 152 | // LLC Implementation of AbstractIntepreter interface |
| 153 | // |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 154 | void LLC::OutputAsm(const std::string &Bytecode, sys::Path &OutputAsmFile) { |
Reid Spencer | cda985e | 2004-12-15 01:51:56 +0000 | [diff] [blame] | 155 | sys::Path uniqueFile(Bytecode+".llc.s"); |
| 156 | uniqueFile.makeUnique(); |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 157 | OutputAsmFile = uniqueFile; |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 158 | std::vector<const char *> LLCArgs; |
| 159 | LLCArgs.push_back (LLCPath.c_str()); |
| 160 | |
| 161 | // Add any extra LLC args. |
| 162 | for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i) |
| 163 | LLCArgs.push_back(ToolArgs[i].c_str()); |
| 164 | |
| 165 | LLCArgs.push_back ("-o"); |
| 166 | LLCArgs.push_back (OutputAsmFile.c_str()); // Output to the Asm file |
| 167 | LLCArgs.push_back ("-f"); // Overwrite as necessary... |
| 168 | LLCArgs.push_back (Bytecode.c_str()); // This is the input bytecode |
| 169 | LLCArgs.push_back (0); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 170 | |
| 171 | std::cout << "<llc>" << std::flush; |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 172 | DEBUG(std::cerr << "\nAbout to run:\t"; |
| 173 | for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i) |
| 174 | std::cerr << " " << LLCArgs[i]; |
| 175 | std::cerr << "\n"; |
| 176 | ); |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 177 | if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0], |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 178 | sys::Path(), sys::Path(), sys::Path())) |
| 179 | ProcessFailure(sys::Path(LLCPath), &LLCArgs[0]); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Chris Lattner | 9cbbee3 | 2004-02-18 23:24:41 +0000 | [diff] [blame] | 182 | void LLC::compileProgram(const std::string &Bytecode) { |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 183 | sys::Path OutputAsmFile; |
Chris Lattner | 9cbbee3 | 2004-02-18 23:24:41 +0000 | [diff] [blame] | 184 | OutputAsm(Bytecode, OutputAsmFile); |
Reid Spencer | a229c5c | 2005-07-08 03:08:58 +0000 | [diff] [blame] | 185 | OutputAsmFile.eraseFromDisk(); |
Chris Lattner | 9cbbee3 | 2004-02-18 23:24:41 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 188 | int LLC::ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 189 | const std::vector<std::string> &Args, |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 190 | const std::string &InputFile, |
| 191 | const std::string &OutputFile, |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 192 | const std::vector<std::string> &ArgsForGCC, |
Chris Lattner | e96b2ed | 2004-07-24 07:49:11 +0000 | [diff] [blame] | 193 | const std::vector<std::string> &SharedLibs, |
| 194 | unsigned Timeout) { |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 195 | |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 196 | sys::Path OutputAsmFile; |
Chris Lattner | 8c56be5 | 2004-02-18 20:21:57 +0000 | [diff] [blame] | 197 | OutputAsm(Bytecode, OutputAsmFile); |
| 198 | FileRemover OutFileRemover(OutputAsmFile); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 199 | |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 200 | std::vector<std::string> GCCArgs(ArgsForGCC); |
| 201 | GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end()); |
| 202 | |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 203 | // Assuming LLC worked, compile the result with GCC and run it. |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 204 | return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile, |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 205 | InputFile, OutputFile, GCCArgs, Timeout); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 208 | /// createLLC - Try to find the LLC executable |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 209 | /// |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 210 | LLC *AbstractInterpreter::createLLC(const std::string &ProgramPath, |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 211 | std::string &Message, |
| 212 | const std::vector<std::string> *Args) { |
Reid Spencer | 51ab8ec | 2004-12-13 23:43:44 +0000 | [diff] [blame] | 213 | std::string LLCPath = FindExecutable("llc", ProgramPath).toString(); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 214 | if (LLCPath.empty()) { |
| 215 | Message = "Cannot find `llc' in executable directory or PATH!\n"; |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | Message = "Found llc: " + LLCPath + "\n"; |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 220 | GCC *gcc = GCC::create(ProgramPath, Message); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 221 | if (!gcc) { |
| 222 | std::cerr << Message << "\n"; |
| 223 | exit(1); |
| 224 | } |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 225 | return new LLC(LLCPath, gcc, Args); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | //===---------------------------------------------------------------------===// |
| 229 | // JIT Implementation of AbstractIntepreter interface |
| 230 | // |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 231 | namespace { |
| 232 | class JIT : public AbstractInterpreter { |
| 233 | std::string LLIPath; // The path to the LLI executable |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 234 | std::vector<std::string> ToolArgs; // Args to pass to LLI |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 235 | public: |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 236 | JIT(const std::string &Path, const std::vector<std::string> *Args) |
| 237 | : LLIPath(Path) { |
| 238 | ToolArgs.clear (); |
Brian Gaeke | 48b008d | 2004-05-04 22:02:41 +0000 | [diff] [blame] | 239 | if (Args) { ToolArgs = *Args; } |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 240 | } |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 241 | |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 242 | virtual int ExecuteProgram(const std::string &Bytecode, |
| 243 | const std::vector<std::string> &Args, |
| 244 | const std::string &InputFile, |
| 245 | const std::string &OutputFile, |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 246 | const std::vector<std::string> &GCCArgs = |
| 247 | std::vector<std::string>(), |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 248 | const std::vector<std::string> &SharedLibs = |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 249 | std::vector<std::string>(), |
| 250 | unsigned Timeout =0 ); |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 251 | }; |
| 252 | } |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 253 | |
| 254 | int JIT::ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 255 | const std::vector<std::string> &Args, |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 256 | const std::string &InputFile, |
| 257 | const std::string &OutputFile, |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 258 | const std::vector<std::string> &GCCArgs, |
Chris Lattner | e96b2ed | 2004-07-24 07:49:11 +0000 | [diff] [blame] | 259 | const std::vector<std::string> &SharedLibs, |
| 260 | unsigned Timeout) { |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 261 | if (!GCCArgs.empty()) |
| 262 | throw ToolExecutionError("JIT does not support GCC Arguments."); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 263 | // Construct a vector of parameters, incorporating those from the command-line |
| 264 | std::vector<const char*> JITArgs; |
| 265 | JITArgs.push_back(LLIPath.c_str()); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 266 | JITArgs.push_back("-force-interpreter=false"); |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 267 | |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 268 | // Add any extra LLI args. |
| 269 | for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i) |
| 270 | JITArgs.push_back(ToolArgs[i].c_str()); |
| 271 | |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 272 | for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) { |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 273 | JITArgs.push_back("-load"); |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 274 | JITArgs.push_back(SharedLibs[i].c_str()); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 275 | } |
| 276 | JITArgs.push_back(Bytecode.c_str()); |
| 277 | // Add optional parameters to the running program from Argv |
| 278 | for (unsigned i=0, e = Args.size(); i != e; ++i) |
| 279 | JITArgs.push_back(Args[i].c_str()); |
| 280 | JITArgs.push_back(0); |
| 281 | |
| 282 | std::cout << "<jit>" << std::flush; |
Chris Lattner | 0b1fe84 | 2003-10-19 02:27:40 +0000 | [diff] [blame] | 283 | DEBUG(std::cerr << "\nAbout to run:\t"; |
Chris Lattner | 7b2ccff | 2003-10-19 02:14:58 +0000 | [diff] [blame] | 284 | for (unsigned i=0, e = JITArgs.size()-1; i != e; ++i) |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 285 | std::cerr << " " << JITArgs[i]; |
| 286 | std::cerr << "\n"; |
| 287 | ); |
| 288 | DEBUG(std::cerr << "\nSending output to " << OutputFile << "\n"); |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 289 | return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0], |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 290 | sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 291 | Timeout); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 294 | /// createJIT - Try to find the LLI executable |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 295 | /// |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 296 | AbstractInterpreter *AbstractInterpreter::createJIT(const std::string &ProgPath, |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 297 | std::string &Message, const std::vector<std::string> *Args) { |
Reid Spencer | 51ab8ec | 2004-12-13 23:43:44 +0000 | [diff] [blame] | 298 | std::string LLIPath = FindExecutable("lli", ProgPath).toString(); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 299 | if (!LLIPath.empty()) { |
| 300 | Message = "Found lli: " + LLIPath + "\n"; |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 301 | return new JIT(LLIPath, Args); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | Message = "Cannot find `lli' in executable directory or PATH!\n"; |
| 305 | return 0; |
| 306 | } |
| 307 | |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 308 | void CBE::OutputC(const std::string &Bytecode, sys::Path& OutputCFile) { |
Reid Spencer | cda985e | 2004-12-15 01:51:56 +0000 | [diff] [blame] | 309 | sys::Path uniqueFile(Bytecode+".cbe.c"); |
| 310 | uniqueFile.makeUnique(); |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 311 | OutputCFile = uniqueFile; |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 312 | std::vector<const char *> LLCArgs; |
| 313 | LLCArgs.push_back (LLCPath.c_str()); |
| 314 | |
| 315 | // Add any extra LLC args. |
| 316 | for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i) |
| 317 | LLCArgs.push_back(ToolArgs[i].c_str()); |
| 318 | |
| 319 | LLCArgs.push_back ("-o"); |
| 320 | LLCArgs.push_back (OutputCFile.c_str()); // Output to the C file |
| 321 | LLCArgs.push_back ("-march=c"); // Output C language |
| 322 | LLCArgs.push_back ("-f"); // Overwrite as necessary... |
| 323 | LLCArgs.push_back (Bytecode.c_str()); // This is the input bytecode |
| 324 | LLCArgs.push_back (0); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 325 | |
| 326 | std::cout << "<cbe>" << std::flush; |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 327 | DEBUG(std::cerr << "\nAbout to run:\t"; |
| 328 | for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i) |
| 329 | std::cerr << " " << LLCArgs[i]; |
| 330 | std::cerr << "\n"; |
| 331 | ); |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 332 | if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(), |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 333 | sys::Path())) |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 334 | ProcessFailure(LLCPath, &LLCArgs[0]); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Chris Lattner | 9cbbee3 | 2004-02-18 23:24:41 +0000 | [diff] [blame] | 337 | void CBE::compileProgram(const std::string &Bytecode) { |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 338 | sys::Path OutputCFile; |
Chris Lattner | 9cbbee3 | 2004-02-18 23:24:41 +0000 | [diff] [blame] | 339 | OutputC(Bytecode, OutputCFile); |
Reid Spencer | a229c5c | 2005-07-08 03:08:58 +0000 | [diff] [blame] | 340 | OutputCFile.eraseFromDisk(); |
Chris Lattner | 9cbbee3 | 2004-02-18 23:24:41 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 343 | int CBE::ExecuteProgram(const std::string &Bytecode, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 344 | const std::vector<std::string> &Args, |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 345 | const std::string &InputFile, |
| 346 | const std::string &OutputFile, |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 347 | const std::vector<std::string> &ArgsForGCC, |
Chris Lattner | e96b2ed | 2004-07-24 07:49:11 +0000 | [diff] [blame] | 348 | const std::vector<std::string> &SharedLibs, |
| 349 | unsigned Timeout) { |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 350 | sys::Path OutputCFile; |
Chris Lattner | 8c56be5 | 2004-02-18 20:21:57 +0000 | [diff] [blame] | 351 | OutputC(Bytecode, OutputCFile); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 352 | |
Chris Lattner | 8c56be5 | 2004-02-18 20:21:57 +0000 | [diff] [blame] | 353 | FileRemover CFileRemove(OutputCFile); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 354 | |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 355 | std::vector<std::string> GCCArgs(ArgsForGCC); |
| 356 | GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end()); |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 357 | return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile, |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 358 | InputFile, OutputFile, GCCArgs, Timeout); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Chris Lattner | 9915cd9 | 2004-02-17 06:40:06 +0000 | [diff] [blame] | 361 | /// createCBE - Try to find the 'llc' executable |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 362 | /// |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 363 | CBE *AbstractInterpreter::createCBE(const std::string &ProgramPath, |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 364 | std::string &Message, |
| 365 | const std::vector<std::string> *Args) { |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 366 | sys::Path LLCPath = FindExecutable("llc", ProgramPath); |
| 367 | if (LLCPath.isEmpty()) { |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 368 | Message = |
Chris Lattner | 9915cd9 | 2004-02-17 06:40:06 +0000 | [diff] [blame] | 369 | "Cannot find `llc' in executable directory or PATH!\n"; |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 370 | return 0; |
| 371 | } |
| 372 | |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 373 | Message = "Found llc: " + LLCPath.toString() + "\n"; |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 374 | GCC *gcc = GCC::create(ProgramPath, Message); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 375 | if (!gcc) { |
| 376 | std::cerr << Message << "\n"; |
| 377 | exit(1); |
| 378 | } |
Brian Gaeke | d11577b | 2004-05-04 21:09:01 +0000 | [diff] [blame] | 379 | return new CBE(LLCPath, gcc, Args); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | //===---------------------------------------------------------------------===// |
| 383 | // GCC abstraction |
| 384 | // |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 385 | int GCC::ExecuteProgram(const std::string &ProgramFile, |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 386 | const std::vector<std::string> &Args, |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 387 | FileType fileType, |
| 388 | const std::string &InputFile, |
| 389 | const std::string &OutputFile, |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 390 | const std::vector<std::string> &ArgsForGCC, |
| 391 | unsigned Timeout ) { |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 392 | std::vector<const char*> GCCArgs; |
| 393 | |
| 394 | GCCArgs.push_back(GCCPath.c_str()); |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 395 | |
Chris Lattner | eeed983 | 2003-10-14 21:52:52 +0000 | [diff] [blame] | 396 | // Specify -x explicitly in case the extension is wonky |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 397 | GCCArgs.push_back("-x"); |
| 398 | if (fileType == CFile) { |
| 399 | GCCArgs.push_back("c"); |
| 400 | GCCArgs.push_back("-fno-strict-aliasing"); |
| 401 | } else { |
| 402 | GCCArgs.push_back("assembler"); |
Chris Lattner | d00b288 | 2005-08-29 13:14:24 +0000 | [diff] [blame] | 403 | #ifdef __APPLE__ |
| 404 | GCCArgs.push_back("-force_cpusubtype_ALL"); |
| 405 | #endif |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 406 | } |
| 407 | GCCArgs.push_back(ProgramFile.c_str()); // Specify the input filename... |
| 408 | GCCArgs.push_back("-o"); |
Reid Spencer | cda985e | 2004-12-15 01:51:56 +0000 | [diff] [blame] | 409 | sys::Path OutputBinary (ProgramFile+".gcc.exe"); |
| 410 | OutputBinary.makeUnique(); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 411 | GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file... |
Reid Spencer | 51ab5c8 | 2006-06-06 00:00:42 +0000 | [diff] [blame^] | 412 | |
| 413 | // Add any arguments intended for GCC. We locate them here because this is |
| 414 | // most likely -L and -l options that need to come before other libraries but |
| 415 | // after the source. Other options won't be sensitive to placement on the |
| 416 | // command line, so this should be safe. |
| 417 | for (unsigned i = 0, e = ArgsForGCC.size(); i != e; ++i) |
| 418 | GCCArgs.push_back(ArgsForGCC[i].c_str()); |
| 419 | |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 420 | GCCArgs.push_back("-lm"); // Hard-code the math library... |
| 421 | GCCArgs.push_back("-O2"); // Optimize the program a bit... |
Brian Gaeke | c8db76c | 2003-11-18 06:31:17 +0000 | [diff] [blame] | 422 | #if defined (HAVE_LINK_R) |
Chris Lattner | 1f0f162 | 2003-10-18 21:54:47 +0000 | [diff] [blame] | 423 | GCCArgs.push_back("-Wl,-R."); // Search this dir for .so files |
Brian Gaeke | c8db76c | 2003-11-18 06:31:17 +0000 | [diff] [blame] | 424 | #endif |
Chris Lattner | fdcc71e | 2006-02-04 05:02:27 +0000 | [diff] [blame] | 425 | #ifdef __sparc__ |
| 426 | GCCArgs.push_back("-mcpu=v9"); |
| 427 | #endif |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 428 | GCCArgs.push_back(0); // NULL terminator |
| 429 | |
| 430 | std::cout << "<gcc>" << std::flush; |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 431 | if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(), |
| 432 | sys::Path())) { |
Chris Lattner | 89bf9ea | 2004-02-18 20:38:00 +0000 | [diff] [blame] | 433 | ProcessFailure(GCCPath, &GCCArgs[0]); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 434 | exit(1); |
| 435 | } |
| 436 | |
| 437 | std::vector<const char*> ProgramArgs; |
Chris Lattner | 45495c5 | 2005-02-13 23:13:47 +0000 | [diff] [blame] | 438 | |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 439 | ProgramArgs.push_back(OutputBinary.c_str()); |
| 440 | // Add optional parameters to the running program from Argv |
| 441 | for (unsigned i=0, e = Args.size(); i != e; ++i) |
| 442 | ProgramArgs.push_back(Args[i].c_str()); |
| 443 | ProgramArgs.push_back(0); // NULL terminator |
| 444 | |
| 445 | // Now that we have a binary, run it! |
| 446 | std::cout << "<program>" << std::flush; |
Chris Lattner | 0b1fe84 | 2003-10-19 02:27:40 +0000 | [diff] [blame] | 447 | DEBUG(std::cerr << "\nAbout to run:\t"; |
Chris Lattner | 7b2ccff | 2003-10-19 02:14:58 +0000 | [diff] [blame] | 448 | for (unsigned i=0, e = ProgramArgs.size()-1; i != e; ++i) |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 449 | std::cerr << " " << ProgramArgs[i]; |
| 450 | std::cerr << "\n"; |
| 451 | ); |
Chris Lattner | 8c56be5 | 2004-02-18 20:21:57 +0000 | [diff] [blame] | 452 | |
Reid Spencer | 9ac1418 | 2004-12-16 23:01:34 +0000 | [diff] [blame] | 453 | FileRemover OutputBinaryRemover(OutputBinary); |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 454 | return RunProgramWithTimeout(OutputBinary, &ProgramArgs[0], |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 455 | sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 456 | Timeout); |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Chris Lattner | 1798e4a | 2003-10-14 21:07:25 +0000 | [diff] [blame] | 459 | int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType, |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 460 | std::string &OutputFile) { |
Reid Spencer | cda985e | 2004-12-15 01:51:56 +0000 | [diff] [blame] | 461 | sys::Path uniqueFilename(InputFile+LTDL_SHLIB_EXT); |
| 462 | uniqueFilename.makeUnique(); |
| 463 | OutputFile = uniqueFilename.toString(); |
| 464 | |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 465 | // Compile the C/asm file into a shared object |
| 466 | const char* GCCArgs[] = { |
| 467 | GCCPath.c_str(), |
| 468 | "-x", (fileType == AsmFile) ? "assembler" : "c", |
| 469 | "-fno-strict-aliasing", |
| 470 | InputFile.c_str(), // Specify the input filename... |
| 471 | #if defined(sparc) || defined(__sparc__) || defined(__sparcv9) |
| 472 | "-G", // Compile a shared library, `-G' for Sparc |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 473 | #elif defined(__APPLE__) |
Nate Begeman | 7925588 | 2004-10-17 23:03:32 +0000 | [diff] [blame] | 474 | "-single_module", // link all source files into a single module |
Misha Brukman | b3998ec | 2004-07-16 19:45:45 +0000 | [diff] [blame] | 475 | "-dynamiclib", // `-dynamiclib' for MacOS X/PowerPC |
Chris Lattner | e312e15 | 2004-07-19 06:03:51 +0000 | [diff] [blame] | 476 | "-undefined", // in data segment, rather than generating |
Chris Lattner | 5fbf29c | 2004-07-19 06:00:17 +0000 | [diff] [blame] | 477 | "dynamic_lookup", // blocks. dynamic_lookup requires that you set |
| 478 | // MACOSX_DEPLOYMENT_TARGET=10.3 in your env. |
Misha Brukman | b3998ec | 2004-07-16 19:45:45 +0000 | [diff] [blame] | 479 | #else |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 480 | "-shared", // `-shared' for Linux/X86, maybe others |
| 481 | #endif |
Chris Lattner | 1c81f13 | 2005-03-09 03:31:02 +0000 | [diff] [blame] | 482 | |
Andrew Lenharth | 572668a | 2005-03-10 20:15:09 +0000 | [diff] [blame] | 483 | #if defined(__ia64__) || defined(__alpha__) |
Chris Lattner | 1c81f13 | 2005-03-09 03:31:02 +0000 | [diff] [blame] | 484 | "-fPIC", // IA64 requires shared objs to contain PIC |
| 485 | #endif |
Chris Lattner | fdcc71e | 2006-02-04 05:02:27 +0000 | [diff] [blame] | 486 | #ifdef __sparc__ |
| 487 | "-mcpu=v9", |
| 488 | #endif |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 489 | "-o", OutputFile.c_str(), // Output to the right filename... |
| 490 | "-O2", // Optimize the program a bit... |
| 491 | 0 |
| 492 | }; |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 493 | |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 494 | std::cout << "<gcc>" << std::flush; |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 495 | if (RunProgramWithTimeout(GCCPath, GCCArgs, sys::Path(), sys::Path(), |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 496 | sys::Path())) { |
Chris Lattner | 89bf9ea | 2004-02-18 20:38:00 +0000 | [diff] [blame] | 497 | ProcessFailure(GCCPath, GCCArgs); |
Chris Lattner | 1798e4a | 2003-10-14 21:07:25 +0000 | [diff] [blame] | 498 | return 1; |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 499 | } |
| 500 | return 0; |
| 501 | } |
| 502 | |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 503 | /// create - Try to find the `gcc' executable |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 504 | /// |
Chris Lattner | 7915a1e | 2003-10-14 21:34:11 +0000 | [diff] [blame] | 505 | GCC *GCC::create(const std::string &ProgramPath, std::string &Message) { |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 506 | sys::Path GCCPath = FindExecutable("gcc", ProgramPath); |
| 507 | if (GCCPath.isEmpty()) { |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 508 | Message = "Cannot find `gcc' in executable directory or PATH!\n"; |
| 509 | return 0; |
| 510 | } |
| 511 | |
Reid Spencer | b31baa8 | 2004-12-19 18:00:21 +0000 | [diff] [blame] | 512 | Message = "Found gcc: " + GCCPath.toString() + "\n"; |
Misha Brukman | 9558c6a | 2003-09-29 22:39:25 +0000 | [diff] [blame] | 513 | return new GCC(GCCPath); |
| 514 | } |