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
|
|
|
|
//
|
2007-12-29 20:44:31 +00:00
|
|
|
// This file 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
|
|
|
|
2009-08-18 03:35:57 +00:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2009-08-05 09:32:10 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
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 {
|
|
|
|
|
2009-08-05 09:32:10 +00:00
|
|
|
extern cl::opt<bool> SaveTemps;
|
2009-08-18 03:35:57 +00:00
|
|
|
extern Triple TargetTriple;
|
2009-08-05 09:32:10 +00:00
|
|
|
|
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 {
|
2009-03-02 23:13:18 +00:00
|
|
|
sys::Path GCCPath; // The path to the gcc executable.
|
|
|
|
sys::Path RemoteClientPath; // The path to the rsh / ssh executable.
|
|
|
|
std::vector<std::string> gccArgs; // GCC-specific arguments.
|
|
|
|
GCC(const sys::Path &gccPath, const sys::Path &RemotePath,
|
|
|
|
const std::vector<std::string> *GCCArgs)
|
|
|
|
: GCCPath(gccPath), RemoteClientPath(RemotePath) {
|
|
|
|
if (GCCArgs) gccArgs = *GCCArgs;
|
|
|
|
}
|
2003-10-14 21:34:11 +00:00
|
|
|
public:
|
|
|
|
enum FileType { AsmFile, CFile };
|
|
|
|
|
2009-08-05 20:21:17 +00:00
|
|
|
static GCC *create(std::string &Message,
|
2009-03-02 23:13:18 +00:00
|
|
|
const std::vector<std::string> *Args);
|
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>(),
|
2007-02-16 19:11:07 +00:00
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 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
|
2007-07-04 21:55:50 +00:00
|
|
|
/// LLVM bitcode in a variety of ways. This abstract interface hides this
|
2003-09-29 22:38:57 +00:00
|
|
|
/// complexity behind a simple interface.
|
|
|
|
///
|
2005-01-22 16:30:58 +00:00
|
|
|
class AbstractInterpreter {
|
|
|
|
public:
|
2009-08-05 20:21:17 +00:00
|
|
|
static CBE *createCBE(const char *Argv0, std::string &Message,
|
2009-03-02 23:13:18 +00:00
|
|
|
const std::vector<std::string> *Args = 0,
|
|
|
|
const std::vector<std::string> *GCCArgs = 0);
|
2009-08-05 20:21:17 +00:00
|
|
|
static LLC *createLLC(const char *Argv0, std::string &Message,
|
2009-03-02 23:13:18 +00:00
|
|
|
const std::vector<std::string> *Args = 0,
|
|
|
|
const std::vector<std::string> *GCCArgs = 0);
|
2003-10-14 21:34:11 +00:00
|
|
|
|
2009-08-05 20:21:17 +00:00
|
|
|
static AbstractInterpreter* createLLI(const char *Argv0, std::string &Message,
|
2004-05-04 21:09:01 +00:00
|
|
|
const std::vector<std::string> *Args=0);
|
2003-10-14 21:34:11 +00:00
|
|
|
|
2009-08-05 20:21:17 +00:00
|
|
|
static AbstractInterpreter* createJIT(const char *Argv0, std::string &Message,
|
2004-05-04 21:09:01 +00:00
|
|
|
const std::vector<std::string> *Args=0);
|
2003-10-14 21:34:11 +00:00
|
|
|
|
2009-08-05 20:21:17 +00:00
|
|
|
static AbstractInterpreter* createCustom(std::string &Message,
|
2008-04-28 20:53:48 +00:00
|
|
|
const std::string &ExecCommandLine);
|
|
|
|
|
2003-09-29 22:38:57 +00:00
|
|
|
|
|
|
|
virtual ~AbstractInterpreter() {}
|
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
/// compileProgram - Compile the specified program from bitcode to executable
|
2004-02-18 23:24:29 +00:00
|
|
|
/// 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.
|
2007-07-04 21:55:50 +00:00
|
|
|
virtual void compileProgram(const std::string &Bitcode) {}
|
2004-02-18 23:24:29 +00:00
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
/// OutputCode - Compile the specified program from bitcode to code
|
2006-09-15 21:29:15 +00:00
|
|
|
/// understood by the GCC driver (either C or asm). If the code generator
|
|
|
|
/// fails, an exception should be thrown, otherwise, this function returns the
|
|
|
|
/// type of code emitted.
|
2007-07-04 21:55:50 +00:00
|
|
|
virtual GCC::FileType OutputCode(const std::string &Bitcode,
|
2006-09-15 21:29:15 +00:00
|
|
|
sys::Path &OutFile) {
|
|
|
|
throw std::string("OutputCode not supported by this AbstractInterpreter!");
|
|
|
|
}
|
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
/// ExecuteProgram - Run the specified bitcode file, emitting output to the
|
2003-09-29 22:38:57 +00:00
|
|
|
/// specified filename. This returns the exit code of the program.
|
|
|
|
///
|
2007-07-04 21:55:50 +00:00
|
|
|
virtual int ExecuteProgram(const std::string &Bitcode,
|
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>(),
|
2007-02-16 19:11:07 +00:00
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) = 0;
|
2003-09-29 22:38:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// CBE Implementation of AbstractIntepreter interface
|
|
|
|
//
|
|
|
|
class CBE : public AbstractInterpreter {
|
2009-03-02 23:13:18 +00:00
|
|
|
sys::Path LLCPath; // The path to the `llc' executable.
|
|
|
|
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,
|
2009-03-02 23:13:18 +00:00
|
|
|
const std::vector<std::string> *Args)
|
|
|
|
: LLCPath(llcPath), gcc(Gcc) {
|
2004-05-04 21:09:01 +00:00
|
|
|
ToolArgs.clear ();
|
2009-03-02 23:13:18 +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; }
|
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
/// compileProgram - Compile the specified program from bitcode to executable
|
2004-02-18 23:24:29 +00:00
|
|
|
/// 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.
|
2007-07-04 21:55:50 +00:00
|
|
|
virtual void compileProgram(const std::string &Bitcode);
|
2004-02-18 23:24:29 +00:00
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
virtual int ExecuteProgram(const std::string &Bitcode,
|
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>(),
|
2007-02-16 19:11:07 +00:00
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0);
|
2003-09-29 22:38:57 +00:00
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
/// OutputCode - Compile the specified program from bitcode to code
|
2006-09-15 21:29:15 +00:00
|
|
|
/// understood by the GCC driver (either C or asm). If the code generator
|
|
|
|
/// fails, an exception should be thrown, otherwise, this function returns the
|
|
|
|
/// type of code emitted.
|
2007-07-04 21:55:50 +00:00
|
|
|
virtual GCC::FileType OutputCode(const std::string &Bitcode,
|
2006-09-15 21:29:15 +00:00
|
|
|
sys::Path &OutFile);
|
2003-09-29 22:38:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// LLC Implementation of AbstractIntepreter interface
|
|
|
|
//
|
|
|
|
class LLC : public AbstractInterpreter {
|
2009-03-02 23:13:18 +00:00
|
|
|
std::string LLCPath; // The path to the LLC executable.
|
|
|
|
std::vector<std::string> ToolArgs; // Extra args to pass to LLC.
|
|
|
|
std::vector<std::string> gccArgs; // Extra args to pass to GCC.
|
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,
|
2009-03-02 23:13:18 +00:00
|
|
|
const std::vector<std::string> *Args,
|
|
|
|
const std::vector<std::string> *GCCArgs)
|
|
|
|
: LLCPath(llcPath), gcc(Gcc) {
|
|
|
|
ToolArgs.clear();
|
|
|
|
if (Args) ToolArgs = *Args;
|
|
|
|
if (GCCArgs) gccArgs = *GCCArgs;
|
2004-05-04 21:09:01 +00:00
|
|
|
}
|
2003-09-29 22:38:57 +00:00
|
|
|
~LLC() { delete gcc; }
|
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
/// compileProgram - Compile the specified program from bitcode to executable
|
2004-02-18 23:24:29 +00:00
|
|
|
/// 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.
|
2007-07-04 21:55:50 +00:00
|
|
|
virtual void compileProgram(const std::string &Bitcode);
|
2004-02-18 23:24:29 +00:00
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
virtual int ExecuteProgram(const std::string &Bitcode,
|
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>(),
|
2007-02-16 19:11:07 +00:00
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0);
|
2003-09-29 22:38:57 +00:00
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
virtual GCC::FileType OutputCode(const std::string &Bitcode,
|
2006-09-15 21:29:15 +00:00
|
|
|
sys::Path &OutFile);
|
|
|
|
|
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
|