llvm-6502/tools/lli/lli.cpp
Brian Gaeke 8e53948881 Move EE dtor where it belongs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8345 91177308-0d34-0410-b5e6-96231b3b80d8
2003-09-04 22:57:27 +00:00

73 lines
2.5 KiB
C++

//===- lli.cpp - LLVM Interpreter / Dynamic compiler ----------------------===//
//
// This utility provides a way to execute LLVM bytecode without static
// compilation. This consists of a very simple and slow (but portable)
// interpreter, along with capability for system specific dynamic compilers. At
// runtime, the fastest (stable) execution engine is selected to run the
// program. This means the JIT compiler for the current platform if it's
// available.
//
//===----------------------------------------------------------------------===//
#include "ExecutionEngine.h"
#include "Support/CommandLine.h"
#include "llvm/Bytecode/Reader.h"
#include "llvm/Module.h"
#include "llvm/Target/TargetMachineImpls.h"
namespace {
cl::opt<std::string>
InputFile(cl::desc("<input bytecode>"), cl::Positional, cl::init("-"));
cl::list<std::string>
InputArgv(cl::ConsumeAfter, cl::desc("<program arguments>..."));
cl::opt<std::string>
MainFunction ("f", cl::desc("Function to execute"), cl::init("main"),
cl::value_desc("function name"));
cl::opt<bool> TraceMode("trace", cl::desc("Enable Tracing"));
cl::opt<bool> ForceInterpreter("force-interpreter",
cl::desc("Force interpretation: disable JIT"),
cl::init(false));
}
//===----------------------------------------------------------------------===//
// main Driver function
//
int main(int argc, char** argv, const char ** envp) {
cl::ParseCommandLineOptions(argc, argv,
" llvm interpreter & dynamic compiler\n");
// Load the bytecode...
std::string ErrorMsg;
Module *M = ParseBytecodeFile(InputFile, &ErrorMsg);
if (M == 0) {
std::cout << "Error parsing '" << InputFile << "': "
<< ErrorMsg << "\n";
exit(1);
}
ExecutionEngine *EE =
ExecutionEngine::create (M, ForceInterpreter, TraceMode);
assert (EE && "Couldn't create an ExecutionEngine, not even an interpreter?");
// Add the module's name to the start of the vector of arguments to main().
// But delete .bc first, since programs (and users) might not expect to
// see it.
const std::string ByteCodeFileSuffix (".bc");
if (InputFile.rfind (ByteCodeFileSuffix) ==
InputFile.length () - ByteCodeFileSuffix.length ()) {
InputFile.erase (InputFile.length () - ByteCodeFileSuffix.length ());
}
InputArgv.insert(InputArgv.begin(), InputFile);
// Run the main function!
int ExitCode = EE->run(MainFunction, InputArgv, envp);
// Now that we are done executing the program, shut down the execution engine
delete EE;
return ExitCode;
}