#define TOOLRUNNER_H
#include "Support/SystemUtils.h"
+#include <exception>
#include <vector>
namespace llvm {
/// AbstractInterpreter instances if there is an error running a tool (e.g., LLC
/// crashes) which prevents execution of the program.
///
-class ToolExecutionError {
+class ToolExecutionError : std::exception {
std::string Message;
public:
- ToolExecutionError(const std::string &M) : Message(M) {}
- const std::string getMessage() const { return Message; }
+ explicit ToolExecutionError(const std::string &M) : Message(M) {}
+ virtual ~ToolExecutionError() throw();
+ virtual const char* what() const throw() { return Message.c_str(); }
};
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &SharedLibs =
- std::vector<std::string>());
+ std::vector<std::string>(), unsigned Timeout = 0);
/// MakeSharedObject - This compiles the specified file (which is either a .c
/// file or a .s file) into a shared object.
/// complexity behind a simple interface.
///
struct AbstractInterpreter {
- static CBE* createCBE(const std::string &ProgramPath, std::string &Message);
- static LLC *createLLC(const std::string &ProgramPath, std::string &Message);
+ static CBE *createCBE(const std::string &ProgramPath, std::string &Message,
+ const std::vector<std::string> *Args = 0);
+ static LLC *createLLC(const std::string &ProgramPath, std::string &Message,
+ const std::vector<std::string> *Args = 0);
static AbstractInterpreter* createLLI(const std::string &ProgramPath,
- std::string &Message);
+ std::string &Message,
+ const std::vector<std::string> *Args=0);
static AbstractInterpreter* createJIT(const std::string &ProgramPath,
- std::string &Message);
+ std::string &Message,
+ const std::vector<std::string> *Args=0);
virtual ~AbstractInterpreter() {}
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &SharedLibs =
- std::vector<std::string>()) = 0;
+ std::vector<std::string>(),
+ unsigned Timeout = 0) = 0;
};
//===---------------------------------------------------------------------===//
//
class CBE : public AbstractInterpreter {
std::string LLCPath; // The path to the `llc' executable
+ std::vector<std::string> ToolArgs; // Extra args to pass to LLC
GCC *gcc;
public:
- CBE(const std::string &llcPath, GCC *Gcc) : LLCPath(llcPath), gcc(Gcc) { }
+ CBE(const std::string &llcPath, GCC *Gcc,
+ const std::vector<std::string> *Args) : LLCPath(llcPath), gcc(Gcc) {
+ ToolArgs.clear ();
+ if (Args) { ToolArgs = *Args; }
+ }
~CBE() { delete gcc; }
/// compileProgram - Compile the specified program from bytecode to executable
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &SharedLibs =
- std::vector<std::string>());
+ std::vector<std::string>(),
+ unsigned Timeout = 0);
// Sometimes we just want to go half-way and only generate the .c file, not
// necessarily compile it with GCC and run the program. This throws an
//
class LLC : public AbstractInterpreter {
std::string LLCPath; // The path to the LLC executable
+ std::vector<std::string> ToolArgs; // Extra args to pass to LLC
GCC *gcc;
public:
- LLC(const std::string &llcPath, GCC *Gcc)
- : LLCPath(llcPath), gcc(Gcc) { }
+ LLC(const std::string &llcPath, GCC *Gcc,
+ const std::vector<std::string> *Args) : LLCPath(llcPath), gcc(Gcc) {
+ ToolArgs.clear ();
+ if (Args) { ToolArgs = *Args; }
+ }
~LLC() { delete gcc; }
-
/// compileProgram - Compile the specified program from bytecode to executable
/// code. This does not produce any output, it is only used when debugging
/// the code generator. If the code generator fails, an exception should be
const std::string &InputFile,
const std::string &OutputFile,
const std::vector<std::string> &SharedLibs =
- std::vector<std::string>());
+ std::vector<std::string>(),
+ unsigned Timeout = 0);
// Sometimes we just want to go half-way and only generate the .s file,
// not necessarily compile it all the way and run the program. This throws