Pass around IntrinsicLowering instances as appropriate.
[oota-llvm.git] / lib / ExecutionEngine / Interpreter / ExternalFunctions.cpp
index a7814397a2b80e6d8c06d7b015ea3571563526ac..1fe0c01275db103f66f26caaafcb7716d50635f0 100644 (file)
@@ -1,5 +1,12 @@
 //===-- ExternalFunctions.cpp - Implement External Functions --------------===//
 // 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+// 
 //  This file contains both code to deal with invoking "external" functions, but
 //  also contains code that implements "exported" external functions.
 //
 //===----------------------------------------------------------------------===//
 
 #include "Interpreter.h"
-#include "ExecutionAnnotations.h"
-#include "llvm/Module.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Target/TargetData.h"
-#include <map>
+#include "Support/DynamicLinker.h"
 #include "Config/dlfcn.h"
 #include "Config/link.h"
 #include <cmath>
-#include "Config/stdio.h"
-#include "Support/DynamicLinker.h"
+#include <csignal>
+#include <map>
 using std::vector;
 
+using namespace llvm;
+
 typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
 static std::map<const Function *, ExFunc> Functions;
 static std::map<std::string, ExFunc> FuncNames;
@@ -81,7 +89,7 @@ GenericValue Interpreter::callExternalFunction(Function *M,
   TheInterpreter = this;
 
   // Do a lookup to see if the function is in our cache... this should just be a
-  // defered annotation!
+  // deferred annotation!
   std::map<const Function *, ExFunc>::iterator FI = Functions.find(M);
   ExFunc Fn = (FI == Functions.end()) ? lookupFunction(M) : FI->second;
   if (Fn == 0) {
@@ -137,10 +145,7 @@ GenericValue lle_X_exit(FunctionType *M, const vector<GenericValue> &Args) {
 
 // void abort(void)
 GenericValue lle_X_abort(FunctionType *M, const vector<GenericValue> &Args) {
-  std::cerr << "***PROGRAM ABORTED***!\n";
-  GenericValue GV;
-  GV.IntVal = 1;
-  TheInterpreter->exitCalled(GV);
+  raise (SIGABRT);
   return GenericValue();
 }
 
@@ -476,11 +481,17 @@ GenericValue lle_X_strcpy(FunctionType *M, const vector<GenericValue> &Args) {
   return PTOGV(strcpy((char*)GVTOP(Args[0]), (char*)GVTOP(Args[1])));
 }
 
-// long strlen(const char *src);
+// size_t strlen(const char *src);
 GenericValue lle_X_strlen(FunctionType *M, const vector<GenericValue> &Args) {
   assert(Args.size() == 1);
+  size_t strlenResult = strlen ((char *) GVTOP (Args[0]));
   GenericValue Ret;
-  Ret.LongVal = strlen((char*)GVTOP(Args[0]));
+  if (sizeof (size_t) == sizeof (uint64_t)) {
+    Ret.ULongVal = strlenResult;
+  } else {
+    assert (sizeof (size_t) == sizeof (unsigned int));
+    Ret.UIntVal = strlenResult;
+  }
   return Ret;
 }
 
@@ -539,25 +550,6 @@ static FILE *getFILE(void *Ptr) {
             break;
       if (IOB) break;
     }
-
-#if 0   /// FIXME!  __iob support for LLI
-    // If we found an __iob symbol now, find out what the actual address it's
-    // held in is...
-    if (IOB) {
-      // Get the address the array lives in...
-      GlobalAddress *Address = 
-        (GlobalAddress*)IOB->getOrCreateAnnotation(GlobalAddressAID);
-      IOBBase = (PointerTy)(GenericValue*)Address->Ptr;
-
-      // Figure out how big each element of the array is...
-      const ArrayType *AT =
-        dyn_cast<ArrayType>(IOB->getType()->getElementType());
-      if (AT)
-        FILESize = TD.getTypeSize(AT->getElementType());
-      else
-        FILESize = 16*8;  // Default size
-    }
-#endif
   }
 
   // Check to see if this is a reference to __iob...
@@ -684,35 +676,6 @@ GenericValue lle_X_fprintf(FunctionType *M, const vector<GenericValue> &Args) {
   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"
 
 
@@ -764,8 +727,5 @@ void Interpreter::initializeExternalFunctions() {
   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;
 }
+