mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-06 04:31:08 +00:00
If there is an error running a tool, include the error message (e.g. assertion failure) in the exception
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11597 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e9f66b9741
commit
89bf9ea65e
@ -18,8 +18,34 @@
|
|||||||
#include "Support/FileUtilities.h"
|
#include "Support/FileUtilities.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
static void ProcessFailure(std::string ProgPath, const char** Args) {
|
||||||
|
std::ostringstream OS;
|
||||||
|
OS << "\n*** Error running tool:\n";
|
||||||
|
for (const char **Arg = Args; *Arg; ++Arg)
|
||||||
|
OS << " " << *Arg;
|
||||||
|
OS << "\n";
|
||||||
|
|
||||||
|
// Rerun the compiler, capturing any error messages to print them.
|
||||||
|
std::string ErrorFilename = getUniqueFilename("error_messages");
|
||||||
|
RunProgramWithTimeout(ProgPath, Args, "/dev/null", ErrorFilename.c_str(),
|
||||||
|
ErrorFilename.c_str());
|
||||||
|
|
||||||
|
// Print out the error messages generated by GCC if possible...
|
||||||
|
std::ifstream ErrorFile(ErrorFilename.c_str());
|
||||||
|
if (ErrorFile) {
|
||||||
|
std::copy(std::istreambuf_iterator<char>(ErrorFile),
|
||||||
|
std::istreambuf_iterator<char>(),
|
||||||
|
std::ostreambuf_iterator<char>(OS));
|
||||||
|
ErrorFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
removeFile(ErrorFilename);
|
||||||
|
throw ToolExecutionError(OS.str());
|
||||||
|
}
|
||||||
|
|
||||||
//===---------------------------------------------------------------------===//
|
//===---------------------------------------------------------------------===//
|
||||||
// LLI Implementation of AbstractIntepreter interface
|
// LLI Implementation of AbstractIntepreter interface
|
||||||
//
|
//
|
||||||
@ -97,7 +123,7 @@ void LLC::OutputAsm(const std::string &Bytecode, std::string &OutputAsmFile) {
|
|||||||
std::cout << "<llc>" << std::flush;
|
std::cout << "<llc>" << std::flush;
|
||||||
if (RunProgramWithTimeout(LLCPath, LLCArgs, "/dev/null", "/dev/null",
|
if (RunProgramWithTimeout(LLCPath, LLCArgs, "/dev/null", "/dev/null",
|
||||||
"/dev/null"))
|
"/dev/null"))
|
||||||
throw ToolExecutionError("LLC failed to compile the program.");
|
ProcessFailure(LLCPath, LLCArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LLC::ExecuteProgram(const std::string &Bytecode,
|
int LLC::ExecuteProgram(const std::string &Bytecode,
|
||||||
@ -202,7 +228,7 @@ AbstractInterpreter *AbstractInterpreter::createJIT(const std::string &ProgPath,
|
|||||||
void CBE::OutputC(const std::string &Bytecode,
|
void CBE::OutputC(const std::string &Bytecode,
|
||||||
std::string &OutputCFile) {
|
std::string &OutputCFile) {
|
||||||
OutputCFile = getUniqueFilename(Bytecode+".cbe.c");
|
OutputCFile = getUniqueFilename(Bytecode+".cbe.c");
|
||||||
const char *DisArgs[] = {
|
const char *LLCArgs[] = {
|
||||||
LLCPath.c_str(),
|
LLCPath.c_str(),
|
||||||
"-o", OutputCFile.c_str(), // Output to the C file
|
"-o", OutputCFile.c_str(), // Output to the C file
|
||||||
"-march=c", // Output to C
|
"-march=c", // Output to C
|
||||||
@ -212,9 +238,9 @@ void CBE::OutputC(const std::string &Bytecode,
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::cout << "<cbe>" << std::flush;
|
std::cout << "<cbe>" << std::flush;
|
||||||
if (RunProgramWithTimeout(LLCPath, DisArgs, "/dev/null", "/dev/null",
|
if (RunProgramWithTimeout(LLCPath, LLCArgs, "/dev/null", "/dev/null",
|
||||||
"/dev/null"))
|
"/dev/null"))
|
||||||
throw ToolExecutionError("llc -march=c failed!");
|
ProcessFailure(LLCPath, LLCArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CBE::ExecuteProgram(const std::string &Bytecode,
|
int CBE::ExecuteProgram(const std::string &Bytecode,
|
||||||
@ -290,7 +316,7 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
|
|||||||
std::cout << "<gcc>" << std::flush;
|
std::cout << "<gcc>" << std::flush;
|
||||||
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], "/dev/null", "/dev/null",
|
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], "/dev/null", "/dev/null",
|
||||||
"/dev/null")) {
|
"/dev/null")) {
|
||||||
ProcessFailure(&GCCArgs[0]);
|
ProcessFailure(GCCPath, &GCCArgs[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,36 +362,12 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|||||||
std::cout << "<gcc>" << std::flush;
|
std::cout << "<gcc>" << std::flush;
|
||||||
if (RunProgramWithTimeout(GCCPath, GCCArgs, "/dev/null", "/dev/null",
|
if (RunProgramWithTimeout(GCCPath, GCCArgs, "/dev/null", "/dev/null",
|
||||||
"/dev/null")) {
|
"/dev/null")) {
|
||||||
ProcessFailure(GCCArgs);
|
ProcessFailure(GCCPath, GCCArgs);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCC::ProcessFailure(const char** GCCArgs) {
|
|
||||||
std::cerr << "\n*** Error: program invocation!\n";
|
|
||||||
for (const char **Arg = GCCArgs; *Arg; ++Arg)
|
|
||||||
std::cerr << " " << *Arg;
|
|
||||||
std::cerr << "\n";
|
|
||||||
|
|
||||||
// Rerun the compiler, capturing any error messages to print them.
|
|
||||||
std::string ErrorFilename = getUniqueFilename("gcc.errors");
|
|
||||||
RunProgramWithTimeout(GCCPath, GCCArgs, "/dev/null", ErrorFilename.c_str(),
|
|
||||||
ErrorFilename.c_str());
|
|
||||||
|
|
||||||
// Print out the error messages generated by GCC if possible...
|
|
||||||
std::ifstream ErrorFile(ErrorFilename.c_str());
|
|
||||||
if (ErrorFile) {
|
|
||||||
std::copy(std::istreambuf_iterator<char>(ErrorFile),
|
|
||||||
std::istreambuf_iterator<char>(),
|
|
||||||
std::ostreambuf_iterator<char>(std::cerr));
|
|
||||||
ErrorFile.close();
|
|
||||||
std::cerr << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
removeFile(ErrorFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// create - Try to find the `gcc' executable
|
/// create - Try to find the `gcc' executable
|
||||||
///
|
///
|
||||||
GCC *GCC::create(const std::string &ProgramPath, std::string &Message) {
|
GCC *GCC::create(const std::string &ProgramPath, std::string &Message) {
|
||||||
|
@ -18,8 +18,34 @@
|
|||||||
#include "Support/FileUtilities.h"
|
#include "Support/FileUtilities.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
static void ProcessFailure(std::string ProgPath, const char** Args) {
|
||||||
|
std::ostringstream OS;
|
||||||
|
OS << "\n*** Error running tool:\n";
|
||||||
|
for (const char **Arg = Args; *Arg; ++Arg)
|
||||||
|
OS << " " << *Arg;
|
||||||
|
OS << "\n";
|
||||||
|
|
||||||
|
// Rerun the compiler, capturing any error messages to print them.
|
||||||
|
std::string ErrorFilename = getUniqueFilename("error_messages");
|
||||||
|
RunProgramWithTimeout(ProgPath, Args, "/dev/null", ErrorFilename.c_str(),
|
||||||
|
ErrorFilename.c_str());
|
||||||
|
|
||||||
|
// Print out the error messages generated by GCC if possible...
|
||||||
|
std::ifstream ErrorFile(ErrorFilename.c_str());
|
||||||
|
if (ErrorFile) {
|
||||||
|
std::copy(std::istreambuf_iterator<char>(ErrorFile),
|
||||||
|
std::istreambuf_iterator<char>(),
|
||||||
|
std::ostreambuf_iterator<char>(OS));
|
||||||
|
ErrorFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
removeFile(ErrorFilename);
|
||||||
|
throw ToolExecutionError(OS.str());
|
||||||
|
}
|
||||||
|
|
||||||
//===---------------------------------------------------------------------===//
|
//===---------------------------------------------------------------------===//
|
||||||
// LLI Implementation of AbstractIntepreter interface
|
// LLI Implementation of AbstractIntepreter interface
|
||||||
//
|
//
|
||||||
@ -97,7 +123,7 @@ void LLC::OutputAsm(const std::string &Bytecode, std::string &OutputAsmFile) {
|
|||||||
std::cout << "<llc>" << std::flush;
|
std::cout << "<llc>" << std::flush;
|
||||||
if (RunProgramWithTimeout(LLCPath, LLCArgs, "/dev/null", "/dev/null",
|
if (RunProgramWithTimeout(LLCPath, LLCArgs, "/dev/null", "/dev/null",
|
||||||
"/dev/null"))
|
"/dev/null"))
|
||||||
throw ToolExecutionError("LLC failed to compile the program.");
|
ProcessFailure(LLCPath, LLCArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LLC::ExecuteProgram(const std::string &Bytecode,
|
int LLC::ExecuteProgram(const std::string &Bytecode,
|
||||||
@ -202,7 +228,7 @@ AbstractInterpreter *AbstractInterpreter::createJIT(const std::string &ProgPath,
|
|||||||
void CBE::OutputC(const std::string &Bytecode,
|
void CBE::OutputC(const std::string &Bytecode,
|
||||||
std::string &OutputCFile) {
|
std::string &OutputCFile) {
|
||||||
OutputCFile = getUniqueFilename(Bytecode+".cbe.c");
|
OutputCFile = getUniqueFilename(Bytecode+".cbe.c");
|
||||||
const char *DisArgs[] = {
|
const char *LLCArgs[] = {
|
||||||
LLCPath.c_str(),
|
LLCPath.c_str(),
|
||||||
"-o", OutputCFile.c_str(), // Output to the C file
|
"-o", OutputCFile.c_str(), // Output to the C file
|
||||||
"-march=c", // Output to C
|
"-march=c", // Output to C
|
||||||
@ -212,9 +238,9 @@ void CBE::OutputC(const std::string &Bytecode,
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::cout << "<cbe>" << std::flush;
|
std::cout << "<cbe>" << std::flush;
|
||||||
if (RunProgramWithTimeout(LLCPath, DisArgs, "/dev/null", "/dev/null",
|
if (RunProgramWithTimeout(LLCPath, LLCArgs, "/dev/null", "/dev/null",
|
||||||
"/dev/null"))
|
"/dev/null"))
|
||||||
throw ToolExecutionError("llc -march=c failed!");
|
ProcessFailure(LLCPath, LLCArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CBE::ExecuteProgram(const std::string &Bytecode,
|
int CBE::ExecuteProgram(const std::string &Bytecode,
|
||||||
@ -290,7 +316,7 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
|
|||||||
std::cout << "<gcc>" << std::flush;
|
std::cout << "<gcc>" << std::flush;
|
||||||
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], "/dev/null", "/dev/null",
|
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], "/dev/null", "/dev/null",
|
||||||
"/dev/null")) {
|
"/dev/null")) {
|
||||||
ProcessFailure(&GCCArgs[0]);
|
ProcessFailure(GCCPath, &GCCArgs[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,36 +362,12 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|||||||
std::cout << "<gcc>" << std::flush;
|
std::cout << "<gcc>" << std::flush;
|
||||||
if (RunProgramWithTimeout(GCCPath, GCCArgs, "/dev/null", "/dev/null",
|
if (RunProgramWithTimeout(GCCPath, GCCArgs, "/dev/null", "/dev/null",
|
||||||
"/dev/null")) {
|
"/dev/null")) {
|
||||||
ProcessFailure(GCCArgs);
|
ProcessFailure(GCCPath, GCCArgs);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCC::ProcessFailure(const char** GCCArgs) {
|
|
||||||
std::cerr << "\n*** Error: program invocation!\n";
|
|
||||||
for (const char **Arg = GCCArgs; *Arg; ++Arg)
|
|
||||||
std::cerr << " " << *Arg;
|
|
||||||
std::cerr << "\n";
|
|
||||||
|
|
||||||
// Rerun the compiler, capturing any error messages to print them.
|
|
||||||
std::string ErrorFilename = getUniqueFilename("gcc.errors");
|
|
||||||
RunProgramWithTimeout(GCCPath, GCCArgs, "/dev/null", ErrorFilename.c_str(),
|
|
||||||
ErrorFilename.c_str());
|
|
||||||
|
|
||||||
// Print out the error messages generated by GCC if possible...
|
|
||||||
std::ifstream ErrorFile(ErrorFilename.c_str());
|
|
||||||
if (ErrorFile) {
|
|
||||||
std::copy(std::istreambuf_iterator<char>(ErrorFile),
|
|
||||||
std::istreambuf_iterator<char>(),
|
|
||||||
std::ostreambuf_iterator<char>(std::cerr));
|
|
||||||
ErrorFile.close();
|
|
||||||
std::cerr << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
removeFile(ErrorFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// create - Try to find the `gcc' executable
|
/// create - Try to find the `gcc' executable
|
||||||
///
|
///
|
||||||
GCC *GCC::create(const std::string &ProgramPath, std::string &Message) {
|
GCC *GCC::create(const std::string &ProgramPath, std::string &Message) {
|
||||||
|
Loading…
Reference in New Issue
Block a user