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
This commit is contained in:
Chris Lattner
2001-10-27 08:43:52 +00:00
parent c259316730
commit 43e3f7c962
4 changed files with 25 additions and 2 deletions

View File

@@ -834,6 +834,9 @@ bool Interpreter::executeInstruction() {
ExecutionContext &SF = ECStack.back(); // Current stack frame ExecutionContext &SF = ECStack.back(); // Current stack frame
Instruction *I = *SF.CurInst++; // Increment before execute Instruction *I = *SF.CurInst++; // Increment before execute
if (Trace)
cout << "Run:" << I;
if (I->isBinaryOp()) { if (I->isBinaryOp()) {
executeBinaryInst((BinaryOperator*)I, SF); executeBinaryInst((BinaryOperator*)I, SF);
} else { } else {

View File

@@ -56,6 +56,7 @@ class Interpreter {
Module *CurMod; // The current Module being executed (0 if none) Module *CurMod; // The current Module being executed (0 if none)
int ExitCode; // The exit code to be returned by the lli util int ExitCode; // The exit code to be returned by the lli util
bool Profile; // Profiling enabled? bool Profile; // Profiling enabled?
bool Trace; // Tracing enabled?
int CurFrame; // The current stack frame being inspected int CurFrame; // The current stack frame being inspected
// The runtime stack of executing code. The top of the stack is the current // The runtime stack of executing code. The top of the stack is the current
@@ -72,6 +73,7 @@ public:
// enableProfiling() - Turn profiling on, clear stats? // enableProfiling() - Turn profiling on, clear stats?
void enableProfiling() { Profile = true; } void enableProfiling() { Profile = true; }
void enableTracing() { Trace = true; }
void initializeExecutionEngine(); void initializeExecutionEngine();
void handleUserInput(); void handleUserInput();

View File

@@ -16,7 +16,8 @@ enum CommandID {
Print, Info, List, StackTrace, Up, Down, // Inspection Print, Info, List, StackTrace, Up, Down, // Inspection
Next, Step, Run, Finish, Call, // Control flow changes Next, Step, Run, Finish, Call, // Control flow changes
Break, Watch, // Debugging Break, Watch, // Debugging
Load, Flush Load, Flush,
TraceOpt, ProfileOpt // Toggle features
}; };
// CommandTable - Build a lookup table for the commands available to the user... // CommandTable - Build a lookup table for the commands available to the user...
@@ -52,6 +53,9 @@ static struct CommandTableElement {
{ "load" , Load }, { "load" , Load },
{ "flush" , Flush }, { "flush" , Flush },
{ "trace" , TraceOpt },
{ "profile" , ProfileOpt },
}; };
static CommandTableElement *CommandTableEnd = static CommandTableElement *CommandTableEnd =
CommandTable+sizeof(CommandTable)/sizeof(CommandTable[0]); CommandTable+sizeof(CommandTable)/sizeof(CommandTable[0]);
@@ -118,6 +122,16 @@ void Interpreter::handleUserInput() {
finish(); // Run until it's complete finish(); // Run until it's complete
break; 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: default:
cout << "Command '" << Command << "' unimplemented!\n"; cout << "Command '" << Command << "' unimplemented!\n";
break; break;

View File

@@ -14,12 +14,15 @@ cl::StringList InputArgv("" , "Input command line", cl::ConsumeAfter);
cl::String MainFunction ("f" , "Function to execute", cl::NoFlags, "main"); cl::String MainFunction ("f" , "Function to execute", cl::NoFlags, "main");
cl::Flag DebugMode ("debug" , "Start program in debugger"); cl::Flag DebugMode ("debug" , "Start program in debugger");
cl::Alias DebugModeA ("d" , "Alias for -debug", cl::NoFlags, DebugMode); cl::Alias DebugModeA ("d" , "Alias for -debug", cl::NoFlags, DebugMode);
cl::Flag TraceMode ("trace" , "Enable Tracing");
cl::Flag ProfileMode ("profile", "Enable Profiling [unimp]"); cl::Flag ProfileMode ("profile", "Enable Profiling [unimp]");
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Interpreter ctor - Initialize stuff // Interpreter ctor - Initialize stuff
// //
Interpreter::Interpreter() : ExitCode(0), Profile(ProfileMode), CurFrame(-1) { Interpreter::Interpreter() : ExitCode(0), Profile(ProfileMode),
Trace(TraceMode), CurFrame(-1) {
CurMod = 0; CurMod = 0;
loadModule(InputArgv.size() ? InputArgv[0] : ""); loadModule(InputArgv.size() ? InputArgv[0] : "");
@@ -46,6 +49,7 @@ int main(int argc, char** argv) {
// If running with the profiler, enable it now... // If running with the profiler, enable it now...
if (ProfileMode) I.enableProfiling(); if (ProfileMode) I.enableProfiling();
if (TraceMode) I.enableTracing();
// Start interpreter into the main function... // Start interpreter into the main function...
// //