-//===----------------------------------------------------------------------===//
-// LLC Implementation of AbstractIntepreter interface
-//
-class LLC : public AbstractInterpreter {
- std::string LLCPath; // The path to the LLC executable
- GCC *gcc;
-public:
- LLC(const std::string &llcPath, GCC *Gcc)
- : LLCPath(llcPath), gcc(Gcc) { }
- ~LLC() { delete gcc; }
-
- // LLC create method - Try to find the LLC executable
- static LLC *create(BugDriver *BD, std::string &Message) {
- std::string LLCPath = FindExecutable("llc", BD->getToolName());
- if (LLCPath.empty()) {
- Message = "Cannot find `llc' in bugpoint executable directory or PATH!\n";
- return 0;
- }
-
- Message = "Found llc: " + LLCPath + "\n";
- GCC *gcc = GCC::create(BD, Message);
- if (!gcc) {
- std::cerr << Message << "\n";
- exit(1);
- }
- return new LLC(LLCPath, gcc);
- }
-
- virtual int ExecuteProgram(const std::string &Bytecode,
- const std::string &OutputFile,
- const std::string &SharedLib = "");
-
- int OutputAsm(const std::string &Bytecode,
- std::string &OutputAsmFile);
-};
-
-int LLC::OutputAsm(const std::string &Bytecode,
- std::string &OutputAsmFile) {
- OutputAsmFile = "bugpoint.llc.s";
- const char *LLCArgs[] = {
- LLCPath.c_str(),
- "-o", OutputAsmFile.c_str(), // Output to the Asm file
- "-f", // Overwrite as necessary...
- Bytecode.c_str(), // This is the input bytecode
- 0
- };
-
- std::cout << "<llc>" << std::flush;
- if (RunProgramWithTimeout(LLCPath, LLCArgs, "/dev/null", "/dev/null",
- "/dev/null")) {
- // If LLC failed on the bytecode, print error...
- std::cerr << "bugpoint error: `llc' failed!\n";
- removeFile(OutputAsmFile);
- return 1;
- }
-
- return 0;
-}
-
-int LLC::ExecuteProgram(const std::string &Bytecode,
- const std::string &OutputFile,
- const std::string &SharedLib) {
-
- std::string OutputAsmFile;
- if (OutputAsm(Bytecode, OutputAsmFile)) {
- std::cerr << "Could not generate asm code with `llc', exiting.\n";
- exit(1);
- }
-
- // Assuming LLC worked, compile the result with GCC and run it.
- int Result = gcc->ExecuteProgram(OutputAsmFile,AsmFile,OutputFile,SharedLib);
- removeFile(OutputAsmFile);
- return Result;
-}
-
-
-//===----------------------------------------------------------------------===//
-// JIT Implementation of AbstractIntepreter interface
-//
-class JIT : public AbstractInterpreter {
- std::string LLIPath; // The path to the LLI executable
-public:
- JIT(const std::string &Path) : LLIPath(Path) { }
-
- // JIT create method - Try to find the LLI executable
- static JIT *create(BugDriver *BD, std::string &Message) {
- std::string LLIPath = FindExecutable("lli", BD->getToolName());
- if (!LLIPath.empty()) {
- Message = "Found lli: " + LLIPath + "\n";
- return new JIT(LLIPath);
- }
-
- Message = "Cannot find `lli' in bugpoint executable directory or PATH!\n";
- return 0;
- }
- virtual int ExecuteProgram(const std::string &Bytecode,
- const std::string &OutputFile,
- const std::string &SharedLib = "");
-};
-
-int JIT::ExecuteProgram(const std::string &Bytecode,
- const std::string &OutputFile,
- const std::string &SharedLib) {
- // Construct a vector of parameters, incorporating those from the command-line
- std::vector<const char*> JITArgs;
- JITArgs.push_back(LLIPath.c_str());
- JITArgs.push_back("-quiet");
- JITArgs.push_back("-force-interpreter=false");
- if (!SharedLib.empty()) {
- JITArgs.push_back("-load");
- JITArgs.push_back(SharedLib.c_str());
- }
- JITArgs.push_back(Bytecode.c_str());
- // Add optional parameters to the running program from Argv
- for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
- JITArgs.push_back(InputArgv[i].c_str());
- JITArgs.push_back(0);
-
- std::cout << "<jit>" << std::flush;
- DEBUG(std::cerr << "\nAbout to run:\n\t";
- for (unsigned i=0, e = JITArgs.size(); i != e; ++i)
- std::cerr << " " << JITArgs[i];
- std::cerr << "\n";
- );
- DEBUG(std::cerr << "\nSending output to " << OutputFile << "\n");
- return RunProgramWithTimeout(LLIPath, &JITArgs[0],
- InputFile, OutputFile, OutputFile);
-}
-
-//===----------------------------------------------------------------------===//
-// CBE Implementation of AbstractIntepreter interface
-//
-class CBE : public AbstractInterpreter {
- std::string DISPath; // The path to the LLVM 'dis' executable
- GCC *gcc;
-public:
- CBE(const std::string &disPath, GCC *Gcc) : DISPath(disPath), gcc(Gcc) { }
- ~CBE() { delete gcc; }
-
- // CBE create method - Try to find the 'dis' executable
- static CBE *create(BugDriver *BD, std::string &Message) {
- std::string DISPath = FindExecutable("dis", BD->getToolName());
- if (DISPath.empty()) {
- Message = "Cannot find `dis' in bugpoint executable directory or PATH!\n";
- return 0;
- }
-
- Message = "Found dis: " + DISPath + "\n";
-
- GCC *gcc = GCC::create(BD, Message);
- if (!gcc) {
- std::cerr << Message << "\n";
- exit(1);
- }
- return new CBE(DISPath, gcc);
- }
-
- virtual int ExecuteProgram(const std::string &Bytecode,
- const std::string &OutputFile,
- const std::string &SharedLib = "");
-
- // Sometimes we just want to go half-way and only generate the C file,
- // not necessarily compile it with GCC and run the program
- virtual int OutputC(const std::string &Bytecode,
- std::string &OutputCFile);
-
-};
-
-int CBE::OutputC(const std::string &Bytecode,
- std::string &OutputCFile) {
- OutputCFile = "bugpoint.cbe.c";
- const char *DisArgs[] = {
- DISPath.c_str(),
- "-o", OutputCFile.c_str(), // Output to the C file
- "-c", // Output to C
- "-f", // Overwrite as necessary...
- Bytecode.c_str(), // This is the input bytecode
- 0
- };
-
- std::cout << "<cbe>" << std::flush;
- if (RunProgramWithTimeout(DISPath, DisArgs, "/dev/null", "/dev/null",
- "/dev/null")) {
- // If dis failed on the bytecode, print error...
- std::cerr << "bugpoint error: `dis -c' failed!\n";
- return 1;
- }
-
- return 0;
-}
-
-
-int CBE::ExecuteProgram(const std::string &Bytecode,
- const std::string &OutputFile,
- const std::string &SharedLib) {
- std::string OutputCFile;
- if (OutputC(Bytecode, OutputCFile)) {
- std::cerr << "Could not generate C code with `dis', exiting.\n";
- exit(1);
- }
-
- int Result = gcc->ExecuteProgram(OutputCFile, CFile, OutputFile, SharedLib);
- removeFile(OutputCFile);
-
- return Result;
-}
-
-