summaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine/Interpreter
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-10-15 13:25:40 +0000
committerChris Lattner <sabre@nondot.org>2001-10-15 13:25:40 +0000
commit39bb5b4ee9f7b0b36f3c304a2c813e38fa4db81f (patch)
treeb3db84ee69c8723ff2d4d23cec4d662fb011f79f /lib/ExecutionEngine/Interpreter
parentc18545dc9e5c8d98ea9089af8702a6cf563a8dfd (diff)
downloadexternal_llvm-39bb5b4ee9f7b0b36f3c304a2c813e38fa4db81f.zip
external_llvm-39bb5b4ee9f7b0b36f3c304a2c813e38fa4db81f.tar.gz
external_llvm-39bb5b4ee9f7b0b36f3c304a2c813e38fa4db81f.tar.bz2
Implement initializers for structs and pointers
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@823 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/Interpreter')
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp180
1 files changed, 100 insertions, 80 deletions
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index 668ef6d..77f82e0 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -22,6 +22,80 @@
static TargetData TD("lli Interpreter");
//===----------------------------------------------------------------------===//
+// Value Manipulation code
+//===----------------------------------------------------------------------===//
+
+static unsigned getOperandSlot(Value *V) {
+ SlotNumber *SN = (SlotNumber*)V->getAnnotation(SlotNumberAID);
+ assert(SN && "Operand does not have a slot number annotation!");
+ return SN->SlotNum;
+}
+
+#define GET_CONST_VAL(TY, CLASS) \
+ case Type::TY##TyID: Result.TY##Val = cast<CLASS>(CPV)->getValue(); break
+
+static GenericValue getOperandValue(Value *V, ExecutionContext &SF) {
+ if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {
+ GenericValue Result;
+ switch (CPV->getType()->getPrimitiveID()) {
+ GET_CONST_VAL(Bool , ConstPoolBool);
+ GET_CONST_VAL(UByte , ConstPoolUInt);
+ GET_CONST_VAL(SByte , ConstPoolSInt);
+ GET_CONST_VAL(UShort , ConstPoolUInt);
+ GET_CONST_VAL(Short , ConstPoolSInt);
+ GET_CONST_VAL(UInt , ConstPoolUInt);
+ GET_CONST_VAL(Int , ConstPoolSInt);
+ GET_CONST_VAL(Float , ConstPoolFP);
+ GET_CONST_VAL(Double , ConstPoolFP);
+ case Type::PointerTyID:
+ if (isa<ConstPoolPointerNull>(CPV)) {
+ Result.PointerVal = 0;
+ } else if (ConstPoolPointerRef *CPR =dyn_cast<ConstPoolPointerRef>(CPV)) {
+ assert(0 && "Not implemented!");
+ } else {
+ assert(0 && "Unknown constant pointer type!");
+ }
+ break;
+ default:
+ cout << "ERROR: Constant unimp for type: " << CPV->getType() << endl;
+ }
+ return Result;
+ } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
+ GlobalAddress *Address =
+ (GlobalAddress*)GV->getOrCreateAnnotation(GlobalAddressAID);
+ GenericValue Result;
+ Result.PointerVal = (GenericValue*)Address->Ptr;
+ return Result;
+ } else {
+ unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
+ return SF.Values[TyP][getOperandSlot(V)];
+ }
+}
+
+static void printOperandInfo(Value *V, ExecutionContext &SF) {
+ if (isa<ConstPoolVal>(V)) {
+ cout << "Constant Pool Value\n";
+ } else if (isa<GlobalValue>(V)) {
+ cout << "Global Value\n";
+ } else {
+ unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
+ unsigned Slot = getOperandSlot(V);
+ cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot
+ << " Addr=" << &SF.Values[TyP][Slot] << " SF=" << &SF << endl;
+ }
+}
+
+
+
+static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) {
+ unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
+
+ //cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)] << endl;
+ SF.Values[TyP][getOperandSlot(V)] = Val;
+}
+
+
+//===----------------------------------------------------------------------===//
// Annotation Wrangling code
//===----------------------------------------------------------------------===//
@@ -36,10 +110,10 @@ void Interpreter::initializeExecutionEngine() {
// specified memory location...
//
static void InitializeMemory(ConstPoolVal *Init, char *Addr) {
-#define INITIALIZE_MEMORY(TYID, CLASS, TY) \
- case Type::TYID##TyID: { \
+#define INITIALIZE_MEMORY(TYID, CLASS, TY) \
+ case Type::TYID##TyID: { \
TY Tmp = cast<CLASS>(Init)->getValue(); \
- memcpy(Addr, &Tmp, sizeof(TY)); \
+ memcpy(Addr, &Tmp, sizeof(TY)); \
} return
switch (Init->getType()->getPrimitiveID()) {
@@ -55,6 +129,7 @@ static void InitializeMemory(ConstPoolVal *Init, char *Addr) {
INITIALIZE_MEMORY(Float , ConstPoolFP , float);
INITIALIZE_MEMORY(Double , ConstPoolFP , double);
#undef INITIALIZE_MEMORY
+
case Type::ArrayTyID: {
ConstPoolArray *CPA = cast<ConstPoolArray>(Init);
const vector<Use> &Val = CPA->getValues();
@@ -64,9 +139,29 @@ static void InitializeMemory(ConstPoolVal *Init, char *Addr) {
InitializeMemory(cast<ConstPoolVal>(Val[i].get()), Addr+i*ElementSize);
return;
}
- // TODO: Struct and Pointer!
- case Type::StructTyID:
+
+ case Type::StructTyID: {
+ ConstPoolStruct *CPS = cast<ConstPoolStruct>(Init);
+ const StructLayout *SL=TD.getStructLayout(cast<StructType>(CPS->getType()));
+ const vector<Use> &Val = CPS->getValues();
+ for (unsigned i = 0; i < Val.size(); ++i)
+ InitializeMemory(cast<ConstPoolVal>(Val[i].get()),
+ Addr+SL->MemberOffsets[i]);
+ return;
+ }
+
case Type::PointerTyID:
+ if (isa<ConstPoolPointerNull>(Init)) {
+ *(void**)Addr = 0;
+ } else if (ConstPoolPointerRef *CPR = dyn_cast<ConstPoolPointerRef>(Init)) {
+ GlobalAddress *Address =
+ (GlobalAddress*)CPR->getValue()->getOrCreateAnnotation(GlobalAddressAID);
+ *(void**)Addr = (GenericValue*)Address->Ptr;
+ } else {
+ assert(0 && "Unknown Constant pointer type!");
+ }
+ return;
+
default:
cout << "Bad Type: " << Init->getType()->getDescription() << endl;
assert(0 && "Unknown constant type to initialize memory with!");
@@ -114,81 +209,6 @@ Annotation *GlobalAddress::Create(AnnotationID AID, const Annotable *O, void *){
return new GlobalAddress(Addr, true); // Simply invoke the ctor
}
-//===----------------------------------------------------------------------===//
-// Value Manipulation code
-//===----------------------------------------------------------------------===//
-
-static unsigned getOperandSlot(Value *V) {
- SlotNumber *SN = (SlotNumber*)V->getAnnotation(SlotNumberAID);
- assert(SN && "Operand does not have a slot number annotation!");
- return SN->SlotNum;
-}
-
-#define GET_CONST_VAL(TY, CLASS) \
- case Type::TY##TyID: Result.TY##Val = cast<CLASS>(CPV)->getValue(); break
-
-static GenericValue getOperandValue(Value *V, ExecutionContext &SF) {
- if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {
- GenericValue Result;
- switch (CPV->getType()->getPrimitiveID()) {
- GET_CONST_VAL(Bool , ConstPoolBool);
- GET_CONST_VAL(UByte , ConstPoolUInt);
- GET_CONST_VAL(SByte , ConstPoolSInt);
- GET_CONST_VAL(UShort , ConstPoolUInt);
- GET_CONST_VAL(Short , ConstPoolSInt);
- GET_CONST_VAL(UInt , ConstPoolUInt);
- GET_CONST_VAL(Int , ConstPoolSInt);
- GET_CONST_VAL(Float , ConstPoolFP);
- GET_CONST_VAL(Double , ConstPoolFP);
- case Type::PointerTyID:
- if (isa<ConstPoolPointerNull>(CPV)) {
- Result.PointerVal = 0;
- } else if (ConstPoolPointerReference *CPR =
- dyn_cast<ConstPoolPointerReference>(CPV)) {
- assert(0 && "Not implemented!");
- } else {
- assert(0 && "Unknown constant pointer type!");
- }
- break;
- default:
- cout << "ERROR: Constant unimp for type: " << CPV->getType() << endl;
- }
- return Result;
- } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
- GlobalAddress *Address =
- (GlobalAddress*)GV->getOrCreateAnnotation(GlobalAddressAID);
- GenericValue Result;
- Result.PointerVal = (GenericValue*)Address->Ptr;
- return Result;
- } else {
- unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
- return SF.Values[TyP][getOperandSlot(V)];
- }
-}
-
-static void printOperandInfo(Value *V, ExecutionContext &SF) {
- if (isa<ConstPoolVal>(V)) {
- cout << "Constant Pool Value\n";
- } else if (isa<GlobalValue>(V)) {
- cout << "Global Value\n";
- } else {
- unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
- unsigned Slot = getOperandSlot(V);
- cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot
- << " Addr=" << &SF.Values[TyP][Slot] << " SF=" << &SF << endl;
- }
-}
-
-
-
-static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) {
- unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
-
- //cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)] << endl;
- SF.Values[TyP][getOperandSlot(V)] = Val;
-}
-
-
//===----------------------------------------------------------------------===//
// Binary Instruction Implementations