- 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);
- }
-
- std::vector<const char*> ProgramArgs;
- ProgramArgs.push_back(OutputBinary.c_str());
- // Add optional parameters to the running program from Argv
- for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
- ProgramArgs.push_back(InputArgv[i].c_str());
- ProgramArgs.push_back(0); // NULL terminator
-
- // Now that we have a binary, run it!
- std::cout << "<program>" << std::flush;
- DEBUG(std::cerr << "\nAbout to run:\n\t";
- for (unsigned i=0, e = ProgramArgs.size(); i != e; ++i)
- std::cerr << " " << ProgramArgs[i];
- std::cerr << "\n";
- );
- int ProgramResult = RunProgramWithTimeout(OutputBinary, &ProgramArgs[0],
- InputFile, OutputFile, OutputFile);
- removeFile(OutputBinary);
- return ProgramResult;