diff options
author | Chris Lattner <sabre@nondot.org> | 2001-09-10 04:49:44 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-09-10 04:49:44 +0000 |
commit | 676d4118cf71c7dc257fd9c2cd260d86220e34af (patch) | |
tree | 86df08e01ef1d63c3988036f98b50e688c076bf2 /llvm/lib/ExecutionEngine/Interpreter | |
parent | f0afd8bac74a03c4d029ec2d62c2617aec746957 (diff) | |
download | bcm5719-llvm-676d4118cf71c7dc257fd9c2cd260d86220e34af.tar.gz bcm5719-llvm-676d4118cf71c7dc257fd9c2cd260d86220e34af.zip |
Genericize support for calling functions a bit
Add external method support
llvm-svn: 528
Diffstat (limited to 'llvm/lib/ExecutionEngine/Interpreter')
-rw-r--r-- | llvm/lib/ExecutionEngine/Interpreter/Execution.cpp | 41 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Interpreter/Interpreter.h | 5 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Interpreter/UserInput.cpp | 7 |
3 files changed, 32 insertions, 21 deletions
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp index e9861581d5f..0b0cf0a4106 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -43,8 +43,6 @@ static GenericValue getOperandValue(Value *V, ExecutionContext &SF) { return Result; } else { unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value - unsigned Slot = getOperandSlot(V); - void *ElementPtr = &SF.Values[TyP][getOperandSlot(V)]; return SF.Values[TyP][getOperandSlot(V)]; } } @@ -316,6 +314,13 @@ void Interpreter::executeRetInst(ReturnInst *I, ExecutionContext &SF) { SetValue(NewSF.Caller, Result, NewSF); NewSF.Caller = 0; // We returned from the call... + } else { + // This must be a function that is executing because of a user 'call' + // instruction. + cout << "Method " << M->getType() << " \"" << M->getName() + << "\" returned "; + printValue(RetTy, Result); + cout << endl; } } @@ -428,7 +433,12 @@ static void executeStoreInst(StoreInst *I, ExecutionContext &SF) { void Interpreter::executeCallInst(CallInst *I, ExecutionContext &SF) { ECStack.back().Caller = I; - callMethod(I->getCalledMethod(), ECStack.size()-1); + vector<GenericValue> ArgVals; + ArgVals.reserve(I->getNumOperands()-1); + for (unsigned i = 1; i < I->getNumOperands(); ++i) + ArgVals.push_back(getOperandValue(I->getOperand(i), SF)); + + callMethod(I->getCalledMethod(), ArgVals); } static void executePHINode(PHINode *I, ExecutionContext &SF) { @@ -599,10 +609,12 @@ void Interpreter::initializeExecutionEngine() { //===----------------------------------------------------------------------===// // callMethod - Execute the specified method... // -void Interpreter::callMethod(Method *M, int CallingSF = -1) { +void Interpreter::callMethod(Method *M, const vector<GenericValue> &ArgVals) { + assert((ECStack.empty() || ECStack.back().Caller == 0 || + ECStack.back().Caller->getNumOperands()-1 == ArgVals.size()) && + "Incorrect number of arguments passed into function call!"); if (M->isExternal()) { - // Handle builtin methods - cout << "Error: Method '" << M->getName() << "' is external!\n"; + callExternalMethod(M, ArgVals); return; } @@ -625,19 +637,12 @@ void Interpreter::callMethod(Method *M, int CallingSF = -1) { StackFrame.PrevBB = 0; // No previous BB for PHI nodes... - // Run through the method arguments and initialize their values... - if (CallingSF != -1) { - CallInst *Call = ECStack[CallingSF].Caller; - assert(Call && "Caller improperly initialized!"); - - unsigned i = 1; - for (Method::ArgumentListType::iterator MI = M->getArgumentList().begin(), - ME = M->getArgumentList().end(); MI != ME; ++MI, ++i) { - Value *V = Call->getOperand(i); - MethodArgument *MA = *MI; - SetValue(MA, getOperandValue(V, ECStack[CallingSF]), StackFrame); - } + // Run through the method arguments and initialize their values... + unsigned i = 0; + for (Method::ArgumentListType::iterator MI = M->getArgumentList().begin(), + ME = M->getArgumentList().end(); MI != ME; ++MI, ++i) { + SetValue(*MI, ArgVals[i], StackFrame); } } diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h index 3b14954c999..e7f5c864a61 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h +++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h @@ -78,14 +78,15 @@ public: void setBreakpoint(const string &Name); void infoValue(const string &Name); void printValue(const string &Name); - void printValue(const Type *Ty, GenericValue V); + static void printValue(const Type *Ty, GenericValue V); void list(); // Do the 'list' command void printStackTrace(); // Do the 'backtrace' command // Code execution methods... - void callMethod(Method *Meth, int SF = -1); + void callMethod (Method *Meth, const vector<GenericValue> &ArgVals); + void callExternalMethod(Method *Meth, const vector<GenericValue> &ArgVals); bool executeInstruction(); // Execute one instruction... void stepInstruction(); // Do the 'step' command diff --git a/llvm/lib/ExecutionEngine/Interpreter/UserInput.cpp b/llvm/lib/ExecutionEngine/Interpreter/UserInput.cpp index f0c7fe1b6b8..508bd4a3246 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/UserInput.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/UserInput.cpp @@ -144,7 +144,12 @@ bool Interpreter::callMethod(const string &Name) { if (PickedMeth == 0) return true; - callMethod(PickedMeth->castMethodAsserting()); // Start executing it... + Method *M = PickedMeth->castMethodAsserting(); + + vector<GenericValue> Args; + // TODO, get args from user... + + callMethod(M, Args); // Start executing it... // Reset the current frame location to the top of stack CurFrame = ECStack.size()-1; |