Implement a -trace command line option and a trace option in the interpreter.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@989 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index a7ded5b..1d7ec7a 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -834,6 +834,9 @@
ExecutionContext &SF = ECStack.back(); // Current stack frame
Instruction *I = *SF.CurInst++; // Increment before execute
+ if (Trace)
+ cout << "Run:" << I;
+
if (I->isBinaryOp()) {
executeBinaryInst((BinaryOperator*)I, SF);
} else {
diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.h b/lib/ExecutionEngine/Interpreter/Interpreter.h
index 16cc569..2d262ae 100644
--- a/lib/ExecutionEngine/Interpreter/Interpreter.h
+++ b/lib/ExecutionEngine/Interpreter/Interpreter.h
@@ -56,6 +56,7 @@
Module *CurMod; // The current Module being executed (0 if none)
int ExitCode; // The exit code to be returned by the lli util
bool Profile; // Profiling enabled?
+ bool Trace; // Tracing enabled?
int CurFrame; // The current stack frame being inspected
// The runtime stack of executing code. The top of the stack is the current
@@ -72,6 +73,7 @@
// enableProfiling() - Turn profiling on, clear stats?
void enableProfiling() { Profile = true; }
+ void enableTracing() { Trace = true; }
void initializeExecutionEngine();
void handleUserInput();
diff --git a/lib/ExecutionEngine/Interpreter/UserInput.cpp b/lib/ExecutionEngine/Interpreter/UserInput.cpp
index a24b311..97bba9c 100644
--- a/lib/ExecutionEngine/Interpreter/UserInput.cpp
+++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp
@@ -16,7 +16,8 @@
Print, Info, List, StackTrace, Up, Down, // Inspection
Next, Step, Run, Finish, Call, // Control flow changes
Break, Watch, // Debugging
- Load, Flush
+ Load, Flush,
+ TraceOpt, ProfileOpt // Toggle features
};
// CommandTable - Build a lookup table for the commands available to the user...
@@ -52,6 +53,9 @@
{ "load" , Load },
{ "flush" , Flush },
+
+ { "trace" , TraceOpt },
+ { "profile" , ProfileOpt },
};
static CommandTableElement *CommandTableEnd =
CommandTable+sizeof(CommandTable)/sizeof(CommandTable[0]);
@@ -118,6 +122,16 @@
finish(); // Run until it's complete
break;
+ case TraceOpt:
+ Trace = !Trace;
+ cout << "Tracing " << (Trace ? "enabled\n" : "disabled\n");
+ break;
+
+ case ProfileOpt:
+ Profile = !Profile;
+ cout << "Profiling " << (Trace ? "enabled\n" : "disabled\n");
+ break;
+
default:
cout << "Command '" << Command << "' unimplemented!\n";
break;