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"
|
2016-09-07 01:18:22 +08:00
|
|
|
#include "llvm/Support/Error.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;
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
2015-10-15 04:29:54 +08:00
|
|
|
// CC abstraction
|
2006-06-07 06:30:59 +08:00
|
|
|
//
|
2015-10-15 04:29:54 +08:00
|
|
|
class CC {
|
2016-09-02 09:21:37 +08:00
|
|
|
std::string CCPath; // The path to the cc executable.
|
|
|
|
std::string RemoteClientPath; // The path to the rsh / ssh executable.
|
2015-10-15 04:29:54 +08:00
|
|
|
std::vector<std::string> ccArgs; // CC-specific arguments.
|
|
|
|
CC(StringRef ccPath, StringRef RemotePath,
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::vector<std::string> *CCArgs)
|
|
|
|
: CCPath(ccPath), RemoteClientPath(RemotePath) {
|
|
|
|
if (CCArgs)
|
|
|
|
ccArgs = *CCArgs;
|
2009-03-03 07:13:18 +08:00
|
|
|
}
|
2016-09-02 09:21:37 +08:00
|
|
|
|
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
|
|
|
|
2016-09-02 09:21:37 +08:00
|
|
|
static CC *create(std::string &Message, const std::string &CCBinary,
|
|
|
|
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.
|
|
|
|
///
|
2016-09-07 01:18:22 +08:00
|
|
|
Expected<int> ExecuteProgram(
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::string &ProgramFile, const std::vector<std::string> &Args,
|
|
|
|
FileType fileType, const std::string &InputFile,
|
2016-09-07 01:18:22 +08:00
|
|
|
const std::string &OutputFile,
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::vector<std::string> &CCArgs = std::vector<std::string>(),
|
|
|
|
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.
|
|
|
|
///
|
2016-09-07 01:18:22 +08:00
|
|
|
Error MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|
|
|
std::string &OutputFile,
|
|
|
|
const std::vector<std::string> &ArgsForCC);
|
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();
|
2016-09-02 09:21:37 +08:00
|
|
|
|
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,
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::string &CCBinary,
|
2014-04-28 12:05:08 +08:00
|
|
|
const std::vector<std::string> *Args = nullptr,
|
2015-10-15 04:29:54 +08:00
|
|
|
const std::vector<std::string> *CCArgs = nullptr,
|
2010-03-16 14:41:47 +08:00
|
|
|
bool UseIntegratedAssembler = false);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2016-09-02 09:21:37 +08:00
|
|
|
static AbstractInterpreter *
|
2014-04-28 12:05:08 +08:00
|
|
|
createLLI(const char *Argv0, std::string &Message,
|
|
|
|
const std::vector<std::string> *Args = nullptr);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2016-09-02 09:21:37 +08:00
|
|
|
static AbstractInterpreter *
|
2014-04-28 12:05:08 +08:00
|
|
|
createJIT(const char *Argv0, std::string &Message,
|
|
|
|
const std::vector<std::string> *Args = nullptr);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2016-09-02 09:21:37 +08:00
|
|
|
static AbstractInterpreter *
|
2011-02-09 02:20:48 +08:00
|
|
|
createCustomCompiler(std::string &Message,
|
|
|
|
const std::string &CompileCommandLine);
|
|
|
|
|
2016-09-02 09:21:37 +08:00
|
|
|
static AbstractInterpreter *
|
2011-02-09 02:20:48 +08:00
|
|
|
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.
|
2016-09-07 01:18:22 +08:00
|
|
|
virtual Error compileProgram(const std::string &Bitcode, unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) {
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Compile the specified program from bitcode to code understood by the CC
|
|
|
|
/// driver (either C or asm). Returns an error if the code generator fails,,
|
|
|
|
/// otherwise, the type of code emitted.
|
|
|
|
virtual Expected<CC::FileType> OutputCode(const std::string &Bitcode,
|
|
|
|
std::string &OutFile,
|
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) {
|
|
|
|
return make_error<StringError>(
|
|
|
|
"OutputCode not supported by this AbstractInterpreter!",
|
|
|
|
inconvertibleErrorCode());
|
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
|
2016-09-07 01:18:22 +08:00
|
|
|
/// returns an Error if a problem was encountered that prevented execution of
|
2010-04-12 13:08:25 +08:00
|
|
|
/// the program.
|
2006-06-07 06:30:59 +08:00
|
|
|
///
|
2016-09-07 01:18:22 +08:00
|
|
|
virtual Expected<int> ExecuteProgram(
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::string &Bitcode, const std::vector<std::string> &Args,
|
|
|
|
const std::string &InputFile, const std::string &OutputFile,
|
|
|
|
const std::vector<std::string> &CCArgs = std::vector<std::string>(),
|
|
|
|
const std::vector<std::string> &SharedLibs = std::vector<std::string>(),
|
|
|
|
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.
|
2015-10-15 04:29:54 +08:00
|
|
|
CC *cc;
|
2010-03-16 14:41:47 +08:00
|
|
|
bool UseIntegratedAssembler;
|
2016-09-02 09:21:37 +08:00
|
|
|
|
2006-06-07 06:30:59 +08:00
|
|
|
public:
|
2016-09-02 09:21:37 +08:00
|
|
|
LLC(const std::string &llcPath, CC *cc, const std::vector<std::string> *Args,
|
2010-03-16 14:41:47 +08:00
|
|
|
bool useIntegratedAssembler)
|
2016-09-02 09:21:37 +08:00
|
|
|
: LLCPath(llcPath), cc(cc),
|
|
|
|
UseIntegratedAssembler(useIntegratedAssembler) {
|
2009-03-03 07:13:18 +08:00
|
|
|
ToolArgs.clear();
|
2016-09-02 09:21:37 +08:00
|
|
|
if (Args)
|
|
|
|
ToolArgs = *Args;
|
2006-06-07 06:30:59 +08:00
|
|
|
}
|
2015-10-15 04:29:54 +08:00
|
|
|
~LLC() override { delete cc; }
|
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.
|
2016-09-07 01:18:22 +08:00
|
|
|
Error compileProgram(const std::string &Bitcode, unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) override;
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2016-09-07 01:18:22 +08:00
|
|
|
Expected<int> ExecuteProgram(
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::string &Bitcode, const std::vector<std::string> &Args,
|
|
|
|
const std::string &InputFile, const std::string &OutputFile,
|
|
|
|
const std::vector<std::string> &CCArgs = 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
|
|
|
|
2016-09-07 01:18:22 +08:00
|
|
|
Expected<CC::FileType> OutputCode(const std::string &Bitcode,
|
|
|
|
std::string &OutFile, unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) override;
|
2006-06-07 06:30:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|