Simplify code a bit, print error message always instead of asserting.
[oota-llvm.git] / lib / ExecutionEngine / Interpreter / Interpreter.cpp
index bcaa8569dc47b5367e8d6466e95b9ec6a458f85d..adb26aea64ed6c38f6f82f22e107335e80181919 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #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;
@@ -40,22 +42,29 @@ ExecutionEngine *Interpreter::create(Module *M){
     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 () {
@@ -68,7 +77,7 @@ 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()");
 
@@ -80,9 +89,9 @@ GenericValue Interpreter::run(Function *F,
   // 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);
@@ -90,10 +99,8 @@ GenericValue Interpreter::run(Function *F,
   // Start executing the function.
   run();
   
-  // Run any atexit handlers now!
-  runAtExitHandlers();
-
   GenericValue rv;
   rv.IntVal = ExitCode;
   return rv;
 }
+