2003-09-30 18:28:53 +00:00
|
|
|
//===-- Support/ToolRunner.h ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2003-10-14 21:34:11 +00:00
|
|
|
// This file exposes an abstraction around a platform C compiler, used to
|
|
|
|
// compile C and assembly code. It also exposes an "AbstractIntepreter"
|
|
|
|
// interface, which is used to execute code using one of the LLVM execution
|
|
|
|
// engines.
|
2003-09-30 18:28:53 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-09-29 22:38:57 +00:00
|
|
|
#ifndef TOOLRUNNER_H
|
|
|
|
#define TOOLRUNNER_H
|
|
|
|
|
|
|
|
#include "Support/SystemUtils.h"
|
|
|
|
#include <vector>
|
|
|
|
|
2003-10-14 21:34:11 +00:00
|
|
|
class CBE;
|
|
|
|
class LLC;
|
2003-09-29 22:38:57 +00:00
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// GCC abstraction
|
|
|
|
//
|
|
|
|
class GCC {
|
|
|
|
std::string GCCPath; // The path to the gcc executable
|
|
|
|
GCC(const std::string &gccPath) : GCCPath(gccPath) { }
|
2003-10-14 21:34:11 +00:00
|
|
|
public:
|
|
|
|
enum FileType { AsmFile, CFile };
|
|
|
|
|
|
|
|
static GCC* create(const std::string &ProgramPath, std::string &Message);
|
2003-09-29 22:38:57 +00:00
|
|
|
|
2003-10-14 21:34:11 +00:00
|
|
|
|
|
|
|
int ExecuteProgram(const std::string &ProgramFile,
|
|
|
|
const std::vector<std::string> &Args,
|
|
|
|
FileType fileType,
|
|
|
|
const std::string &InputFile,
|
|
|
|
const std::string &OutputFile,
|
|
|
|
const std::string &SharedLib = "");
|
2003-09-29 22:38:57 +00:00
|
|
|
|
|
|
|
int MakeSharedObject(const std::string &InputFile,
|
|
|
|
FileType fileType,
|
|
|
|
std::string &OutputFile);
|
|
|
|
|
|
|
|
void ProcessFailure(const char **Args);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-10-14 21:34:11 +00:00
|
|
|
//===---------------------------------------------------------------------===//
|
2003-09-29 22:38:57 +00:00
|
|
|
/// AbstractInterpreter Class - Subclasses of this class are used to execute
|
|
|
|
/// LLVM bytecode in a variety of ways. This abstract interface hides this
|
|
|
|
/// complexity behind a simple interface.
|
|
|
|
///
|
|
|
|
struct AbstractInterpreter {
|
2003-10-14 21:34:11 +00:00
|
|
|
static CBE* createCBE(const std::string &ProgramPath, std::string &Message);
|
|
|
|
static LLC *createLLC(const std::string &ProgramPath, std::string &Message);
|
|
|
|
|
|
|
|
static AbstractInterpreter* createLLI(const std::string &ProgramPath,
|
|
|
|
std::string &Message);
|
|
|
|
|
|
|
|
static AbstractInterpreter* createJIT(const std::string &ProgramPath,
|
|
|
|
std::string &Message);
|
|
|
|
|
2003-09-29 22:38:57 +00:00
|
|
|
|
|
|
|
virtual ~AbstractInterpreter() {}
|
|
|
|
|
|
|
|
/// ExecuteProgram - Run the specified bytecode file, emitting output to the
|
|
|
|
/// specified filename. This returns the exit code of the program.
|
|
|
|
///
|
|
|
|
virtual int ExecuteProgram(const std::string &Bytecode,
|
2003-10-14 21:34:11 +00:00
|
|
|
const std::vector<std::string> &Args,
|
2003-09-29 22:38:57 +00:00
|
|
|
const std::string &InputFile,
|
|
|
|
const std::string &OutputFile,
|
|
|
|
const std::string &SharedLib = "") = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// CBE Implementation of AbstractIntepreter interface
|
|
|
|
//
|
|
|
|
class CBE : public AbstractInterpreter {
|
|
|
|
std::string DISPath; // The path to the `llvm-dis' executable
|
|
|
|
GCC *gcc;
|
|
|
|
public:
|
|
|
|
CBE(const std::string &disPath, GCC *Gcc) : DISPath(disPath), gcc(Gcc) { }
|
|
|
|
~CBE() { delete gcc; }
|
|
|
|
|
|
|
|
virtual int ExecuteProgram(const std::string &Bytecode,
|
2003-10-14 21:34:11 +00:00
|
|
|
const std::vector<std::string> &Args,
|
2003-09-29 22:38:57 +00:00
|
|
|
const std::string &InputFile,
|
|
|
|
const std::string &OutputFile,
|
|
|
|
const std::string &SharedLib = "");
|
|
|
|
|
2003-10-14 21:34:11 +00:00
|
|
|
// Sometimes we just want to go half-way and only generate the .c file,
|
|
|
|
// not necessarily compile it with GCC and run the program.
|
|
|
|
//
|
|
|
|
virtual int OutputC(const std::string &Bytecode, std::string &OutputCFile);
|
2003-09-29 22:38:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// LLC Implementation of AbstractIntepreter interface
|
|
|
|
//
|
|
|
|
class LLC : public AbstractInterpreter {
|
|
|
|
std::string LLCPath; // The path to the LLC executable
|
|
|
|
GCC *gcc;
|
|
|
|
public:
|
|
|
|
LLC(const std::string &llcPath, GCC *Gcc)
|
|
|
|
: LLCPath(llcPath), gcc(Gcc) { }
|
|
|
|
~LLC() { delete gcc; }
|
|
|
|
|
|
|
|
virtual int ExecuteProgram(const std::string &Bytecode,
|
2003-10-14 21:34:11 +00:00
|
|
|
const std::vector<std::string> &Args,
|
2003-09-29 22:38:57 +00:00
|
|
|
const std::string &InputFile,
|
|
|
|
const std::string &OutputFile,
|
|
|
|
const std::string &SharedLib = "");
|
|
|
|
|
2003-10-14 21:34:11 +00:00
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
int OutputAsm(const std::string &Bytecode, std::string &OutputAsmFile);
|
2003-09-29 22:38:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|