[llvm-commits] CVS: llvm/lib/ExecutionEngine/JIT/JIT.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Aug 15 16:53:18 PDT 2004
Changes in directory llvm/lib/ExecutionEngine/JIT:
JIT.cpp updated: 1.40 -> 1.41
---
Log message:
Handle all nullary functions, of any valid return type.
---
Diffs of the changes: (+46 -7)
Index: llvm/lib/ExecutionEngine/JIT/JIT.cpp
diff -u llvm/lib/ExecutionEngine/JIT/JIT.cpp:1.40 llvm/lib/ExecutionEngine/JIT/JIT.cpp:1.41
--- llvm/lib/ExecutionEngine/JIT/JIT.cpp:1.40 Sun Aug 15 18:39:59 2004
+++ llvm/lib/ExecutionEngine/JIT/JIT.cpp Sun Aug 15 18:53:06 2004
@@ -59,14 +59,19 @@
GenericValue JIT::runFunction(Function *F,
const std::vector<GenericValue> &ArgValues) {
assert(F && "Function *F was null at entry to run()");
- GenericValue rv;
void *FPtr = getPointerToFunction(F);
assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
- const Type *RetTy = F->getReturnType();
const FunctionType *FTy = F->getFunctionType();
+ const Type *RetTy = FTy->getReturnType();
- // Handle some common cases first.
+ assert((FTy->getNumParams() <= ArgValues.size() || FTy->isVarArg()) &&
+ "Too many arguments passed into function!");
+ assert(FTy->getNumParams() == ArgValues.size() &&
+ "This doesn't support passing arguments through varargs (yet)!");
+
+ // Handle some common cases first. These cases correspond to common 'main'
+ // prototypes.
if (RetTy == Type::IntTy || RetTy == Type::UIntTy || RetTy == Type::VoidTy) {
switch (ArgValues.size()) {
case 3:
@@ -79,6 +84,7 @@
(int(*)(int, char **, const char **))FPtr;
// Call the function.
+ GenericValue rv;
rv.IntVal = PF(ArgValues[0].IntVal, (char **)GVTOP(ArgValues[1]),
(const char **)GVTOP(ArgValues[2]));
return rv;
@@ -88,15 +94,48 @@
if (FTy->getNumParams() == 1 &&
(FTy->getParamType(0) == Type::IntTy ||
FTy->getParamType(0) == Type::UIntTy)) {
+ GenericValue rv;
int (*PF)(int) = (int(*)(int))FPtr;
rv.IntVal = PF(ArgValues[0].IntVal);
return rv;
}
break;
- case 0:
- int (*PF)() = (int(*)())FPtr;
- rv.IntVal = PF();
+ }
+ }
+
+ // Handle cases where no arguments are passed first.
+ if (ArgValues.empty()) {
+ GenericValue rv;
+ switch (RetTy->getTypeID()) {
+ default: assert(0 && "Unknown return type for function call!");
+ case Type::BoolTyID:
+ rv.BoolVal = ((bool(*)())FPtr)();
+ return rv;
+ case Type::SByteTyID:
+ case Type::UByteTyID:
+ rv.SByteVal = ((char(*)())FPtr)();
+ return rv;
+ case Type::ShortTyID:
+ case Type::UShortTyID:
+ rv.ShortVal = ((short(*)())FPtr)();
+ return rv;
+ case Type::VoidTyID:
+ case Type::IntTyID:
+ case Type::UIntTyID:
+ rv.IntVal = ((int(*)())FPtr)();
+ return rv;
+ case Type::LongTyID:
+ case Type::ULongTyID:
+ rv.LongVal = ((int64_t(*)())FPtr)();
+ return rv;
+ case Type::FloatTyID:
+ rv.FloatVal = ((float(*)())FPtr)();
+ return rv;
+ case Type::DoubleTyID:
+ rv.DoubleVal = ((double(*)())FPtr)();
return rv;
+ case Type::PointerTyID:
+ return PTOGV(((void*(*)())FPtr)());
}
}
@@ -106,7 +145,7 @@
std::cerr << "Sorry, unimplemented feature in the LLVM JIT. See LLVM"
<< " PR#419\n for details.\n";
abort();
- return rv;
+ return GenericValue();
}
/// runJITOnFunction - Run the FunctionPassManager full of
More information about the llvm-commits
mailing list