-//===----------------------------------------------------------------------===//
-// GCC abstraction
-//
-// This is not a *real* AbstractInterpreter as it does not accept bytecode
-// files, but only input acceptable to GCC, i.e. C, C++, and assembly files
-//
-class GCC {
- std::string GCCPath; // The path to the gcc executable
-public:
- GCC(const std::string &gccPath) : GCCPath(gccPath) { }
- virtual ~GCC() {}
-
- // GCC create method - Try to find the `gcc' executable
- static GCC *create(BugDriver *BD, std::string &Message) {
- std::string GCCPath = FindExecutable("gcc", BD->getToolName());
- if (GCCPath.empty()) {
- Message = "Cannot find `gcc' in bugpoint executable directory or PATH!\n";
- return 0;
- }
-
- Message = "Found gcc: " + GCCPath + "\n";
- return new GCC(GCCPath);
- }
-
- virtual int ExecuteProgram(const std::string &ProgramFile,
- FileType fileType,
- const std::string &OutputFile,
- const std::string &SharedLib = "");
-
- int MakeSharedObject(const std::string &InputFile,
- FileType fileType,
- std::string &OutputFile);
-
- void ProcessFailure(const char **Args);
-};
-
-int GCC::ExecuteProgram(const std::string &ProgramFile,
- FileType fileType,
- const std::string &OutputFile,
- const std::string &SharedLib) {
- std::string OutputBinary = getUniqueFilename("bugpoint.gcc.exe");
- std::vector<const char*> GCCArgs;
-
- GCCArgs.push_back(GCCPath.c_str());
- if (!SharedLib.empty()) // Specify the shared library to link in...
- GCCArgs.push_back(SharedLib.c_str());
- GCCArgs.push_back("-x");
- GCCArgs.push_back((fileType == AsmFile) ? "assembler" : "c");
- GCCArgs.push_back(ProgramFile.c_str()); // Specify the input filename...
- GCCArgs.push_back("-o");
- GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file...
- GCCArgs.push_back("-lm"); // Hard-code the math library...
- GCCArgs.push_back("-O2"); // Optimize the program a bit...
- GCCArgs.push_back(0); // NULL terminator
-
- std::cout << "<gcc>" << std::flush;
- if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], "/dev/null", "/dev/null",
- "/dev/null")) {
- ProcessFailure(&GCCArgs[0]);
- exit(1);
- }