aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-08-15 23:53:06 +0000
committerChris Lattner <sabre@nondot.org>2004-08-15 23:53:06 +0000
commite5eab142a51373dd3bee758ea958575afbfce259 (patch)
tree2df413fff5448bdb7943d2ad9a7f3fc087580df6 /lib
parentf7bedf447e080cb57c64d6f0cbf6fbeb9f4c596e (diff)
downloadexternal_llvm-e5eab142a51373dd3bee758ea958575afbfce259.zip
external_llvm-e5eab142a51373dd3bee758ea958575afbfce259.tar.gz
external_llvm-e5eab142a51373dd3bee758ea958575afbfce259.tar.bz2
Handle all nullary functions, of any valid return type.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15798 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp53
1 files changed, 46 insertions, 7 deletions
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index e6fd470..fa0a2c1 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -59,14 +59,19 @@ JIT::~JIT() {
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 @@ GenericValue JIT::runFunction(Function *F,
(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 @@ GenericValue JIT::runFunction(Function *F,
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 @@ GenericValue JIT::runFunction(Function *F,
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