[llvm-commits] CVS: llvm/tools/lli/Interpreter/Execution.cpp ExternalFunctions.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu May 8 11:53:04 PDT 2003


Changes in directory llvm/tools/lli/Interpreter:

Execution.cpp updated: 1.86 -> 1.87
ExternalFunctions.cpp updated: 1.50 -> 1.51

---
Log message:

Implement varargs support for LLI!


---
Diffs of the changes:

Index: llvm/tools/lli/Interpreter/Execution.cpp
diff -u llvm/tools/lli/Interpreter/Execution.cpp:1.86 llvm/tools/lli/Interpreter/Execution.cpp:1.87
--- llvm/tools/lli/Interpreter/Execution.cpp:1.86	Thu May  8 11:18:31 2003
+++ llvm/tools/lli/Interpreter/Execution.cpp	Thu May  8 11:52:43 2003
@@ -761,78 +761,7 @@
 void Interpreter::executeLoadInst(LoadInst &I, ExecutionContext &SF) {
   GenericValue SRC = getOperandValue(I.getPointerOperand(), SF);
   GenericValue *Ptr = (GenericValue*)GVTOP(SRC);
-  GenericValue Result;
-
-  if (TD.isLittleEndian()) {
-    switch (I.getType()->getPrimitiveID()) {
-    case Type::BoolTyID:
-    case Type::UByteTyID:
-    case Type::SByteTyID:   Result.UByteVal = Ptr->Untyped[0]; break;
-    case Type::UShortTyID:
-    case Type::ShortTyID:   Result.UShortVal = (unsigned)Ptr->Untyped[0] |
-                                              ((unsigned)Ptr->Untyped[1] << 8);
-                            break;
-    Load4BytesLittleEndian:                            
-    case Type::FloatTyID:
-    case Type::UIntTyID:
-    case Type::IntTyID:     Result.UIntVal = (unsigned)Ptr->Untyped[0] |
-                                            ((unsigned)Ptr->Untyped[1] <<  8) |
-                                            ((unsigned)Ptr->Untyped[2] << 16) |
-                                            ((unsigned)Ptr->Untyped[3] << 24);
-                            break;
-    case Type::PointerTyID: if (getModule().has32BitPointers())
-                              goto Load4BytesLittleEndian;
-    case Type::DoubleTyID:
-    case Type::ULongTyID:
-    case Type::LongTyID:    Result.ULongVal = (uint64_t)Ptr->Untyped[0] |
-                                             ((uint64_t)Ptr->Untyped[1] <<  8) |
-                                             ((uint64_t)Ptr->Untyped[2] << 16) |
-                                             ((uint64_t)Ptr->Untyped[3] << 24) |
-                                             ((uint64_t)Ptr->Untyped[4] << 32) |
-                                             ((uint64_t)Ptr->Untyped[5] << 40) |
-                                             ((uint64_t)Ptr->Untyped[6] << 48) |
-                                             ((uint64_t)Ptr->Untyped[7] << 56);
-                            break;
-    default:
-      std::cout << "Cannot load value of type " << *I.getType() << "!\n";
-      abort();
-    }
-  } else {
-    switch (I.getType()->getPrimitiveID()) {
-    case Type::BoolTyID:
-    case Type::UByteTyID:
-    case Type::SByteTyID:   Result.UByteVal = Ptr->Untyped[0]; break;
-    case Type::UShortTyID:
-    case Type::ShortTyID:   Result.UShortVal = (unsigned)Ptr->Untyped[1] |
-                                              ((unsigned)Ptr->Untyped[0] << 8);
-                            break;
-    Load4BytesBigEndian:
-    case Type::FloatTyID:
-    case Type::UIntTyID:
-    case Type::IntTyID:     Result.UIntVal = (unsigned)Ptr->Untyped[3] |
-                                            ((unsigned)Ptr->Untyped[2] <<  8) |
-                                            ((unsigned)Ptr->Untyped[1] << 16) |
-                                            ((unsigned)Ptr->Untyped[0] << 24);
-                            break;
-    case Type::PointerTyID: if (getModule().has32BitPointers())
-                              goto Load4BytesBigEndian;
-    case Type::DoubleTyID:
-    case Type::ULongTyID:
-    case Type::LongTyID:    Result.ULongVal = (uint64_t)Ptr->Untyped[7] |
-                                             ((uint64_t)Ptr->Untyped[6] <<  8) |
-                                             ((uint64_t)Ptr->Untyped[5] << 16) |
-                                             ((uint64_t)Ptr->Untyped[4] << 24) |
-                                             ((uint64_t)Ptr->Untyped[3] << 32) |
-                                             ((uint64_t)Ptr->Untyped[2] << 40) |
-                                             ((uint64_t)Ptr->Untyped[1] << 48) |
-                                             ((uint64_t)Ptr->Untyped[0] << 56);
-                            break;
-    default:
-      std::cout << "Cannot load value of type " << *I.getType() << "!\n";
-      abort();
-    }
-  }
-
+  GenericValue Result = LoadValueFromMemory(Ptr, I.getType());
   SetValue(&I, Result, SF);
 }
 
