blob: ba5a3a5dc725f43cf792939bdb0f271ea8d0b628 [file] [log] [blame]
Chris Lattner92101ac2001-08-23 17:05:04 +00001//===----------------------------------------------------------------------===//
2// LLVM INTERPRETER/DEBUGGER/PROFILER UTILITY
3//
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.
7//
8//===----------------------------------------------------------------------===//
9
10#include "Interpreter.h"
11#include "llvm/Support/CommandLine.h"
Chris Lattner92101ac2001-08-23 17:05:04 +000012
Chris Lattner204eec32001-10-27 05:54:31 +000013cl::StringList InputArgv("" , "Input command line", cl::ConsumeAfter);
Chris Lattner92101ac2001-08-23 17:05:04 +000014cl::String MainFunction ("f" , "Function to execute", cl::NoFlags, "main");
15cl::Flag DebugMode ("debug" , "Start program in debugger");
16cl::Alias DebugModeA ("d" , "Alias for -debug", cl::NoFlags, DebugMode);
Chris Lattner43e3f7c2001-10-27 08:43:52 +000017cl::Flag TraceMode ("trace" , "Enable Tracing");
Chris Lattner92101ac2001-08-23 17:05:04 +000018cl::Flag ProfileMode ("profile", "Enable Profiling [unimp]");
19
Chris Lattner43e3f7c2001-10-27 08:43:52 +000020
Chris Lattner92101ac2001-08-23 17:05:04 +000021//===----------------------------------------------------------------------===//
22// Interpreter ctor - Initialize stuff
23//
Chris Lattner43e3f7c2001-10-27 08:43:52 +000024Interpreter::Interpreter() : ExitCode(0), Profile(ProfileMode),
25 Trace(TraceMode), CurFrame(-1) {
Chris Lattner2e42d3a2001-10-15 05:51:48 +000026 CurMod = 0;
Chris Lattneraa7420b2001-10-29 14:00:48 +000027 loadModule(InputArgv.size() ? InputArgv[0] : "-");
Chris Lattner92101ac2001-08-23 17:05:04 +000028
29 // Initialize the "backend"
30 initializeExecutionEngine();
Chris Lattner2b2e5b32001-10-30 20:28:46 +000031 initializeExternalMethods();
Chris Lattner92101ac2001-08-23 17:05:04 +000032}
33
34//===----------------------------------------------------------------------===//
35// main Driver function
36//
37int main(int argc, char** argv) {
38 cl::ParseCommandLineOptions(argc, argv, " llvm interpreter\n");
39
40 // Create the interpreter...
41 Interpreter I;
42
43 // Handle alternate names of the program. If started as llp, enable profiling
44 // if started as ldb, enable debugging...
45 //
46 if (argv[0] == "ldb") // TODO: Obviously incorrect, but you get the idea
47 DebugMode = true;
48 else if (argv[0] == "llp")
49 ProfileMode = true;
50
51 // If running with the profiler, enable it now...
52 if (ProfileMode) I.enableProfiling();
Chris Lattner43e3f7c2001-10-27 08:43:52 +000053 if (TraceMode) I.enableTracing();
Chris Lattner92101ac2001-08-23 17:05:04 +000054
55 // Start interpreter into the main function...
56 //
Chris Lattner204eec32001-10-27 05:54:31 +000057 if (!I.callMainMethod(MainFunction, InputArgv) && !DebugMode) {
Chris Lattner92101ac2001-08-23 17:05:04 +000058 // If not in debug mode and if the call succeeded, run the code now...
59 I.run();
60 }
61
62 // If debug mode, allow the user to interact... also, if the user pressed
63 // ctrl-c or execution hit an error, enter the event loop...
64 if (DebugMode || I.isStopped())
65 I.handleUserInput();
66
67 // Return the status code of the program executed...
68 return I.getExitCode();
69}