2001-08-23 17:05:04 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LLVM INTERPRETER/DEBUGGER/PROFILER UTILITY
|
|
|
|
//
|
|
|
|
// This utility is an interactive frontend to almost all other LLVM
|
|
|
|
// functionality. It may be used as an interpreter to run code, a debugger to
|
|
|
|
// find problems, or a profiler to analyze execution frequencies.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Interpreter.h"
|
2001-11-27 00:03:19 +00:00
|
|
|
#include "Support/CommandLine.h"
|
2001-08-23 17:05:04 +00:00
|
|
|
|
2002-07-25 16:39:56 +00:00
|
|
|
static cl::opt<std::string>
|
2002-07-22 02:10:13 +00:00
|
|
|
InputFile(cl::desc("<input bytecode>"), cl::Positional, cl::init("-"));
|
|
|
|
|
|
|
|
static cl::list<std::string>
|
|
|
|
InputArgv(cl::ConsumeAfter, cl::desc("<program arguments>..."));
|
|
|
|
|
2002-07-25 16:39:56 +00:00
|
|
|
static cl::opt<std::string>
|
2002-07-22 02:10:13 +00:00
|
|
|
MainFunction ("f", cl::desc("Function to execute"), cl::init("main"),
|
|
|
|
cl::value_desc("function name"));
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
DebugMode("debug", cl::desc("Start program in debugger"));
|
|
|
|
|
|
|
|
static cl::alias
|
|
|
|
DebugModeA("d", cl::desc("Alias for -debug"), cl::aliasopt(DebugMode));
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
TraceMode("trace", cl::desc("Enable Tracing"));
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
ProfileMode("profile", cl::desc("Enable Profiling [unimp]"));
|
2001-08-23 17:05:04 +00:00
|
|
|
|
2001-10-27 08:43:52 +00:00
|
|
|
|
2001-08-23 17:05:04 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Interpreter ctor - Initialize stuff
|
|
|
|
//
|
2001-10-27 08:43:52 +00:00
|
|
|
Interpreter::Interpreter() : ExitCode(0), Profile(ProfileMode),
|
|
|
|
Trace(TraceMode), CurFrame(-1) {
|
2001-10-15 05:51:48 +00:00
|
|
|
CurMod = 0;
|
2002-07-22 02:10:13 +00:00
|
|
|
loadModule(InputFile);
|
2001-08-23 17:05:04 +00:00
|
|
|
|
|
|
|
// Initialize the "backend"
|
|
|
|
initializeExecutionEngine();
|
2001-10-30 20:28:46 +00:00
|
|
|
initializeExternalMethods();
|
2001-08-23 17:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// main Driver function
|
|
|
|
//
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
cl::ParseCommandLineOptions(argc, argv, " llvm interpreter\n");
|
|
|
|
|
2002-07-22 02:10:13 +00:00
|
|
|
// Add the module name to the start of the argv vector...
|
|
|
|
//
|
|
|
|
InputArgv.insert(InputArgv.begin(), InputFile);
|
|
|
|
|
2001-08-23 17:05:04 +00:00
|
|
|
// Create the interpreter...
|
|
|
|
Interpreter I;
|
|
|
|
|
|
|
|
// Handle alternate names of the program. If started as llp, enable profiling
|
|
|
|
// if started as ldb, enable debugging...
|
|
|
|
//
|
|
|
|
if (argv[0] == "ldb") // TODO: Obviously incorrect, but you get the idea
|
|
|
|
DebugMode = true;
|
|
|
|
else if (argv[0] == "llp")
|
|
|
|
ProfileMode = true;
|
|
|
|
|
|
|
|
// If running with the profiler, enable it now...
|
|
|
|
if (ProfileMode) I.enableProfiling();
|
2001-10-27 08:43:52 +00:00
|
|
|
if (TraceMode) I.enableTracing();
|
2001-08-23 17:05:04 +00:00
|
|
|
|
|
|
|
// Start interpreter into the main function...
|
|
|
|
//
|
2001-10-27 05:54:31 +00:00
|
|
|
if (!I.callMainMethod(MainFunction, InputArgv) && !DebugMode) {
|
2001-08-23 17:05:04 +00:00
|
|
|
// If not in debug mode and if the call succeeded, run the code now...
|
|
|
|
I.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If debug mode, allow the user to interact... also, if the user pressed
|
|
|
|
// ctrl-c or execution hit an error, enter the event loop...
|
|
|
|
if (DebugMode || I.isStopped())
|
|
|
|
I.handleUserInput();
|
|
|
|
|
|
|
|
// Return the status code of the program executed...
|
|
|
|
return I.getExitCode();
|
|
|
|
}
|