-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)) {
- errs() << "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);
-
- outs() << "<cbe>"; outs().flush();
- DEBUG(errs() << "\nAbout to run:\t";
- for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
- errs() << " " << LLCArgs[i];
- errs() << "\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, !SaveTemps);
-
- 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);
-}
-
-/// createCBE - Try to find the 'llc' executable
-///
-CBE *AbstractInterpreter::createCBE(const char *Argv0,
- std::string &Message,
- const std::vector<std::string> *Args,
- const std::vector<std::string> *GCCArgs) {
- sys::Path LLCPath =
- FindExecutable("llc", Argv0,
- reinterpret_cast<void *>(&createCBE));
- if (LLCPath.isEmpty()) {
- Message =
- "Cannot find `llc' in executable directory or PATH!\n";
- return 0;
- }
-
- Message = "Found llc: " + LLCPath.toString() + "\n";
- GCC *gcc = GCC::create(Message, GCCArgs);
- if (!gcc) {
- errs() << Message << "\n";
- exit(1);
- }
- return new CBE(LLCPath, gcc, Args);
-}
-