aboutsummaryrefslogtreecommitdiff
path: root/tools/lli/lli.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-08-23 17:05:04 +0000
committerChris Lattner <sabre@nondot.org>2001-08-23 17:05:04 +0000
commit92101acd7fd44fd467fbeb974ae6c042289c74f9 (patch)
tree8a95b8161082bc30eb13e16302b30a3f38fd0ef3 /tools/lli/lli.cpp
parente27c344b5657eb225688c2adb163d6064cc9cf8f (diff)
Initial checkin of interpreter
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lli/lli.cpp')
-rw-r--r--tools/lli/lli.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
new file mode 100644
index 0000000000..9611e0ca85
--- /dev/null
+++ b/tools/lli/lli.cpp
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+// 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"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Bytecode/Reader.h"
+
+cl::String InputFilename("" , "Input filename", cl::NoFlags, "-");
+cl::String MainFunction ("f" , "Function to execute", cl::NoFlags, "main");
+cl::Flag DebugMode ("debug" , "Start program in debugger");
+cl::Alias DebugModeA ("d" , "Alias for -debug", cl::NoFlags, DebugMode);
+cl::Flag ProfileMode ("profile", "Enable Profiling [unimp]");
+
+//===----------------------------------------------------------------------===//
+// Interpreter ctor - Initialize stuff
+//
+Interpreter::Interpreter() : ExitCode(0), Profile(ProfileMode), CurFrame(-1) {
+ CurMod = ParseBytecodeFile(InputFilename);
+ if (CurMod == 0) {
+ cout << "Error parsing '" << InputFilename << "': No module loaded.\n";
+ }
+
+ // Initialize the "backend"
+ initializeExecutionEngine();
+}
+
+//===----------------------------------------------------------------------===//
+// main Driver function
+//
+int main(int argc, char** argv) {
+ cl::ParseCommandLineOptions(argc, argv, " llvm interpreter\n");
+
+ // 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();
+
+ // Start interpreter into the main function...
+ //
+ if (!I.callMethod(MainFunction) && !DebugMode) {
+ // 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();
+}