-GCC::FileType CBE::OutputCode(const std::string &Bitcode,
- sys::Path &OutputCFile) {
- sys::Path uniqueFile(Bitcode+".cbe.c");
- std::string ErrMsg;
- if (uniqueFile.makeUnique(true, &ErrMsg)) {
- std::cerr << "Error making unique filename: " << ErrMsg << "\n";
- exit(1);
- }
- OutputCFile = uniqueFile;
- std::vector<const char *> LLCArgs;
- LLCArgs.push_back (LLCPath.c_str());
-
- // Add any extra LLC args.
- for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
- LLCArgs.push_back(ToolArgs[i].c_str());
-
- LLCArgs.push_back ("-o");
- LLCArgs.push_back (OutputCFile.c_str()); // Output to the C file
- LLCArgs.push_back ("-march=c"); // Output C language
- LLCArgs.push_back ("-f"); // Overwrite as necessary...
- LLCArgs.push_back (Bitcode.c_str()); // This is the input bitcode
- LLCArgs.push_back (0);
-
- std::cout << "<cbe>" << std::flush;
- DEBUG(std::cerr << "\nAbout to run:\t";
- for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
- std::cerr << " " << LLCArgs[i];
- std::cerr << "\n";
- );
- if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(),
- sys::Path()))
- ProcessFailure(LLCPath, &LLCArgs[0]);
- return GCC::CFile;
-}
-
-void CBE::compileProgram(const std::string &Bitcode) {
- sys::Path OutputCFile;
- OutputCode(Bitcode, OutputCFile);
- OutputCFile.eraseFromDisk();
-}
-
-int CBE::ExecuteProgram(const std::string &Bitcode,
- const std::vector<std::string> &Args,
- const std::string &InputFile,
- const std::string &OutputFile,
- const std::vector<std::string> &ArgsForGCC,
- const std::vector<std::string> &SharedLibs,
- unsigned Timeout,
- unsigned MemoryLimit) {
- sys::Path OutputCFile;
- OutputCode(Bitcode, OutputCFile);
-
- FileRemover CFileRemove(OutputCFile);
-
- std::vector<std::string> GCCArgs(ArgsForGCC);
- GCCArgs.insert(GCCArgs.end(),SharedLibs.begin(),SharedLibs.end());
- return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
- InputFile, OutputFile, GCCArgs,
- Timeout, MemoryLimit);
-}