using namespace llvm;
void llvm::DisplayGraph(const sys::Path &Filename) {
+ std::string ErrMsg;
#if HAVE_GRAPHVIZ
sys::Path Graphviz(LLVM_PATH_GRAPHVIZ);
args.push_back(0);
std::cerr << "Running 'Graphviz' program... " << std::flush;
- if (sys::Program::ExecuteAndWait(Graphviz, &args[0])) {
- std::cerr << "Error viewing graph: 'Graphviz' not in path?\n";
+ if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,&ErrMsg)) {
+ std::cerr << "Error viewing graph: " << ErrMsg << "\n";
}
#elif (HAVE_GV && HAVE_DOT)
sys::Path PSFilename = Filename;
args.push_back(0);
std::cerr << "Running 'dot' program... " << std::flush;
- if (sys::Program::ExecuteAndWait(dot, &args[0])) {
- std::cerr << "Error viewing graph: 'dot' not in path?\n";
+ if (sys::Program::ExecuteAndWait(dot, &args[0],0,0,0,&ErrMsg)) {
+ std::cerr << "Error viewing graph: '" << ErrMsg << "\n";
} else {
std::cerr << " done. \n";
args.push_back(PSFilename.c_str());
args.push_back(0);
- if (sys::Program::ExecuteAndWait(gv, &args[0])) {
- std::cerr << "Error viewing graph: 'gv' not in path?\n";
+ ErrMsg.clear();
+ if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,&ErrMsg)) {
+ std::cerr << "Error viewing graph: " << ErrMsg << "\n";
}
}
PSFilename.eraseFromDisk();
args.push_back(0);
std::cerr << "Running 'dotty' program... " << std::flush;
- if (sys::Program::ExecuteAndWait(dotty, &args[0])) {
- std::cerr << "Error viewing graph: 'dotty' not in path?\n";
+ if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,&ErrMsg)) {
+ std::cerr << "Error viewing graph: " << ErrMsg << "\n";
} else {
#ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns.
return;
args[n++] = 0;
sys::Path prog(sys::Program::FindProgramByName(ToolName));
- int result = sys::Program::ExecuteAndWait(prog,args,0,0,Timeout);
+ std::string ErrMsg;
+ int result = sys::Program::ExecuteAndWait(prog,args,0,0,Timeout,&ErrMsg);
// If we are supposed to delete the bytecode file or if the passes crashed,
// remove it now. This may fail if the file was never created, but that's ok.
std::cout << "Success!\n";
else if (result > 0)
std::cout << "Exited with error code '" << result << "'\n";
- else if (result == -9999)
- std::cout << "Program not executable\n";
- else if (result < 0)
- std::cout << "Crashed with signal #" << abs(result) << "\n";
+ else if (result < 0) {
+ if (result == -1)
+ std::cout << "Execute failed: " << ErrMsg << "\n";
+ else
+ std::cout << "Crashed with signal #" << abs(result) << "\n";
+ }
if (result & 0x01000000)
std::cout << "Dumped core\n";
}
sys::Path ErrorFilename("error_messages");
ErrorFilename.makeUnique();
RunProgramWithTimeout(ProgPath, Args, sys::Path(""), ErrorFilename,
- ErrorFilename); // FIXME: check return code
+ ErrorFilename); // FIXME: check return code ?
// Print out the error messages generated by GCC if possible...
std::ifstream ErrorFile(ErrorFilename.c_str());
int llvm::GenerateAssembly(const std::string &OutputFilename,
const std::string &InputFilename,
const sys::Path &llc,
+ std::string& ErrMsg,
bool Verbose) {
// Run LLC to convert the bytecode file into assembly code.
std::vector<const char*> args;
args.push_back(InputFilename.c_str());
args.push_back(0);
if (Verbose) dumpArgs(&args[0]);
- return sys::Program::ExecuteAndWait(llc, &args[0]);
+ return sys::Program::ExecuteAndWait(llc, &args[0],0,0,0,&ErrMsg);
}
/// GenerateCFile - generates a C source file from the specified bytecode file.
int llvm::GenerateCFile(const std::string &OutputFile,
const std::string &InputFile,
const sys::Path &llc,
+ std::string& ErrMsg,
bool Verbose) {
// Run LLC to convert the bytecode file into C.
std::vector<const char*> args;
args.push_back(InputFile.c_str());
args.push_back(0);
if (Verbose) dumpArgs(&args[0]);
- return sys::Program::ExecuteAndWait(llc, &args[0]);
+ return sys::Program::ExecuteAndWait(llc, &args[0],0,0,0,&ErrMsg);
}
/// GenerateNative - generates a native executable file from the specified
bool ExportAllAsDynamic,
const std::vector<std::string> &RPaths,
const std::string &SOName,
+ std::string& ErrMsg,
bool Verbose) {
// Remove these environment variables from the environment of the
// programs that we will execute. It appears that GCC sets these
// Run the compiler to assembly and link together the program.
if (Verbose) dumpArgs(&args[0]);
- int Res = sys::Program::ExecuteAndWait(gcc, &args[0],(const char**)clean_env);
+ int Res = sys::Program::ExecuteAndWait(
+ gcc, &args[0],(const char**)clean_env,0,0,&ErrMsg);
delete [] clean_env;
// Generate an assembly language file for the bytecode.
if (Verbose) std::cout << "Generating Assembly Code\n";
- GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput, llc,
- Verbose);
+ std::string ErrMsg;
+ if (0 != GenerateAssembly(
+ AssemblyFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
+ std::cerr << argv[0] << ": " << ErrMsg << "\n";
+ return 2;
+ }
if (Verbose) std::cout << "Generating Native Code\n";
- GenerateNative(OutputFilename, AssemblyFile.toString(),
+ if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
LibPaths, Libraries, gcc, envp, LinkAsLibrary,
- NoInternalize, RPath, SOName, Verbose);
+ NoInternalize, RPath, SOName, ErrMsg, Verbose) ) {
+ std::cerr << argv[0] << ": " << ErrMsg << "\n";
+ return 2;
+ }
if (!SaveTemps) {
// Remove the assembly language file.
// Generate an assembly language file for the bytecode.
if (Verbose) std::cout << "Generating C Source Code\n";
- GenerateCFile(CFile.toString(), RealBytecodeOutput, llc, Verbose);
+ std::string ErrMsg;
+ if (0 != GenerateCFile(
+ CFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
+ std::cerr << argv[0] << ": " << ErrMsg << "\n";
+ return 2;
+ }
if (Verbose) std::cout << "Generating Native Code\n";
- GenerateNative(OutputFilename, CFile.toString(),
+ if (0 != GenerateNative(OutputFilename, CFile.toString(),
LibPaths, Libraries, gcc, envp, LinkAsLibrary,
- NoInternalize, RPath, SOName, Verbose);
+ NoInternalize, RPath, SOName, ErrMsg, Verbose)) {
+ std::cerr << argv[0] << ": " << ErrMsg << "\n";
+ return 2;
+ }
if (!SaveTemps) {
// Remove the assembly language file.
GenerateAssembly (const std::string &OutputFilename,
const std::string &InputFilename,
const sys::Path &llc,
+ std::string& ErrMsg,
bool Verbose=false);
int
GenerateCFile (const std::string &OutputFile,
const std::string &InputFile,
const sys::Path &llc,
+ std::string& ErrMsg,
bool Verbose=false);
int
GenerateNative (const std::string &OutputFilename,
bool ExportAllAsDynamic,
const std::vector<std::string> &RPath,
const std::string &SOName,
+ std::string& ErrMsg,
bool Verbose=false);
} // End llvm namespace
///
static int GenerateAssembly(const std::string &OutputFilename,
const std::string &InputFilename,
- const sys::Path &llc) {
+ const sys::Path &llc,
+ std::string &ErrMsg ) {
// Run LLC to convert the bytecode file into assembly code.
std::vector<const char*> args;
args.push_back(llc.c_str());
args.push_back(InputFilename.c_str());
args.push_back(0);
- return sys::Program::ExecuteAndWait(llc,&args[0]);
+ return sys::Program::ExecuteAndWait(llc,&args[0],0,0,0,&ErrMsg);
}
/// GenerateCFile - generates a C source file from the specified bytecode file.
static int GenerateCFile(const std::string &OutputFile,
const std::string &InputFile,
- const sys::Path &llc) {
+ const sys::Path &llc,
+ std::string& ErrMsg) {
// Run LLC to convert the bytecode file into C.
std::vector<const char*> args;
args.push_back(llc.c_str());
args.push_back(OutputFile.c_str());
args.push_back(InputFile.c_str());
args.push_back(0);
- return sys::Program::ExecuteAndWait(llc, &args[0]);
+ return sys::Program::ExecuteAndWait(llc, &args[0],0,0,0,&ErrMsg);
}
/// GenerateNative - generates a native object file from the
static int GenerateNative(const std::string &OutputFilename,
const std::string &InputFilename,
const std::vector<std::string> &Libraries,
- const sys::Path &gcc, char ** const envp) {
+ const sys::Path &gcc, char ** const envp,
+ std::string& ErrMsg) {
// Remove these environment variables from the environment of the
// programs that we will execute. It appears that GCC sets these
// environment variables so that the programs it uses can configure
args.push_back(0);
// Run the compiler to assembly and link together the program.
- int R = sys::Program::ExecuteAndWait(gcc, &args[0], (const char**)clean_env);
+ int R = sys::Program::ExecuteAndWait(
+ gcc, &args[0], (const char**)clean_env,0,0,&ErrMsg);
delete [] clean_env;
return R;
}
args[1] = RealBytecodeOutput.c_str();
args[2] = tmp_output.c_str();
args[3] = 0;
- if (0 == sys::Program::ExecuteAndWait(prog, args)) {
+ std::string ErrMsg;
+ if (0 == sys::Program::ExecuteAndWait(prog, args, 0,0,0, &ErrMsg)) {
if (tmp_output.isBytecodeFile()) {
sys::Path target(RealBytecodeOutput);
target.eraseFromDisk();
} else
return PrintAndReturn(
"Post-link optimization output is not bytecode");
+ } else {
+ std::cerr << argv[0] << ": " << ErrMsg << "\n";
+ return 2;
}
}
}
// Generate an assembly language file for the bytecode.
if (Verbose) std::cout << "Generating Assembly Code\n";
- GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput, llc);
+ std::string ErrMsg;
+ if (0 != GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput,
+ llc, ErrMsg)) {
+ std::cerr << argv[0] << ": " << ErrMsg << "\n";
+ return 1;
+ }
+
if (Verbose) std::cout << "Generating Native Code\n";
- GenerateNative(OutputFilename, AssemblyFile.toString(), Libraries,
- gcc, envp);
+ if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
+ Libraries,gcc,envp,ErrMsg)) {
+ std::cerr << argv[0] << ": " << ErrMsg << "\n";
+ return 1;
+ }
// Remove the assembly language file.
AssemblyFile.eraseFromDisk();
// Generate an assembly language file for the bytecode.
if (Verbose) std::cout << "Generating Assembly Code\n";
- GenerateCFile(CFile.toString(), RealBytecodeOutput, llc);
+ std::string ErrMsg;
+ if (0 != GenerateCFile(
+ CFile.toString(), RealBytecodeOutput, llc, ErrMsg)) {
+ std::cerr << argv[0] << ": " << ErrMsg << "\n";
+ return 1;
+ }
+
if (Verbose) std::cout << "Generating Native Code\n";
- GenerateNative(OutputFilename, CFile.toString(), Libraries, gcc, envp);
+ if (0 != GenerateNative(OutputFilename, CFile.toString(), Libraries,
+ gcc, envp, ErrMsg)) {
+ std::cerr << argv[0] << ": " << ErrMsg << "\n";
+ return 1;
+ }
// Remove the assembly language file.
CFile.eraseFromDisk();
return action;
}
- bool DoAction(Action*action) {
+ int DoAction(Action*action, std::string& ErrMsg) {
assert(action != 0 && "Invalid Action!");
if (isSet(VERBOSE_FLAG))
WriteAction(action);
if (isSet(TIME_ACTIONS_FLAG)) {
Timer timer(action->program.toString());
timer.startTimer();
- int resultCode = sys::Program::ExecuteAndWait(action->program, Args);
+ int resultCode =
+ sys::Program::ExecuteAndWait(action->program, Args,0,0,0,&ErrMsg);
timer.stopTimer();
timer.print(timer,std::cerr);
- return resultCode == 0;
+ return resultCode;
}
else
- return 0 == sys::Program::ExecuteAndWait(action->program, Args);
+ return
+ sys::Program::ExecuteAndWait(action->program, Args, 0,0,0, &ErrMsg);
}
- return true;
+ return 0;
}
/// This method tries various variants of a linkage item's file
/// @name Methods
/// @{
public:
- virtual int execute(const InputList& InpList, const sys::Path& Output ) {
+ virtual int execute(const InputList& InpList, const sys::Path& Output, std::string& ErrMsg ) {
try {
// Echo the configuration of options if we're running verbose
if (isSet(DEBUG_FLAG)) {
std::vector<Action*>::iterator AI = actions.begin();
std::vector<Action*>::iterator AE = actions.end();
while (AI != AE) {
- if (!DoAction(*AI))
- throw std::string("Action failed");
+ int ActionResult = DoAction(*AI, ErrMsg);
+ if (ActionResult != 0)
+ return ActionResult;
AI++;
}
link->args.push_back(Output.toString());
// Execute the link
- if (!DoAction(link))
- throw std::string("Action failed");
+ int ActionResult = DoAction(link, ErrMsg);
+ if (ActionResult != 0)
+ return ActionResult;
}
} catch (std::string& msg) {
cleanup();
/// @{
public:
/// @brief Execute the actions requested for the given input list.
- virtual int execute(const InputList& list, const sys::Path& output) = 0;
+ virtual int execute(
+ const InputList& list, const sys::Path& output, std::string& ErrMsg) =0;
/// @brief Set the final phase at which compilation terminates
virtual void setFinalPhase(Phases phase) = 0;
}
// Tell the driver to do its thing
- int result = CD->execute(InpList, sys::Path(OutputFilename));
+ std::string ErrMsg;
+ int result = CD->execute(InpList, sys::Path(OutputFilename), ErrMsg);
if (result != 0) {
- throw std::string("Error executing actions. Terminated.");
+ std::cerr << argv[0] << ": " << ErrMsg << '\n';
return result;
}