@@ -1009,6 +938,26 @@
   SetValue(&I, executeCastOperation(I.getOperand(0), I.getType(), SF), SF);
 }
 
+static void executeVarArgInst(VarArgInst &I, ExecutionContext &SF) {
+  // Get the pointer to the valist element.  LLI treats the valist in memory as
+  // an integer.
+  GenericValue VAListPtr = getOperandValue(I.getOperand(0), SF);
+
+  // Load the pointer
+  GenericValue VAList = 
+    TheEE->LoadValueFromMemory((GenericValue *)GVTOP(VAListPtr), Type::UIntTy);
+
+  unsigned Argument = VAList.IntVal++;
+
+  // Update the valist to point to the next argument...
+  TheEE->StoreValueToMemory(VAList, (GenericValue *)GVTOP(VAListPtr),
+                            Type::UIntTy);
+
+  // Set the value...
+  assert(Argument < SF.VarArgs.size() &&
+         "Accessing past the last vararg argument!");
+  SetValue(&I, SF.VarArgs[Argument], SF);
+}
 
 //===----------------------------------------------------------------------===//
 //                        Dispatch and Execution Code
@@ -1166,9 +1115,10 @@
       // Miscellaneous Instructions
     case Instruction::Call:    executeCallInst (cast<CallInst> (I), SF); break;
     case Instruction::PHINode: executePHINode  (cast<PHINode>  (I), SF); break;
+    case Instruction::Cast:    executeCastInst (cast<CastInst> (I), SF); break;
     case Instruction::Shl:     executeShlInst  (cast<ShiftInst>(I), SF); break;
     case Instruction::Shr:     executeShrInst  (cast<ShiftInst>(I), SF); break;
-    case Instruction::Cast:    executeCastInst (cast<CastInst> (I), SF); break;
+    case Instruction::VarArg:  executeVarArgInst(cast<VarArgInst>(I),SF); break;
     default:
       std::cout << "Don't know how to execute this instruction!\n-->" << I;
       abort();


Index: llvm/tools/lli/Interpreter/ExternalFunctions.cpp
diff -u llvm/tools/lli/Interpreter/ExternalFunctions.cpp:1.50 llvm/tools/lli/Interpreter/ExternalFunctions.cpp:1.51
--- llvm/tools/lli/Interpreter/ExternalFunctions.cpp:1.50	Thu May  8 11:18:31 2003
+++ llvm/tools/lli/Interpreter/ExternalFunctions.cpp	Thu May  8 11:52:43 2003
@@ -695,6 +695,35 @@
   return GV;
 }
 
+//===----------------------------------------------------------------------===//
+// LLVM Intrinsic Functions...
+//===----------------------------------------------------------------------===//
+
+// void llvm.va_start(<va_list> *) - Implement the va_start operation...
+GenericValue llvm_va_start(FunctionType *F, const vector<GenericValue> &Args) {
+  assert(Args.size() == 1);
+  GenericValue *VAListP = (GenericValue *)GVTOP(Args[0]);
+  GenericValue Val;
+  Val.UIntVal = 0;   // Start at the first '...' argument...
+  TheInterpreter->StoreValueToMemory(Val, VAListP, Type::UIntTy);
+  return GenericValue();
+}
+
+// void llvm.va_end(<va_list> *) - Implement the va_end operation...
+GenericValue llvm_va_end(FunctionType *F, const vector<GenericValue> &Args) {
+  assert(Args.size() == 1);
+  return GenericValue();    // Noop!
+}
+
+// void llvm.va_copy(<va_list> *, <va_list>) - Implement the va_copy
+// operation...
+GenericValue llvm_va_copy(FunctionType *F, const vector<GenericValue> &Args) {
+  assert(Args.size() == 2);
+  GenericValue *DestVAList = (GenericValue*)GVTOP(Args[0]);
+  TheInterpreter->StoreValueToMemory(Args[1], DestVAList, Type::UIntTy);
+  return GenericValue();
+}
+
 } // End extern "C"
 
 
@@ -748,4 +777,8 @@
   FuncNames["lle_X_ungetc"]       = lle_X_ungetc;
   FuncNames["lle_X_fprintf"]      = lle_X_fprintf;
   FuncNames["lle_X_freopen"]      = lle_X_freopen;
+
+  FuncNames["lle_X_llvm.va_start"]= llvm_va_start;
+  FuncNames["lle_X_llvm.va_end"]  = llvm_va_end;
+  FuncNames["lle_X_llvm.va_copy"] = llvm_va_copy;
 }





More information about the llvm-commits mailing list