2006-06-07 06:30:59 +08:00
|
|
|
//===-- tools/bugpoint/ToolRunner.h -----------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:44:31 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-06-07 06:30:59 +08: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_TOOLS_BUGPOINT_TOOLRUNNER_H
|
|
|
|
#define LLVM_TOOLS_BUGPOINT_TOOLRUNNER_H
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2009-08-18 11:35:57 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2009-08-05 17:32:10 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2010-04-12 13:08:25 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-12-04 18:44:52 +08:00
|
|
|
#include "llvm/Support/SystemUtils.h"
|
2006-06-07 06:30:59 +08:00
|
|
|
#include <exception>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2009-08-05 17:32:10 +08:00
|
|
|
extern cl::opt<bool> SaveTemps;
|
2009-08-18 11:35:57 +08:00
|
|
|
extern Triple TargetTriple;
|
2009-08-05 17:32:10 +08:00
|
|
|
|
2006-06-07 06:30:59 +08:00
|
|
|
class LLC;
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// GCC abstraction
|
|
|
|
//
|
|
|
|
class GCC {
|
2013-06-14 00:22:26 +08:00
|
|
|
std::string GCCPath; // The path to the gcc executable.
|
|
|
|
std::string RemoteClientPath; // The path to the rsh / ssh executable.
|
2009-03-03 07:13:18 +08:00
|
|
|
std::vector<std::string> gccArgs; // GCC-specific arguments.
|
2013-06-14 00:22:26 +08:00
|
|
|
GCC(StringRef gccPath, StringRef RemotePath,
|
2009-03-03 07:13:18 +08:00
|
|
|
const std::vector<std::string> *GCCArgs)
|
|
|
|
: GCCPath(gccPath), RemoteClientPath(RemotePath) {
|
|
|
|
if (GCCArgs) gccArgs = *GCCArgs;
|
|
|
|
}
|
2006-06-07 06:30:59 +08:00
|
|
|
public:
|
2010-03-16 14:41:47 +08:00
|
|
|
enum FileType { AsmFile, ObjectFile, CFile };
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2009-08-06 04:21:17 +08:00
|
|
|
static GCC *create(std::string &Message,
|
2010-05-10 15:38:37 +08:00
|
|
|
const std::string &GCCBinary,
|
2009-03-03 07:13:18 +08:00
|
|
|
const std::vector<std::string> *Args);
|
2006-06-07 06:30:59 +08: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.
|
|
|
|
///
|
|
|
|
int ExecuteProgram(const std::string &ProgramFile,
|
|
|
|
const std::vector<std::string> &Args,
|
|
|
|
FileType fileType,
|
|
|
|
const std::string &InputFile,
|
|
|
|
const std::string &OutputFile,
|
2014-04-28 12:05:08 +08:00
|
|
|
std::string *Error = nullptr,
|
2006-06-07 06:30:59 +08:00
|
|
|
const std::vector<std::string> &GCCArgs =
|
2011-02-09 02:07:10 +08:00
|
|
|
std::vector<std::string>(),
|
2007-02-17 03:11:07 +08:00
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0);
|
2006-06-07 06:30:59 +08: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-28 04:35:36 +08:00
|
|
|
std::string &OutputFile,
|
2010-04-12 13:08:25 +08:00
|
|
|
const std::vector<std::string> &ArgsForGCC,
|
|
|
|
std::string &Error);
|
2006-06-07 06:30:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
/// AbstractInterpreter Class - Subclasses of this class are used to execute
|
2007-07-05 05:55:50 +08:00
|
|
|
/// LLVM bitcode in a variety of ways. This abstract interface hides this
|
2006-06-07 06:30:59 +08:00
|
|
|
/// complexity behind a simple interface.
|
|
|
|
///
|
|
|
|
class AbstractInterpreter {
|
2011-12-20 10:50:00 +08:00
|
|
|
virtual void anchor();
|
2006-06-07 06:30:59 +08:00
|
|
|
public:
|
2009-08-06 04:21:17 +08:00
|
|
|
static LLC *createLLC(const char *Argv0, std::string &Message,
|
2010-05-10 15:38:37 +08:00
|
|
|
const std::string &GCCBinary,
|
2014-04-28 12:05:08 +08:00
|
|
|
const std::vector<std::string> *Args = nullptr,
|
|
|
|
const std::vector<std::string> *GCCArgs = nullptr,
|
2010-03-16 14:41:47 +08:00
|
|
|
bool UseIntegratedAssembler = false);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2014-04-28 12:05:08 +08:00
|
|
|
static AbstractInterpreter*
|
|
|
|
createLLI(const char *Argv0, std::string &Message,
|
|
|
|
const std::vector<std::string> *Args = nullptr);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2014-04-28 12:05:08 +08:00
|
|
|
static AbstractInterpreter*
|
|
|
|
createJIT(const char *Argv0, std::string &Message,
|
|
|
|
const std::vector<std::string> *Args = nullptr);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2011-02-09 02:20:48 +08:00
|
|
|
static AbstractInterpreter*
|
|
|
|
createCustomCompiler(std::string &Message,
|
|
|
|
const std::string &CompileCommandLine);
|
|
|
|
|
|
|
|
static AbstractInterpreter*
|
|
|
|
createCustomExecutor(std::string &Message,
|
|
|
|
const std::string &ExecCommandLine);
|
2008-04-29 04:53:48 +08:00
|
|
|
|
2006-06-07 06:30:59 +08:00
|
|
|
|
|
|
|
virtual ~AbstractInterpreter() {}
|
|
|
|
|
2007-07-05 05:55:50 +08:00
|
|
|
/// compileProgram - Compile the specified program from bitcode to executable
|
2006-06-07 06:30:59 +08:00
|
|
|
/// code. This does not produce any output, it is only used when debugging
|
2010-04-12 13:08:25 +08:00
|
|
|
/// the code generator. It returns false if the code generator fails.
|
2010-05-24 15:49:55 +08:00
|
|
|
virtual void compileProgram(const std::string &Bitcode, std::string *Error,
|
|
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0) {}
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2007-07-05 05:55:50 +08:00
|
|
|
/// OutputCode - Compile the specified program from bitcode to code
|
2006-09-16 05:29:15 +08:00
|
|
|
/// understood by the GCC driver (either C or asm). If the code generator
|
2010-04-12 13:08:25 +08:00
|
|
|
/// fails, it sets Error, otherwise, this function returns the type of code
|
|
|
|
/// emitted.
|
2007-07-05 05:55:50 +08:00
|
|
|
virtual GCC::FileType OutputCode(const std::string &Bitcode,
|
2013-06-18 03:21:38 +08:00
|
|
|
std::string &OutFile, std::string &Error,
|
2010-05-24 15:49:55 +08:00
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) {
|
2010-04-12 13:08:25 +08:00
|
|
|
Error = "OutputCode not supported by this AbstractInterpreter!";
|
|
|
|
return GCC::AsmFile;
|
2006-09-16 05:29:15 +08:00
|
|
|
}
|
2010-04-12 13:08:25 +08:00
|
|
|
|
2007-07-05 05:55:50 +08:00
|
|
|
/// ExecuteProgram - Run the specified bitcode file, emitting output to the
|
2010-04-12 13:08:25 +08: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.
|
2006-06-07 06:30:59 +08:00
|
|
|
///
|
2007-07-05 05:55:50 +08:00
|
|
|
virtual int ExecuteProgram(const std::string &Bitcode,
|
2006-06-07 06:30:59 +08:00
|
|
|
const std::vector<std::string> &Args,
|
|
|
|
const std::string &InputFile,
|
|
|
|
const std::string &OutputFile,
|
2010-04-12 13:08:25 +08:00
|
|
|
std::string *Error,
|
2006-06-07 06:30:59 +08:00
|
|
|
const std::vector<std::string> &GCCArgs =
|
|
|
|
std::vector<std::string>(),
|
|
|
|
const std::vector<std::string> &SharedLibs =
|
|
|
|
std::vector<std::string>(),
|
2007-02-17 03:11:07 +08:00
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) = 0;
|
2006-06-07 06:30:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// LLC Implementation of AbstractIntepreter interface
|
|
|
|
//
|
|
|
|
class LLC : public AbstractInterpreter {
|
2009-03-03 07:13:18 +08:00
|
|
|
std::string LLCPath; // The path to the LLC executable.
|
|
|
|
std::vector<std::string> ToolArgs; // Extra args to pass to LLC.
|
2006-06-07 06:30:59 +08:00
|
|
|
GCC *gcc;
|
2010-03-16 14:41:47 +08:00
|
|
|
bool UseIntegratedAssembler;
|
2006-06-07 06:30:59 +08:00
|
|
|
public:
|
|
|
|
LLC(const std::string &llcPath, GCC *Gcc,
|
2009-03-03 07:13:18 +08:00
|
|
|
const std::vector<std::string> *Args,
|
2010-03-16 14:41:47 +08:00
|
|
|
bool useIntegratedAssembler)
|
|
|
|
: LLCPath(llcPath), gcc(Gcc),
|
|
|
|
UseIntegratedAssembler(useIntegratedAssembler) {
|
2009-03-03 07:13:18 +08:00
|
|
|
ToolArgs.clear();
|
|
|
|
if (Args) ToolArgs = *Args;
|
2006-06-07 06:30:59 +08:00
|
|
|
}
|
2015-04-11 10:11:45 +08:00
|
|
|
~LLC() override { delete gcc; }
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2007-07-05 05:55:50 +08:00
|
|
|
/// compileProgram - Compile the specified program from bitcode to executable
|
2006-06-07 06:30:59 +08:00
|
|
|
/// code. This does not produce any output, it is only used when debugging
|
2010-04-12 13:08:25 +08:00
|
|
|
/// the code generator. Returns false if the code generator fails.
|
2014-03-08 16:27:28 +08:00
|
|
|
void compileProgram(const std::string &Bitcode, std::string *Error,
|
|
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0) override;
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2014-03-08 16:27:28 +08:00
|
|
|
int ExecuteProgram(const std::string &Bitcode,
|
|
|
|
const std::vector<std::string> &Args,
|
|
|
|
const std::string &InputFile,
|
|
|
|
const std::string &OutputFile,
|
|
|
|
std::string *Error,
|
|
|
|
const std::vector<std::string> &GCCArgs =
|
|
|
|
std::vector<std::string>(),
|
|
|
|
const std::vector<std::string> &SharedLibs =
|
|
|
|
std::vector<std::string>(),
|
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) override;
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2010-04-12 13:08:25 +08: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.
|
2014-03-08 16:27:28 +08:00
|
|
|
GCC::FileType OutputCode(const std::string &Bitcode,
|
|
|
|
std::string &OutFile, std::string &Error,
|
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) override;
|
2006-06-07 06:30:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|