Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 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 Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 12 | |
| 13 | cl::String InputFilename("" , "Input filename", cl::NoFlags, "-"); |
| 14 | cl::String MainFunction ("f" , "Function to execute", cl::NoFlags, "main"); |
| 15 | cl::Flag DebugMode ("debug" , "Start program in debugger"); |
| 16 | cl::Alias DebugModeA ("d" , "Alias for -debug", cl::NoFlags, DebugMode); |
| 17 | cl::Flag ProfileMode ("profile", "Enable Profiling [unimp]"); |
| 18 | |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | // Interpreter ctor - Initialize stuff |
| 21 | // |
| 22 | Interpreter::Interpreter() : ExitCode(0), Profile(ProfileMode), CurFrame(-1) { |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 23 | CurMod = 0; |
| 24 | loadModule(InputFilename); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 25 | |
| 26 | // Initialize the "backend" |
| 27 | initializeExecutionEngine(); |
| 28 | } |
| 29 | |
| 30 | //===----------------------------------------------------------------------===// |
| 31 | // main Driver function |
| 32 | // |
| 33 | int main(int argc, char** argv) { |
| 34 | cl::ParseCommandLineOptions(argc, argv, " llvm interpreter\n"); |
| 35 | |
| 36 | // Create the interpreter... |
| 37 | Interpreter I; |
| 38 | |
| 39 | // Handle alternate names of the program. If started as llp, enable profiling |
| 40 | // if started as ldb, enable debugging... |
| 41 | // |
| 42 | if (argv[0] == "ldb") // TODO: Obviously incorrect, but you get the idea |
| 43 | DebugMode = true; |
| 44 | else if (argv[0] == "llp") |
| 45 | ProfileMode = true; |
| 46 | |
| 47 | // If running with the profiler, enable it now... |
| 48 | if (ProfileMode) I.enableProfiling(); |
| 49 | |
| 50 | // Start interpreter into the main function... |
| 51 | // |
Chris Lattner | f8f2afb | 2001-10-18 21:55:32 +0000 | [diff] [blame^] | 52 | if (!I.callMainMethod(MainFunction, InputFilename) && !DebugMode) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 53 | // If not in debug mode and if the call succeeded, run the code now... |
| 54 | I.run(); |
| 55 | } |
| 56 | |
| 57 | // If debug mode, allow the user to interact... also, if the user pressed |
| 58 | // ctrl-c or execution hit an error, enter the event loop... |
| 59 | if (DebugMode || I.isStopped()) |
| 60 | I.handleUserInput(); |
| 61 | |
| 62 | // Return the status code of the program executed... |
| 63 | return I.getExitCode(); |
| 64 | } |