Remove support for interactive (step finish next) instructions.

Remove printCurrentInstruction, printStackFrame and infoValue
 (only used interactively) and other unused methods of Interpreter.
Fold UserInput.cpp containing only callMainFunction() into Interpreter.cpp.
Remove unused Profile flag.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8359 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Brian Gaeke 2003-09-05 04:46:26 +00:00
parent 8df956ccf2
commit 413ab6655b
4 changed files with 44 additions and 186 deletions

View File

@ -1048,46 +1048,6 @@ void Interpreter::executeInstruction() {
CurFrame = ECStack.size()-1;
}
void Interpreter::stepInstruction() { // Do the 'step' command
if (ECStack.empty()) {
std::cout << "Error: no program running, cannot step!\n";
return;
}
// Run an instruction...
executeInstruction();
// Print the next instruction to execute...
printCurrentInstruction();
}
// --- UI Stuff...
void Interpreter::nextInstruction() { // Do the 'next' command
if (ECStack.empty()) {
std::cout << "Error: no program running, cannot 'next'!\n";
return;
}
// If this is a call instruction, step over the call instruction...
// TODO: ICALL, CALL WITH, ...
if (ECStack.back().CurInst->getOpcode() == Instruction::Call) {
unsigned StackSize = ECStack.size();
// Step into the function...
executeInstruction();
// If we we able to step into the function, finish it now. We might not be
// able the step into a function, if it's external for example.
if (ECStack.size() != StackSize)
finish(); // Finish executing the function...
else
printCurrentInstruction();
} else {
// Normal instruction, just step...
stepInstruction();
}
}
void Interpreter::run() {
if (ECStack.empty()) {
std::cout << "Error: no program running, cannot run!\n";
@ -1098,40 +1058,6 @@ void Interpreter::run() {
// Run an instruction...
executeInstruction();
}
// Print the next instruction to execute...
printCurrentInstruction();
}
void Interpreter::finish() {
if (ECStack.empty()) {
std::cout << "Error: no program running, cannot run!\n";
return;
}
unsigned StackSize = ECStack.size();
while (ECStack.size() >= StackSize) {
// Run an instruction...
executeInstruction();
}
// Print the next instruction to execute...
printCurrentInstruction();
}
// printCurrentInstruction - Print out the instruction that the virtual PC is
// at, or fail silently if no program is running.
//
void Interpreter::printCurrentInstruction() {
if (!ECStack.empty()) {
if (ECStack.back().CurBB->begin() == ECStack.back().CurInst) // print label
WriteAsOperand(std::cout, ECStack.back().CurBB) << ":\n";
Instruction &I = *ECStack.back().CurInst;
InstNumber *IN = (InstNumber*)I.getAnnotation(SlotNumberAID);
assert(IN && "Instruction has no numbering annotation!");
std::cout << "#" << IN->InstNum << I;
}
}
void Interpreter::printValue(const Type *Ty, GenericValue V) {
@ -1177,44 +1103,3 @@ void Interpreter::print(const std::string &Name) {
std::cout << "\n";
}
}
void Interpreter::infoValue(const std::string &Name) {
Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name));
if (!PickedVal) return;
std::cout << "Value: ";
print(PickedVal->getType(),
getOperandValue(PickedVal, ECStack[CurFrame]));
std::cout << "\n";
printOperandInfo(PickedVal, ECStack[CurFrame]);
}
// printStackFrame - Print information about the specified stack frame, or -1
// for the default one.
//
void Interpreter::printStackFrame(int FrameNo) {
if (FrameNo == -1) FrameNo = CurFrame;
Function *F = ECStack[FrameNo].CurFunction;
const Type *RetTy = F->getReturnType();
CW << ((FrameNo == CurFrame) ? '>' : '-') << "#" << FrameNo << ". "
<< (Value*)RetTy << " \"" << F->getName() << "\"(";
unsigned i = 0;
for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++i) {
if (i != 0) std::cout << ", ";
CW << *I << "=";
printValue(I->getType(), getOperandValue(I, ECStack[FrameNo]));
}
std::cout << ")\n";
if (FrameNo != int(ECStack.size()-1)) {
BasicBlock::iterator I = ECStack[FrameNo].CurInst;
CW << --I;
} else {
CW << *ECStack[FrameNo].CurInst;
}
}

View File

