2006-06-06 22:30:59 +00:00
|
|
|
//===-- tools/bugpoint/ToolRunner.h -----------------------------*- C++ -*-===//
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-09-30 18:28:53 +00:00
|
|
|
//
|
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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-06-06 22:30:59 +00:00
|
|
|
#ifndef BUGPOINT_TOOLRUNNER_H
|
|
|
|
#define BUGPOINT_TOOLRUNNER_H
|
2003-09-29 22:38:57 +00:00
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/SystemUtils.h"
|
2004-02-19 07:39:26 +00:00
|
|
|
#include <exception>
|
2003-09-29 22:38:57 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2003-10-14 21:34:11 +00:00
|
|
|
class CBE;
|
|
|
|
class LLC;
|
2003-09-29 22:38:57 +00:00
|
|
|
|
2004-02-18 20:21:57 +00:00
|
|
|
/// ToolExecutionError - An instance of this class is thrown by the
|
|
|
|
/// AbstractInterpreter instances if there is an error running a tool (e.g., LLC
|
|
|
|
/// crashes) which prevents execution of the program.
|
|
|
|
///
|
2004-02-19 07:39:26 +00:00
|
|
|
class ToolExecutionError : std::exception {
|
2004-02-18 20:21:57 +00:00
|
|
|
std::string Message;
|
|
|
|
public:
|
2004-02-19 07:39:26 +00:00
|
|
|
explicit ToolExecutionError(const std::string &M) : Message(M) {}
|
|
|
|
virtual ~ToolExecutionError() throw();
|
|
|
|
virtual const char* what() const throw() { return Message.c_str(); }
|
2004-02-18 20:21:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-09-29 22:38:57 +00:00
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// GCC abstraction
|
|
|
|
//
|
|
|
|
class GCC {
|
2004-12-19 17:59:45 +00:00
|
|
|
sys::Path GCCPath; // The path to the gcc executable
|
|
|
|
GCC(const sys::Path &gccPath) : GCCPath(gccPath) { }
|
2003-10-14 21:34:11 +00:00
|
|
|
public:
|
|
|
|
enum FileType { AsmFile, CFile };
|
|
|
|
|
2006-06-27 20:35:36 +00:00
|
|
|
static GCC *create(const std::string &ProgramPath, std::string &Message);
|
2003-09-29 22:38:57 +00:00
|
|
|
|
2003-10-14 21:52:52 +00:00
|
|
|
/// ExecuteProgram - Execute the program specified by "ProgramFile" (which is
|
|
|
|
/// either a .s file, or a .c file, specified by FileType), with the specified
|
|
|
|
/// arguments. Standard input is specified with InputFile, and standard
|
|
|
|
/// Output is captured to the specified OutputFile location. The SharedLibs
|
|
|
|
/// option specifies optional native shared objects that can be loaded into
|
|
|
|
/// the program for execution.
|
|
|
|
///
|
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,
|
2006-06-06 00:00:42 +00:00
|
|
|
const std::vector<std::string> &GCCArgs =
|
|
|
|
std::vector<std::string>(),
|
|
|
|
unsigned Timeout = 0);
|
2003-09-29 22:38:57 +00:00
|
|
|
|
2003-10-14 21:52:52 +00:00
|
|
|
/// MakeSharedObject - This compiles the specified file (which is either a .c
|
|
|
|
/// file or a .s file) into a shared object.
|
|
|
|
///
|
|
|
|
int MakeSharedObject(const std::string &InputFile, FileType fileType,
|
2006-06-27 20:35:36 +00:00
|
|
|
std::string &OutputFile,
|
|
|
|
const std::vector<std::string> &ArgsForGCC);
|
2003-09-29 22:38:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
///
|
2005-01-22 16:30:58 +00:00
|
|
|
class AbstractInterpreter {
|
|
|
|
public:
|
2004-05-04 21:09:01 +00:00
|
|
|
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);
|
2003-10-14 21:34:11 +00:00
|
|
|
|
|
|
|
static AbstractInterpreter* createLLI(const std::string &ProgramPath,
|
2004-05-04 21:09:01 +00:00
|
|
|
std::string &Message,
|
|
|
|
const std::vector<std::string> *Args=0);
|
2003-10-14 21:34:11 +00:00
|
|
|
|
|
|
|
static AbstractInterpreter* createJIT(const std::string &ProgramPath,
|
2004-05-04 21:09:01 +00:00
|
|
|
std::string &Message,
|
|
|
|
const std::vector<std::string> *Args=0);
|
2003-10-14 21:34:11 +00:00
|
|
|
|
2003-09-29 22:38:57 +00:00
|
|
|
|
|
|
|
virtual ~AbstractInterpreter() {}
|
|
|
|
|
2004-02-18 23:24:29 +00:00
|
|
|
/// 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
|
|
|
|
/// thrown, otherwise, this function will just return.
|
|
|
|
virtual void compileProgram(const std::string &Bytecode) {}
|
|
|
|
|
2003-09-29 22:38:57 +00:00
|
|
|
/// 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,
|
2006-06-06 00:00:42 +00:00
|
|
|
const std::vector<std::string> &GCCArgs =
|
|
|
|
std::vector<std::string>(),
|
2005-04-21 20:48:15 +00:00
|
|
|
const std::vector<std::string> &SharedLibs =
|
2004-07-24 07:48:50 +00:00
|
|
|
std::vector<std::string>(),
|
|
|
|
unsigned Timeout = 0) = 0;
|
2003-09-29 22:38:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// CBE Implementation of AbstractIntepreter interface
|
|
|
|
//
|
|
|
|
class CBE : public AbstractInterpreter {
|
2004-12-19 17:59:45 +00:00
|
|
|
sys::Path LLCPath; // The path to the `llc' executable
|
2004-05-04 21:09:01 +00:00
|
|
|
std::vector<std::string> ToolArgs; // Extra args to pass to LLC
|
2003-09-29 22:38:57 +00:00
|
|
|
GCC *gcc;
|
|
|
|
public:
|
2004-12-19 17:59:45 +00:00
|
|
|
CBE(const sys::Path &llcPath, GCC *Gcc,
|
2004-05-04 21:09:01 +00:00
|
|
|
const std::vector<std::string> *Args) : LLCPath(llcPath), gcc(Gcc) {
|
|
|
|
ToolArgs.clear ();
|
2004-05-04 22:02:41 +00:00
|
|
|
if (Args) { ToolArgs = *Args; }
|
2004-05-04 21:09:01 +00:00
|
|
|
}
|
2003-09-29 22:38:57 +00:00
|
|
|
~CBE() { delete gcc; }
|
|
|
|
|
2004-02-18 23:24:29 +00:00
|
|
|
/// 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
|
|
|
|
/// thrown, otherwise, this function will just return.
|
|
|
|
virtual void compileProgram(const std::string &Bytecode);
|
|
|
|
|
2003-09-29 22:38:57 +00:00
|
|
|
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,
|
2006-06-06 00:00:42 +00:00
|
|
|
const std::vector<std::string> &GCCArgs =
|
|
|
|
std::vector<std::string>(),
|
2005-04-21 20:48:15 +00:00
|
|
|
const std::vector<std::string> &SharedLibs =
|
2004-07-24 07:48:50 +00:00
|
|
|
std::vector<std::string>(),
|
|
|
|
unsigned Timeout = 0);
|
2003-09-29 22:38:57 +00:00
|
|
|
|
2004-02-18 20:21:57 +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. This throws an
|
|
|
|
// exception if LLC crashes.
|
2003-10-14 21:34:11 +00:00
|
|
|
//
|
2004-12-16 23:01:34 +00:00
|
|
|
virtual void OutputC(const std::string &Bytecode, sys::Path& 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
|
2004-05-04 21:09:01 +00:00
|
|
|
std::vector<std::string> ToolArgs; // Extra args to pass to LLC
|
2003-09-29 22:38:57 +00:00
|
|
|
GCC *gcc;
|
|
|
|
public:
|
2004-05-04 21:09:01 +00:00
|
|
|
LLC(const std::string &llcPath, GCC *Gcc,
|
|
|
|
const std::vector<std::string> *Args) : LLCPath(llcPath), gcc(Gcc) {
|
|
|
|
ToolArgs.clear ();
|
2004-05-04 22:02:41 +00:00
|
|
|
if (Args) { ToolArgs = *Args; }
|
2004-05-04 21:09:01 +00:00
|
|
|
}
|
2003-09-29 22:38:57 +00:00
|
|
|
~LLC() { delete gcc; }
|
|
|
|
|
2004-02-18 23:24:29 +00:00
|
|
|
/// 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
|
|
|
|
/// thrown, otherwise, this function will just return.
|
|
|
|
virtual void compileProgram(const std::string &Bytecode);
|
|
|
|
|
2003-09-29 22:38:57 +00:00
|
|
|
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,
|
2006-06-06 00:00:42 +00:00
|
|
|
const std::vector<std::string> &GCCArgs =
|
|
|
|
std::vector<std::string>(),
|
2005-04-21 20:48:15 +00:00
|
|
|
const std::vector<std::string> &SharedLibs =
|
2004-07-24 07:48:50 +00:00
|
|
|
std::vector<std::string>(),
|
|
|
|
unsigned Timeout = 0);
|
2003-09-29 22:38:57 +00:00
|
|
|
|
2003-10-14 21:34:11 +00:00
|
|
|
// Sometimes we just want to go half-way and only generate the .s file,
|
2004-02-18 20:21:57 +00:00
|
|
|
// not necessarily compile it all the way and run the program. This throws
|
|
|
|
// an exception if execution of LLC fails.
|
2003-10-14 21:34:11 +00:00
|
|
|
//
|
2004-12-16 23:01:34 +00:00
|
|
|
void OutputAsm(const std::string &Bytecode, sys::Path &OutputAsmFile);
|
2003-09-29 22:38:57 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-09-29 22:38:57 +00:00
|
|
|
#endif
|