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"
|
2010-04-12 05:08:25 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/SystemUtils.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Path.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
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// 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:
|
2010-03-16 06:41:47 +00:00
|
|
|
enum FileType { AsmFile, ObjectFile, CFile };
|
2003-10-14 21:34:11 +00:00
|
|
|
|
2009-08-05 20:21:17 +00:00
|
|
|
static GCC *create(std::string &Message,
|
2010-05-10 07:38:37 +00:00
|
|
|
const std::string &GCCBinary,
|
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,
|
2010-07-12 08:16:59 +00:00
|
|
|
std::string *Error = 0,
|
2006-06-06 00:00:42 +00:00
|
|
|
const std::vector<std::string> &GCCArgs =
|
2011-02-08 18:07:10 +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
|
|
|
|
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,
|
2010-04-12 05:08:25 +00:00
|
|
|
const std::vector<std::string> &ArgsForGCC,
|
|
|
|
std::string &Error);
|
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,
|
2010-05-10 07:38:37 +00:00
|
|
|
const std::string &GCCBinary,
|
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,
|
2010-05-10 07:38:37 +00:00
|
|
|
const std::string &GCCBinary,
|
2009-03-02 23:13:18 +00:00
|
|
|
const std::vector<std::string> *Args = 0,
|
2010-03-16 06:41:47 +00:00
|
|
|
const std::vector<std::string> *GCCArgs = 0,
|
|
|
|
bool UseIntegratedAssembler = false);
|
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
|
2010-04-12 05:08:25 +00:00
|
|
|
/// the code generator. It returns false if the code generator fails.
|
2010-05-24 07:49:55 +00:00
|
|
|
virtual void compileProgram(const std::string &Bitcode, std::string *Error,
|
|
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0) {}
|
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
|
2010-04-12 05:08:25 +00:00
|
|
|
/// fails, it sets Error, 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,
|
2010-05-24 07:49:55 +00:00
|
|
|
sys::Path &OutFile, std::string &Error,
|
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) {
|
2010-04-12 05:08:25 +00:00
|
|
|
Error = "OutputCode not supported by this AbstractInterpreter!";
|
|
|
|
return GCC::AsmFile;
|
2006-09-15 21:29:15 +00:00
|
|
|
}
|
2010-04-12 05:08:25 +00:00
|
|
|
|
2007-07-04 21:55:50 +00:00
|
|
|
/// ExecuteProgram - Run the specified bitcode file, emitting output to the
|
2010-04-12 05:08:25 +00:00
|
|
|
/// specified filename. This sets RetVal to the exit code of the program or
|
|
|
|
/// returns false if a problem was encountered that prevented execution of
|
|
|
|
/// the program.
|
2003-09-29 22:38:57 +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,
|
2010-04-12 05:08:25 +00:00
|
|
|
std::string *Error,
|
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
|
2010-04-12 05:08:25 +00:00
|
|
|
/// the code generator. Returns false if the code generator fails.
|
2010-05-24 07:49:55 +00:00
|
|
|
virtual void compileProgram(const std::string &Bitcode, std::string *Error,
|
|
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0);
|
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,
|
2010-04-12 05:08:25 +00:00
|
|
|
std::string *Error,
|
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
|
2010-04-12 05:08:25 +00:00
|
|
|
/// fails, it sets Error, 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,
|
2010-05-24 07:49:55 +00:00
|
|
|
sys::Path &OutFile, std::string &Error,
|
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0);
|
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.
|
2003-09-29 22:38:57 +00:00
|
|
|
GCC *gcc;
|
2010-03-16 06:41:47 +00:00
|
|
|
bool UseIntegratedAssembler;
|
2003-09-29 22:38:57 +00:00
|
|
|
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,
|
2010-03-16 06:41:47 +00:00
|
|
|
bool useIntegratedAssembler)
|
|
|
|
: LLCPath(llcPath), gcc(Gcc),
|
|
|
|
UseIntegratedAssembler(useIntegratedAssembler) {
|
2009-03-02 23:13:18 +00:00
|
|
|
ToolArgs.clear();
|
|
|
|
if (Args) ToolArgs = *Args;
|
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
|
2010-04-12 05:08:25 +00:00
|
|
|
/// the code generator. Returns false if the code generator fails.
|
2010-05-24 07:49:55 +00:00
|
|
|
virtual void compileProgram(const std::string &Bitcode, std::string *Error,
|
|
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0);
|
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,
|
2010-04-12 05:08:25 +00:00
|
|
|
std::string *Error,
|
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
|
|
|
|
2010-04-12 05:08:25 +00:00
|
|
|
/// OutputCode - Compile the specified program from bitcode to code
|
|
|
|
/// understood by the GCC driver (either C or asm). If the code generator
|
|
|
|
/// fails, it sets Error, 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,
|
2010-05-24 07:49:55 +00:00
|
|
|
sys::Path &OutFile, std::string &Error,
|
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0);
|
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
|