1 //===----------------------------------------------------------------------===//
2 // LLVM INTERPRETER/DEBUGGER/PROFILER UTILITY
4 // This utility is an interactive frontend to almost all other LLVM
5 // functionality. It may be used as an interpreter to run code, a debugger to
6 // find problems, or a profiler to analyze execution frequencies.
8 //===----------------------------------------------------------------------===//
10 #include "Interpreter.h"
11 #include "Support/CommandLine.h"
13 static cl::opt<std::string>
14 InputFile(cl::desc("<input bytecode>"), cl::Positional, cl::init("-"));
16 static cl::list<std::string>
17 InputArgv(cl::ConsumeAfter, cl::desc("<program arguments>..."));
19 static cl::opt<std::string>
20 MainFunction ("f", cl::desc("Function to execute"), cl::init("main"),
21 cl::value_desc("function name"));
24 DebugMode("debug", cl::desc("Start program in debugger"));
27 DebugModeA("d", cl::desc("Alias for -debug"), cl::aliasopt(DebugMode));
30 TraceMode("trace", cl::desc("Enable Tracing"));
33 ProfileMode("profile", cl::desc("Enable Profiling [unimp]"));
36 //===----------------------------------------------------------------------===//
37 // Interpreter ctor - Initialize stuff
39 Interpreter::Interpreter() : ExitCode(0), Profile(ProfileMode),
40 Trace(TraceMode), CurFrame(-1) {
42 loadModule(InputFile);
44 // Initialize the "backend"
45 initializeExecutionEngine();
46 initializeExternalMethods();
49 //===----------------------------------------------------------------------===//
50 // main Driver function
52 int main(int argc, char** argv) {
53 cl::ParseCommandLineOptions(argc, argv, " llvm interpreter\n");
55 // Add the module name to the start of the argv vector...
57 InputArgv.insert(InputArgv.begin(), InputFile);
59 // Create the interpreter...
62 // Handle alternate names of the program. If started as llp, enable profiling
63 // if started as ldb, enable debugging...
65 if (argv[0] == "ldb") // TODO: Obviously incorrect, but you get the idea
67 else if (argv[0] == "llp")
70 // If running with the profiler, enable it now...
71 if (ProfileMode) I.enableProfiling();
72 if (TraceMode) I.enableTracing();
74 // Start interpreter into the main function...
76 if (!I.callMainMethod(MainFunction, InputArgv) && !DebugMode) {
77 // If not in debug mode and if the call succeeded, run the code now...
81 // If debug mode, allow the user to interact... also, if the user pressed
82 // ctrl-c or execution hit an error, enter the event loop...
83 if (DebugMode || I.isStopped())
86 // Return the status code of the program executed...
87 return I.getExitCode();