mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-05 13:09:10 +00:00
A large number of simple changes:
* s/Method/Function * Kill some obsolete (external) functions that used to be to support tracing git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6041 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cdf5178f83
commit
da82ed52ac
@ -157,8 +157,8 @@ static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) {
|
||||
|
||||
void Interpreter::initializeExecutionEngine() {
|
||||
TheEE = this;
|
||||
AnnotationManager::registerAnnotationFactory(MethodInfoAID,
|
||||
&MethodInfo::Create);
|
||||
AnnotationManager::registerAnnotationFactory(FunctionInfoAID,
|
||||
&FunctionInfo::Create);
|
||||
initializeSignalHandlers();
|
||||
}
|
||||
|
||||
@ -588,7 +588,7 @@ void Interpreter::executeRetInst(ReturnInst &I, ExecutionContext &SF) {
|
||||
}
|
||||
|
||||
// Save previously executing meth
|
||||
const Function *M = ECStack.back().CurMethod;
|
||||
const Function *M = ECStack.back().CurFunction;
|
||||
|
||||
// Pop the current stack frame... this invalidates SF
|
||||
ECStack.pop_back();
|
||||
@ -880,7 +880,7 @@ void Interpreter::executeCallInst(CallInst &I, ExecutionContext &SF) {
|
||||
// and treat it as a function pointer.
|
||||
GenericValue SRC = getOperandValue(I.getCalledValue(), SF);
|
||||
|
||||
callMethod((Function*)GVTOP(SRC), ArgVals);
|
||||
callFunction((Function*)GVTOP(SRC), ArgVals);
|
||||
}
|
||||
|
||||
static void executePHINode(PHINode &I, ExecutionContext &SF) {
|
||||
@ -1014,7 +1014,7 @@ static void executeCastInst(CastInst &I, ExecutionContext &SF) {
|
||||
// Dispatch and Execution Code
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
MethodInfo::MethodInfo(Function *F) : Annotation(MethodInfoAID) {
|
||||
FunctionInfo::FunctionInfo(Function *F) : Annotation(FunctionInfoAID) {
|
||||
// Assign slot numbers to the function arguments...
|
||||
for (Function::const_aiterator AI = F->abegin(), E = F->aend(); AI != E; ++AI)
|
||||
AI->addAnnotation(new SlotNumber(getValueSlot(AI)));
|
||||
@ -1027,7 +1027,7 @@ MethodInfo::MethodInfo(Function *F) : Annotation(MethodInfoAID) {
|
||||
II->addAnnotation(new InstNumber(++InstNum, getValueSlot(II)));
|
||||
}
|
||||
|
||||
unsigned MethodInfo::getValueSlot(const Value *V) {
|
||||
unsigned FunctionInfo::getValueSlot(const Value *V) {
|
||||
unsigned Plane = V->getType()->getUniqueID();
|
||||
if (Plane >= NumPlaneElements.size())
|
||||
NumPlaneElements.resize(Plane+1, 0);
|
||||
@ -1036,15 +1036,15 @@ unsigned MethodInfo::getValueSlot(const Value *V) {
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// callMethod - Execute the specified function...
|
||||
// callFunction - Execute the specified function...
|
||||
//
|
||||
void Interpreter::callMethod(Function *F,
|
||||
const std::vector<GenericValue> &ArgVals) {
|
||||
void Interpreter::callFunction(Function *F,
|
||||
const std::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 (F->isExternal()) {
|
||||
GenericValue Result = callExternalMethod(F, ArgVals);
|
||||
GenericValue Result = callExternalFunction(F, ArgVals);
|
||||
const Type *RetTy = F->getReturnType();
|
||||
|
||||
// Copy the result back into the result variable if we are not returning
|
||||
@ -1074,23 +1074,24 @@ void Interpreter::callMethod(Function *F,
|
||||
// the function. Also calculate the number of values for each type slot
|
||||
// active.
|
||||
//
|
||||
MethodInfo *MethInfo = (MethodInfo*)F->getOrCreateAnnotation(MethodInfoAID);
|
||||
FunctionInfo *FuncInfo =
|
||||
(FunctionInfo*)F->getOrCreateAnnotation(FunctionInfoAID);
|
||||
ECStack.push_back(ExecutionContext()); // Make a new stack frame...
|
||||
|
||||
ExecutionContext &StackFrame = ECStack.back(); // Fill it in...
|
||||
StackFrame.CurMethod = F;
|
||||
StackFrame.CurFunction = F;
|
||||
StackFrame.CurBB = F->begin();
|
||||
StackFrame.CurInst = StackFrame.CurBB->begin();
|
||||
StackFrame.MethInfo = MethInfo;
|
||||
StackFrame.FuncInfo = FuncInfo;
|
||||
|
||||
// Initialize the values to nothing...
|
||||
StackFrame.Values.resize(MethInfo->NumPlaneElements.size());
|
||||
for (unsigned i = 0; i < MethInfo->NumPlaneElements.size(); ++i) {
|
||||
StackFrame.Values[i].resize(MethInfo->NumPlaneElements[i]);
|
||||
StackFrame.Values.resize(FuncInfo->NumPlaneElements.size());
|
||||
for (unsigned i = 0; i < FuncInfo->NumPlaneElements.size(); ++i) {
|
||||
StackFrame.Values[i].resize(FuncInfo->NumPlaneElements[i]);
|
||||
|
||||
// Taint the initial values of stuff
|
||||
memset(&StackFrame.Values[i][0], 42,
|
||||
MethInfo->NumPlaneElements[i]*sizeof(GenericValue));
|
||||
FuncInfo->NumPlaneElements[i]*sizeof(GenericValue));
|
||||
}
|
||||
|
||||
StackFrame.PrevBB = 0; // No previous BB for PHI nodes...
|
||||
@ -1345,7 +1346,7 @@ void Interpreter::infoValue(const std::string &Name) {
|
||||
//
|
||||
void Interpreter::printStackFrame(int FrameNo) {
|
||||
if (FrameNo == -1) FrameNo = CurFrame;
|
||||
Function *F = ECStack[FrameNo].CurMethod;
|
||||
Function *F = ECStack[FrameNo].CurFunction;
|
||||
const Type *RetTy = F->getReturnType();
|
||||
|
||||
CW << ((FrameNo == CurFrame) ? '>' : '-') << "#" << FrameNo << ". "
|
||||
|
@ -8,7 +8,7 @@
|
||||
#define LLI_EXECUTION_ANNOTATIONS_H
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Support for MethodInfo annotations
|
||||
// Support for FunctionInfo annotations
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// This annotation (attached only to Function objects) is used to cache useful
|
||||
@ -18,20 +18,19 @@
|
||||
// This annotation object is created on demand, and attaches other annotation
|
||||
// objects to the instructions in the function when it's created.
|
||||
//
|
||||
static AnnotationID MethodInfoAID(
|
||||
static AnnotationID FunctionInfoAID(
|
||||
AnnotationManager::getID("Interpreter::FunctionInfo"));
|
||||
|
||||
struct MethodInfo : public Annotation {
|
||||
MethodInfo(Function *F);
|
||||
struct FunctionInfo : public Annotation {
|
||||
FunctionInfo(Function *F);
|
||||
std::vector<unsigned> NumPlaneElements;
|
||||
|
||||
|
||||
// Create - Factory function to allow MethodInfo annotations to be
|
||||
// Create - Factory function to allow FunctionInfo annotations to be
|
||||
// created on demand.
|
||||
//
|
||||
static Annotation *Create(AnnotationID AID, const Annotable *O, void *) {
|
||||
assert(AID == MethodInfoAID);
|
||||
return new MethodInfo(cast<Function>((Value*)O)); // Simply invoke the ctor
|
||||
assert(AID == FunctionInfoAID);
|
||||
return new FunctionInfo(cast<Function>((Value*)O));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -47,7 +46,7 @@ private:
|
||||
// hold the the slot number for the value in its type plane.
|
||||
//
|
||||
// Entities have this annotation attached to them when the containing
|
||||
// function has it's MethodInfo created (by the MethodInfo ctor).
|
||||
// function has it's FunctionInfo created (by the FunctionInfo ctor).
|
||||
//
|
||||
static AnnotationID SlotNumberAID(
|
||||
AnnotationManager::getID("Interpreter::SlotNumber"));
|
||||
@ -72,7 +71,7 @@ struct SlotNumber : public Annotation {
|
||||
// calculating which value slot to store the result of the instruction in.
|
||||
//
|
||||
// Instructions have this annotation attached to them when the containing
|
||||
// function has it's MethodInfo created (by the MethodInfo ctor).
|
||||
// function has it's FunctionInfo created (by the FunctionInfo ctor).
|
||||
//
|
||||
struct InstNumber : public SlotNumber {
|
||||
unsigned InstNum; // Ranges from 1->
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
using std::vector;
|
||||
using std::cout;
|
||||
|
||||
typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
|
||||
static std::map<const Function *, ExFunc> Functions;
|
||||
@ -78,7 +77,7 @@ static ExFunc lookupFunction(const Function *M) {
|
||||
ExtName += getTypeID(Ty);
|
||||
ExtName += "_" + M->getName();
|
||||
|
||||
//cout << "Tried: '" << ExtName << "'\n";
|
||||
//std::cout << "Tried: '" << ExtName << "'\n";
|
||||
ExFunc FnPtr = FuncNames[ExtName];
|
||||
if (FnPtr == 0)
|
||||
FnPtr = (ExFunc)dlsym(RTLD_DEFAULT, ExtName.c_str());
|
||||
@ -91,7 +90,7 @@ static ExFunc lookupFunction(const Function *M) {
|
||||
return FnPtr;
|
||||
}
|
||||
|
||||
GenericValue Interpreter::callExternalMethod(Function *M,
|
||||
GenericValue Interpreter::callExternalFunction(Function *M,
|
||||
const vector<GenericValue> &ArgVals) {
|
||||
TheInterpreter = this;
|
||||
|
||||
@ -100,8 +99,8 @@ GenericValue Interpreter::callExternalMethod(Function *M,
|
||||
std::map<const Function *, ExFunc>::iterator FI = Functions.find(M);
|
||||
ExFunc Fn = (FI == Functions.end()) ? lookupFunction(M) : FI->second;
|
||||
if (Fn == 0) {
|
||||
cout << "Tried to execute an unknown external function: "
|
||||
<< M->getType()->getDescription() << " " << M->getName() << "\n";
|
||||
std::cout << "Tried to execute an unknown external function: "
|
||||
<< M->getType()->getDescription() << " " << M->getName() << "\n";
|
||||
return GenericValue();
|
||||
}
|
||||
|
||||
@ -117,85 +116,21 @@ GenericValue Interpreter::callExternalMethod(Function *M,
|
||||
//
|
||||
extern "C" { // Don't add C++ manglings to llvm mangling :)
|
||||
|
||||
// Implement void printstr([ubyte {x N}] *)
|
||||
GenericValue lle_VP_printstr(FunctionType *M,
|
||||
const vector<GenericValue> &ArgVal){
|
||||
assert(ArgVal.size() == 1 && "printstr only takes one argument!");
|
||||
cout << (char*)GVTOP(ArgVal[0]);
|
||||
return GenericValue();
|
||||
}
|
||||
|
||||
// Implement 'void print(X)' for every type...
|
||||
GenericValue lle_X_print(FunctionType *M, const vector<GenericValue> &ArgVals) {
|
||||
assert(ArgVals.size() == 1 && "generic print only takes one argument!");
|
||||
|
||||
Interpreter::print(M->getParamTypes()[0], ArgVals[0]);
|
||||
return GenericValue();
|
||||
}
|
||||
|
||||
// Implement 'void printVal(X)' for every type...
|
||||
GenericValue lle_X_printVal(FunctionType *M,
|
||||
const vector<GenericValue> &ArgVal) {
|
||||
assert(ArgVal.size() == 1 && "generic print only takes one argument!");
|
||||
|
||||
// Specialize print([ubyte {x N} ] *) and print(sbyte *)
|
||||
if (const PointerType *PTy =
|
||||
dyn_cast<PointerType>(M->getParamTypes()[0].get()))
|
||||
if (PTy->getElementType() == Type::SByteTy ||
|
||||
isa<ArrayType>(PTy->getElementType())) {
|
||||
return lle_VP_printstr(M, ArgVal);
|
||||
}
|
||||
|
||||
Interpreter::printValue(M->getParamTypes()[0], ArgVal[0]);
|
||||
return GenericValue();
|
||||
}
|
||||
|
||||
// Implement 'void printString(X)'
|
||||
// Argument must be [ubyte {x N} ] * or sbyte *
|
||||
GenericValue lle_X_printString(FunctionType *M,
|
||||
const vector<GenericValue> &ArgVal) {
|
||||
assert(ArgVal.size() == 1 && "generic print only takes one argument!");
|
||||
return lle_VP_printstr(M, ArgVal);
|
||||
}
|
||||
|
||||
// Implement 'void print<TYPE>(X)' for each primitive type or pointer type
|
||||
#define PRINT_TYPE_FUNC(TYPENAME,TYPEID) \
|
||||
GenericValue lle_X_print##TYPENAME(FunctionType *M,\
|
||||
const vector<GenericValue> &ArgVal) {\
|
||||
assert(ArgVal.size() == 1 && "generic print only takes one argument!");\
|
||||
assert(M->getParamTypes()[0].get()->getPrimitiveID() == Type::TYPEID);\
|
||||
Interpreter::printValue(M->getParamTypes()[0], ArgVal[0]);\
|
||||
return GenericValue();\
|
||||
}
|
||||
|
||||
PRINT_TYPE_FUNC(SByte, SByteTyID)
|
||||
PRINT_TYPE_FUNC(UByte, UByteTyID)
|
||||
PRINT_TYPE_FUNC(Short, ShortTyID)
|
||||
PRINT_TYPE_FUNC(UShort, UShortTyID)
|
||||
PRINT_TYPE_FUNC(Int, IntTyID)
|
||||
PRINT_TYPE_FUNC(UInt, UIntTyID)
|
||||
PRINT_TYPE_FUNC(Long, LongTyID)
|
||||
PRINT_TYPE_FUNC(ULong, ULongTyID)
|
||||
PRINT_TYPE_FUNC(Float, FloatTyID)
|
||||
PRINT_TYPE_FUNC(Double, DoubleTyID)
|
||||
PRINT_TYPE_FUNC(Pointer, PointerTyID)
|
||||
|
||||
|
||||
// void putchar(sbyte)
|
||||
GenericValue lle_Vb_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
cout << Args[0].SByteVal;
|
||||
std::cout << Args[0].SByteVal;
|
||||
return GenericValue();
|
||||
}
|
||||
|
||||
// int putchar(int)
|
||||
GenericValue lle_ii_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
cout << ((char)Args[0].IntVal) << std::flush;
|
||||
std::cout << ((char)Args[0].IntVal) << std::flush;
|
||||
return Args[0];
|
||||
}
|
||||
|
||||
// void putchar(ubyte)
|
||||
GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
cout << Args[0].SByteVal << std::flush;
|
||||
std::cout << Args[0].SByteVal << std::flush;
|
||||
return Args[0];
|
||||
}
|
||||
|
||||
@ -395,7 +330,7 @@ GenericValue lle_X_sprintf(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
sprintf(Buffer, FmtBuf, (void*)GVTOP(Args[ArgNo++])); break;
|
||||
case 's':
|
||||
sprintf(Buffer, FmtBuf, (char*)GVTOP(Args[ArgNo++])); break;
|
||||
default: cout << "<unknown printf code '" << *FmtStr << "'!>";
|
||||
default: std::cout << "<unknown printf code '" << *FmtStr << "'!>";
|
||||
ArgNo++; break;
|
||||
}
|
||||
strcpy(OutputBuffer, Buffer);
|
||||
@ -413,7 +348,7 @@ GenericValue lle_X_printf(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
NewArgs.push_back(PTOGV(Buffer));
|
||||
NewArgs.insert(NewArgs.end(), Args.begin(), Args.end());
|
||||
GenericValue GV = lle_X_sprintf(M, NewArgs);
|
||||
cout << Buffer;
|
||||
std::cout << Buffer;
|
||||
return GV;
|
||||
}
|
||||
|
||||
@ -763,22 +698,7 @@ GenericValue lle_X_fprintf(FunctionType *M, const vector<GenericValue> &Args) {
|
||||
} // End extern "C"
|
||||
|
||||
|
||||
void Interpreter::initializeExternalMethods() {
|
||||
FuncNames["lle_VP_printstr"] = lle_VP_printstr;
|
||||
FuncNames["lle_X_print"] = lle_X_print;
|
||||
FuncNames["lle_X_printVal"] = lle_X_printVal;
|
||||
FuncNames["lle_X_printString"] = lle_X_printString;
|
||||
FuncNames["lle_X_printUByte"] = lle_X_printUByte;
|
||||
FuncNames["lle_X_printSByte"] = lle_X_printSByte;
|
||||
FuncNames["lle_X_printUShort"] = lle_X_printUShort;
|
||||
FuncNames["lle_X_printShort"] = lle_X_printShort;
|
||||
FuncNames["lle_X_printInt"] = lle_X_printInt;
|
||||
FuncNames["lle_X_printUInt"] = lle_X_printUInt;
|
||||
FuncNames["lle_X_printLong"] = lle_X_printLong;
|
||||
FuncNames["lle_X_printULong"] = lle_X_printULong;
|
||||
FuncNames["lle_X_printFloat"] = lle_X_printFloat;
|
||||
FuncNames["lle_X_printDouble"] = lle_X_printDouble;
|
||||
FuncNames["lle_X_printPointer"] = lle_X_printPointer;
|
||||
void Interpreter::initializeExternalFunctions() {
|
||||
FuncNames["lle_Vb_putchar"] = lle_Vb_putchar;
|
||||
FuncNames["lle_ii_putchar"] = lle_ii_putchar;
|
||||
FuncNames["lle_VB_putchar"] = lle_VB_putchar;
|
||||
@ -810,7 +730,7 @@ void Interpreter::initializeExternalMethods() {
|
||||
FuncNames["lle_X_strcat"] = lle_X_strcat;
|
||||
FuncNames["lle_X_strcpy"] = lle_X_strcpy;
|
||||
FuncNames["lle_X_strlen"] = lle_X_strlen;
|
||||
FuncNames["lle_X___strdup"] = lle_X___strdup;
|
||||
FuncNames["lle_X___strdup"] = lle_X___strdup;
|
||||
FuncNames["lle_X_memset"] = lle_X_memset;
|
||||
FuncNames["lle_X_memcpy"] = lle_X_memcpy;
|
||||
|
||||
|
@ -32,7 +32,7 @@ Interpreter::Interpreter(Module *M, unsigned Config,
|
||||
setTargetData(TD);
|
||||
// Initialize the "backend"
|
||||
initializeExecutionEngine();
|
||||
initializeExternalMethods();
|
||||
initializeExternalFunctions();
|
||||
CW.setModule(M); // Update Writer
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ int Interpreter::run(const std::string &MainFunction,
|
||||
const std::vector<std::string> &Args) {
|
||||
// Start interpreter into the main function...
|
||||
//
|
||||
if (!callMainMethod(MainFunction, Args) && !Debug) {
|
||||
if (!callMainFunction(MainFunction, Args) && !Debug) {
|
||||
// If not in debug mode and if the call succeeded, run the code now...
|
||||
run();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
extern CachedWriter CW; // Object to accelerate printing of LLVM
|
||||
|
||||
struct MethodInfo; // Defined in ExecutionAnnotations.h
|
||||
struct FunctionInfo; // Defined in ExecutionAnnotations.h
|
||||
class CallInst;
|
||||
class ReturnInst;
|
||||
class BranchInst;
|
||||
@ -63,10 +63,10 @@ typedef std::vector<GenericValue> ValuePlaneTy;
|
||||
// executing.
|
||||
//
|
||||
struct ExecutionContext {
|
||||
Function *CurMethod; // The currently executing function
|
||||
Function *CurFunction;// The currently executing function
|
||||
BasicBlock *CurBB; // The currently executing BB
|
||||
BasicBlock::iterator CurInst; // The next instruction to execute
|
||||
MethodInfo *MethInfo; // The MethInfo annotation for the function
|
||||
FunctionInfo *FuncInfo; // The FuncInfo annotation for the function
|
||||
std::vector<ValuePlaneTy> Values;// ValuePlanes for each type
|
||||
std::vector<GenericValue> VarArgs; // Values passed through an ellipsis
|
||||
|
||||
@ -111,21 +111,21 @@ public:
|
||||
void handleUserInput();
|
||||
|
||||
// User Interation Methods...
|
||||
bool callMethod(const std::string &Name); // return true on failure
|
||||
bool callFunction(const std::string &Name); // return true on failure
|
||||
void setBreakpoint(const std::string &Name);
|
||||
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);
|
||||
|
||||
bool callMainMethod(const std::string &MainName,
|
||||
const std::vector<std::string> &InputFilename);
|
||||
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 callMethod(Function *F, const std::vector<GenericValue> &ArgVals);
|
||||
void callFunction(Function *F, const std::vector<GenericValue> &ArgVals);
|
||||
bool executeInstruction(); // Execute one instruction...
|
||||
|
||||
void stepInstruction(); // Do the 'step' command
|
||||
@ -138,13 +138,13 @@ public:
|
||||
void executeRetInst(ReturnInst &I, ExecutionContext &SF);
|
||||
void executeBrInst(BranchInst &I, ExecutionContext &SF);
|
||||
void executeAllocInst(AllocationInst &I, ExecutionContext &SF);
|
||||
GenericValue callExternalMethod(Function *F,
|
||||
const std::vector<GenericValue> &ArgVals);
|
||||
GenericValue callExternalFunction(Function *F,
|
||||
const std::vector<GenericValue> &ArgVals);
|
||||
void exitCalled(GenericValue GV);
|
||||
|
||||
// getCurrentMethod - Return the currently executing method
|
||||
inline Function *getCurrentMethod() const {
|
||||
return CurFrame < 0 ? 0 : ECStack[CurFrame].CurMethod;
|
||||
// getCurrentFunction - Return the currently executing function
|
||||
inline Function *getCurrentFunction() const {
|
||||
return CurFrame < 0 ? 0 : ECStack[CurFrame].CurFunction;
|
||||
}
|
||||
|
||||
// isStopped - Return true if a program is stopped. Return false if no
|
||||
@ -194,7 +194,7 @@ private: // Helper functions
|
||||
|
||||
|
||||
void initializeExecutionEngine();
|
||||
void initializeExternalMethods();
|
||||
void initializeExternalFunctions();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -8,8 +8,6 @@
|
||||
#include "llvm/SymbolTable.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Module.h"
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
@ -36,9 +34,9 @@ static inline void LookupMatchingNames(const std::string &Name,
|
||||
//
|
||||
std::vector<Value*> Interpreter::LookupMatchingNames(const std::string &Name) {
|
||||
std::vector<Value*> Results;
|
||||
Function *CurMeth = getCurrentMethod();
|
||||
Function *CurFunc = getCurrentFunction();
|
||||
|
||||
if (CurMeth) ::LookupMatchingNames(Name, CurMeth->getSymbolTable(), Results);
|
||||
if (CurFunc) ::LookupMatchingNames(Name, CurFunc->getSymbolTable(), Results);
|
||||
::LookupMatchingNames(Name, getModule().getSymbolTable(), Results);
|
||||
return Results;
|
||||
}
|
||||
@ -52,25 +50,26 @@ Value *Interpreter::ChooseOneOption(const std::string &Name,
|
||||
switch (Opts.size()) {
|
||||
case 1: return Opts[0];
|
||||
case 0:
|
||||
cout << "Error: no entities named '" << Name << "' found!\n";
|
||||
std::cout << "Error: no entities named '" << Name << "' found!\n";
|
||||
return 0;
|
||||
default: break; // Must prompt user...
|
||||
}
|
||||
|
||||
cout << "Multiple entities named '" << Name << "' found! Please choose:\n";
|
||||
cout << " 0. Cancel operation\n";
|
||||
std::cout << "Multiple entities named '" << Name
|
||||
<< "' found! Please choose:\n";
|
||||
std::cout << " 0. Cancel operation\n";
|
||||
for (unsigned i = 0; i < Opts.size(); ++i) {
|
||||
cout << " " << (i+1) << ".";
|
||||
WriteAsOperand(cout, Opts[i]) << "\n";
|
||||
std::cout << " " << (i+1) << ".";
|
||||
WriteAsOperand(std::cout, Opts[i]) << "\n";
|
||||
}
|
||||
|
||||
unsigned Option;
|
||||
do {
|
||||
cout << "lli> " << std::flush;
|
||||
std::cout << "lli> " << std::flush;
|
||||
std::cin >> Option;
|
||||
if (Option > Opts.size())
|
||||
cout << "Invalid selection: Please choose from 0 to " << Opts.size()
|
||||
<< "\n";
|
||||
std::cout << "Invalid selection: Please choose from 0 to " << Opts.size()
|
||||
<< "\n";
|
||||
} while (Option > Opts.size());
|
||||
|
||||
if (Option == 0) return 0;
|
||||
|
@ -10,9 +10,6 @@
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/Transforms/Utils/Linker.h"
|
||||
#include <algorithm>
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
|
||||
enum CommandID {
|
||||
Quit, Help, // Basics
|
||||
@ -29,10 +26,10 @@ static struct CommandTableElement {
|
||||
enum CommandID CID;
|
||||
|
||||
inline bool operator<(const CommandTableElement &E) const {
|
||||
return string(Name) < string(E.Name);
|
||||
return std::string(Name) < std::string(E.Name);
|
||||
}
|
||||
inline bool operator==(const string &S) const {
|
||||
return string(Name) == S;
|
||||
inline bool operator==(const std::string &S) const {
|
||||
return std::string(Name) == S;
|
||||
}
|
||||
} CommandTable[] = {
|
||||
{ "quit" , Quit }, { "q", Quit }, { "", Quit }, // Empty str = eof
|
||||
@ -76,25 +73,25 @@ void Interpreter::handleUserInput() {
|
||||
printCurrentInstruction();
|
||||
|
||||
do {
|
||||
string Command;
|
||||
cout << "lli> " << std::flush;
|
||||
cin >> Command;
|
||||
std::string Command;
|
||||
std::cout << "lli> " << std::flush;
|
||||
std::cin >> Command;
|
||||
|
||||
CommandTableElement *E = find(CommandTable, CommandTableEnd, Command);
|
||||
|
||||
if (E == CommandTableEnd) {
|
||||
cout << "Error: '" << Command << "' not recognized!\n";
|
||||
std::cout << "Error: '" << Command << "' not recognized!\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (E->CID) {
|
||||
case Quit: UserQuit = true; break;
|
||||
case Print:
|
||||
cin >> Command;
|
||||
std::cin >> Command;
|
||||
print(Command);
|
||||
break;
|
||||
case Info:
|
||||
cin >> Command;
|
||||
std::cin >> Command;
|
||||
infoValue(Command);
|
||||
break;
|
||||
|
||||
@ -102,32 +99,32 @@ void Interpreter::handleUserInput() {
|
||||
case StackTrace: printStackTrace(); break;
|
||||
case Up:
|
||||
if (CurFrame > 0) { --CurFrame; printStackFrame(); }
|
||||
else cout << "Error: Already at root of stack!\n";
|
||||
else std::cout << "Error: Already at root of stack!\n";
|
||||
break;
|
||||
case Down:
|
||||
if ((unsigned)CurFrame < ECStack.size()-1) {
|
||||
++CurFrame;
|
||||
printStackFrame();
|
||||
} else
|
||||
cout << "Error: Already at bottom of stack!\n";
|
||||
std::cout << "Error: Already at bottom of stack!\n";
|
||||
break;
|
||||
case Next: nextInstruction(); break;
|
||||
case Step: stepInstruction(); break;
|
||||
case Run: run(); break;
|
||||
case Finish: finish(); break;
|
||||
case Call:
|
||||
cin >> Command;
|
||||
callMethod(Command); // Enter the specified function
|
||||
std::cin >> Command;
|
||||
callFunction(Command); // Enter the specified function
|
||||
finish(); // Run until it's complete
|
||||
break;
|
||||
|
||||
case TraceOpt:
|
||||
Trace = !Trace;
|
||||
cout << "Tracing " << (Trace ? "enabled\n" : "disabled\n");
|
||||
std::cout << "Tracing " << (Trace ? "enabled\n" : "disabled\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
cout << "Command '" << Command << "' unimplemented!\n";
|
||||
std::cout << "Command '" << Command << "' unimplemented!\n";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -137,15 +134,15 @@ void Interpreter::handleUserInput() {
|
||||
//===----------------------------------------------------------------------===//
|
||||
// setBreakpoint - Enable a breakpoint at the specified location
|
||||
//
|
||||
void Interpreter::setBreakpoint(const string &Name) {
|
||||
void Interpreter::setBreakpoint(const std::string &Name) {
|
||||
Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name));
|
||||
// TODO: Set a breakpoint on PickedVal
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// callMethod - Enter the specified method...
|
||||
// callFunction - Enter the specified function...
|
||||
//
|
||||
bool Interpreter::callMethod(const string &Name) {
|
||||
bool Interpreter::callFunction(const std::string &Name) {
|
||||
std::vector<Value*> Options = LookupMatchingNames(Name);
|
||||
|
||||
for (unsigned i = 0; i < Options.size(); ++i) { // Remove non-fn matches...
|
||||
@ -164,7 +161,7 @@ bool Interpreter::callMethod(const string &Name) {
|
||||
std::vector<GenericValue> Args;
|
||||
// TODO, get args from user...
|
||||
|
||||
callMethod(F, Args); // Start executing it...
|
||||
callFunction(F, Args); // Start executing it...
|
||||
|
||||
// Reset the current frame location to the top of stack
|
||||
CurFrame = ECStack.size()-1;
|
||||
@ -172,11 +169,11 @@ bool Interpreter::callMethod(const string &Name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// callMainMethod - This is a nasty gross hack that will dissapear when
|
||||
// callMethod can parse command line options and stuff for us.
|
||||
// callMainFunction - This is a nasty gross hack that will dissapear when
|
||||
// callFunction can parse command line options and stuff for us.
|
||||
//
|
||||
bool Interpreter::callMainMethod(const string &Name,
|
||||
const std::vector<string> &InputArgv) {
|
||||
bool Interpreter::callMainFunction(const std::string &Name,
|
||||
const std::vector<std::string> &InputArgv) {
|
||||
std::vector<Value*> Options = LookupMatchingNames(Name);
|
||||
|
||||
for (unsigned i = 0; i < Options.size(); ++i) { // Remove non-fn matches...
|
||||
@ -196,7 +193,8 @@ bool Interpreter::callMainMethod(const string &Name,
|
||||
std::vector<GenericValue> Args;
|
||||
switch (MT->getParamTypes().size()) {
|
||||
default:
|
||||
cout << "Unknown number of arguments to synthesize for '" << Name << "'!\n";
|
||||
std::cout << "Unknown number of arguments to synthesize for '" << Name
|
||||
<< "'!\n";
|
||||
return true;
|
||||
case 2: {
|
||||
PointerType *SPP = PointerType::get(PointerType::get(Type::SByteTy));
|
||||
@ -211,7 +209,7 @@ bool Interpreter::callMainMethod(const string &Name,
|
||||
// fallthrough
|
||||
case 1:
|
||||
if (!MT->getParamTypes()[0]->isInteger()) {
|
||||
cout << "First argument of '" << Name << "' should be an integer!\n";
|
||||
std::cout << "First argument of '" << Name << "' should be an integer!\n";
|
||||
return true;
|
||||
} else {
|
||||
GenericValue GV; GV.UIntVal = InputArgv.size();
|
||||
@ -222,7 +220,7 @@ bool Interpreter::callMainMethod(const string &Name,
|
||||
break;
|
||||
}
|
||||
|
||||
callMethod(M, Args); // Start executing it...
|
||||
callFunction(M, Args); // Start executing it...
|
||||
|
||||
// Reset the current frame location to the top of stack
|
||||
CurFrame = ECStack.size()-1;
|
||||
@ -234,13 +232,13 @@ bool Interpreter::callMainMethod(const string &Name,
|
||||
|
||||
void Interpreter::list() {
|
||||
if (ECStack.empty())
|
||||
cout << "Error: No program executing!\n";
|
||||
std::cout << "Error: No program executing!\n";
|
||||
else
|
||||
CW << ECStack[CurFrame].CurMethod; // Just print the function out...
|
||||
CW << ECStack[CurFrame].CurFunction; // Just print the function out...
|
||||
}
|
||||
|
||||
void Interpreter::printStackTrace() {
|
||||
if (ECStack.empty()) cout << "No program executing!\n";
|
||||
if (ECStack.empty()) std::cout << "No program executing!\n";
|
||||
|
||||
for (unsigned i = 0; i < ECStack.size(); ++i) {
|
||||
printStackFrame((int)i);
|
||||
|
Loading…
Reference in New Issue
Block a user