@ -8,6 +8,8 @@
#include "Interpreter.h"
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
/// create - Create a new interpreter object. This can never fail.
///
@ -76,3 +78,45 @@ int Interpreter::run(const std::string &MainFunction,
return ExitCode;
}
// callMainFunction - Construct call to typical C main() function and
// call it using callFunction().
//
bool Interpreter::callMainFunction(const std::string &Name,
const std::vector<std::string> &InputArgv) {
Function *M = getModule().getNamedFunction(Name);
if (M == 0) {
std::cerr << "Could not find function '" << Name << "' in module!\n";
return 1;
}
const FunctionType *MT = M->getFunctionType();
std::vector<GenericValue> Args;
if (MT->getParamTypes().size() >= 2) {
PointerType *SPP = PointerType::get(PointerType::get(Type::SByteTy));
if (MT->getParamTypes()[1] != SPP) {
CW << "Second argument of '" << Name << "' should have type: '"
<< SPP << "'!\n";
return true;
}
Args.push_back(PTOGV(CreateArgv(InputArgv)));
}
if (MT->getParamTypes().size() >= 1) {
if (!MT->getParamTypes()[0]->isInteger()) {
std::cout << "First argument of '" << Name
<< "' should be an integer!\n";
return true;
} else {
GenericValue GV; GV.UIntVal = InputArgv.size();
Args.insert(Args.begin(), GV);
}
}
callFunction(M, Args); // Start executing it...
// Reset the current frame location to the top of stack
CurFrame = ECStack.size()-1;
return false;
}

View File

@ -71,7 +71,6 @@ struct ExecutionContext {
//
class Interpreter : public ExecutionEngine, public InstVisitor<Interpreter> {
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
TargetData TD;
@ -91,11 +90,6 @@ public:
///
static ExecutionEngine *create(Module *M, bool TraceMode);
/// getExitCode - return the code that should be the exit code for the lli
/// utility.
///
inline int getExitCode() const { return ExitCode; }
/// run - Start execution with the specified function and arguments.
///
virtual int run(const std::string &FnName,
@ -103,15 +97,12 @@ public:
const char ** envp);
// enableProfiling() - Turn profiling on, clear stats?
void enableProfiling() { Profile = true; }
void enableTracing() { Trace = true; }
void handleUserInput();
// User Interation Methods...
bool callFunction(const std::string &Name); // return true on failure
void infoValue(const std::string &Name);
void print(const std::string &Name);
static void print(const Type *Ty, GenericValue V);
static void printValue(const Type *Ty, GenericValue V);
@ -119,17 +110,11 @@ public:
bool callMainFunction(const std::string &MainName,
const std::vector<std::string> &InputFilename);
void list(); // Do the 'list' command
void printStackTrace(); // Do the 'backtrace' command
// Code execution methods...
void callFunction(Function *F, const std::vector<GenericValue> &ArgVals);
void executeInstruction(); // Execute one instruction...
void stepInstruction(); // Do the 'step' command
void nextInstruction(); // Do the 'next' command
void run(); // Do the 'run' command
void finish(); // Do the 'finish' command
// Opcode Implementations
void visitReturnInst(ReturnInst &I);
@ -196,11 +181,6 @@ private: // Helper functions
//
void printCurrentInstruction();
// printStackFrame - Print information about the specified stack frame, or -1
// for the default one.
//
void printStackFrame(int FrameNo = -1);
// LookupMatchingNames - Search the current function namespace, then the
// global namespace looking for values that match the specified name. Return
// ALL matches to that name. This is obviously slow, and should only be used

View File

@ -1,51 +0,0 @@
//===-- UserInput.cpp - Interpreter Input Loop support --------------------===//
//
// This file implements the interpreter Input I/O loop.
//
//===----------------------------------------------------------------------===//
#include "Interpreter.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
#include "llvm/Module.h"
// callMainFunction - This is a nasty gross hack that will dissapear when
// callFunction can parse command line options and stuff for us.
//
bool Interpreter::callMainFunction(const std::string &Name,
const std::vector<std::string> &InputArgv) {
Function *M = getModule().getNamedFunction(Name);
if (M == 0) {
std::cerr << "Could not find function '" << Name << "' in module!\n";
return 1;
}
const FunctionType *MT = M->getFunctionType();
std::vector<GenericValue> Args;
if (MT->getParamTypes().size() >= 2) {
PointerType *SPP = PointerType::get(PointerType::get(Type::SByteTy));
if (MT->getParamTypes()[1] != SPP) {
CW << "Second argument of '" << Name << "' should have type: '"
<< SPP << "'!\n";
return true;
}
Args.push_back(PTOGV(CreateArgv(InputArgv)));
}
if (MT->getParamTypes().size() >= 1) {
if (!MT->getParamTypes()[0]->isInteger()) {
std::cout << "First argument of '" << Name << "' should be an integer!\n";
return true;
} else {
GenericValue GV; GV.UIntVal = InputArgv.size();
Args.insert(Args.begin(), GV);
}
}
callFunction(M, Args); // Start executing it...
// Reset the current frame location to the top of stack
CurFrame = ECStack.size()-1;
return false;
}