//===----------------------------------------------------------------------===//
#include "Interpreter.h"
-#include "llvm/Module.h"
+#include "llvm/CodeGen/IntrinsicLowering.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/Module.h"
+using namespace llvm;
/// create - Create a new interpreter object. This can never fail.
///
-ExecutionEngine *Interpreter::create(Module *M){
+ExecutionEngine *Interpreter::create(Module *M, IntrinsicLowering *IL) {
bool isLittleEndian = false;
switch (M->getEndianness()) {
case Module::LittleEndian: isLittleEndian = true; break;
break;
}
- return new Interpreter(M, isLittleEndian, isLongPointer);
+ return new Interpreter(M, isLittleEndian, isLongPointer, IL);
}
//===----------------------------------------------------------------------===//
// Interpreter ctor - Initialize stuff
//
-Interpreter::Interpreter(Module *M, bool isLittleEndian, bool isLongPointer)
- : ExecutionEngine(M), ExitCode(0),
+Interpreter::Interpreter(Module *M, bool isLittleEndian, bool isLongPointer,
+ IntrinsicLowering *il)
+ : ExecutionEngine(M), ExitCode(0),
TD("lli", isLittleEndian, isLongPointer ? 8 : 4, isLongPointer ? 8 : 4,
- isLongPointer ? 8 : 4) {
+ isLongPointer ? 8 : 4), IL(il) {
setTargetData(TD);
// Initialize the "backend"
initializeExecutionEngine();
initializeExternalFunctions();
emitGlobals();
+
+ if (IL == 0) IL = new DefaultIntrinsicLowering();
+}
+
+Interpreter::~Interpreter() {
+ delete IL;
}
void Interpreter::runAtExitHandlers () {
/// run - Start execution with the specified function and arguments.
///
-GenericValue Interpreter::run(Function *F,
+GenericValue Interpreter::runFunction(Function *F,
const std::vector<GenericValue> &ArgValues) {
assert (F && "Function *F was null at entry to run()");
// take into account gratuitous differences in declared types,
// though.
std::vector<GenericValue> ActualArgs;
- const unsigned ArgCount = F->getFunctionType()->getParamTypes().size();
+ const unsigned ArgCount = F->getFunctionType()->getNumParams();
for (unsigned i = 0; i < ArgCount; ++i)
- ActualArgs.push_back (ArgValues[i]);
+ ActualArgs.push_back(ArgValues[i]);
// Set up the function call.
callFunction(F, ActualArgs);
// Start executing the function.
run();
- // Run any atexit handlers now!
- runAtExitHandlers();
-
GenericValue rv;
rv.IntVal = ExitCode;
return rv;
}
+