Add support for isnan
[oota-llvm.git] / lib / ExecutionEngine / Interpreter / UserInput.cpp
index 7ece7bc54b9af7e9edcc4c1d46d9092da3d860d2..f0975a72d8fcccf65d39e2d0e716401c9f0fe5f6 100644 (file)
@@ -6,10 +6,12 @@
 
 #include "Interpreter.h"
 #include "llvm/Bytecode/Reader.h"
-#include "llvm/Assembly/Writer.h"
 #include "llvm/DerivedTypes.h"
-#include "llvm/Transforms/Linker.h"
+#include "llvm/Transforms/Utils/Linker.h"
 #include <algorithm>
+using std::string;
+using std::cout;
+using std::cin;
 
 enum CommandID {
   Quit, Help,                                 // Basics
@@ -69,14 +71,14 @@ void Interpreter::handleUserInput() {
   bool UserQuit = false;
 
   // Sort the table...
-  sort(CommandTable, CommandTableEnd);
+  std::sort(CommandTable, CommandTableEnd);
 
   // Print the instruction that we are stopped at...
   printCurrentInstruction();
 
   do {
     string Command;
-    cout << "lli> " << flush;
+    cout << "lli> " << std::flush;
     cin >> Command;
 
     CommandTableElement *E = find(CommandTable, CommandTableEnd, Command);
@@ -121,7 +123,7 @@ void Interpreter::handleUserInput() {
     case Finish:     finish();          break;
     case Call:
       cin >> Command;
-      callMethod(Command);    // Enter the specified method
+      callMethod(Command);    // Enter the specified function
       finish();               // Run until it's complete
       break;
 
@@ -158,18 +160,20 @@ void Interpreter::loadModule(const string &Filename) {
   }
   CW.setModule(CurMod);  // Update Writer
 
+#if 0
   string RuntimeLib = getCurrentExecutablePath();
   if (!RuntimeLib.empty()) RuntimeLib += "/";
   RuntimeLib += "RuntimeLib.bc";
 
   if (Module *SupportLib = ParseBytecodeFile(RuntimeLib, &ErrorMsg)) {
     if (LinkModules(CurMod, SupportLib, &ErrorMsg))
-      cerr << "Error Linking runtime library into current module: "
-           << ErrorMsg << endl;
+      std::cerr << "Error Linking runtime library into current module: "
+                << ErrorMsg << "\n";
   } else {
-    cerr << "Error loading runtime library '"+RuntimeLib+"': "
-         << ErrorMsg << "\n";
+    std::cerr << "Error loading runtime library '"+RuntimeLib+"': "
+              << ErrorMsg << "\n";
   }
+#endif
 }
 
 
@@ -208,10 +212,10 @@ void Interpreter::setBreakpoint(const string &Name) {
 // callMethod - Enter the specified method...
 //
 bool Interpreter::callMethod(const string &Name) {
-  vector<Value*> Options = LookupMatchingNames(Name);
+  std::vector<Value*> Options = LookupMatchingNames(Name);
 
-  for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
-    if (!isa<Method>(Options[i])) {
+  for (unsigned i = 0; i < Options.size(); ++i) { // Remove non-fn matches...
+    if (!isa<Function>(Options[i])) {
       Options.erase(Options.begin()+i);
       --i;
     }
@@ -221,12 +225,12 @@ bool Interpreter::callMethod(const string &Name) {
   if (PickedMeth == 0)
     return true;
 
-  Method *M = cast<Method>(PickedMeth);
+  Function *F = cast<Function>(PickedMeth);
 
-  vector<GenericValue> Args;
+  std::vector<GenericValue> Args;
   // TODO, get args from user...
 
-  callMethod(M, Args);  // Start executing it...
+  callMethod(F, Args);  // Start executing it...
 
   // Reset the current frame location to the top of stack
   CurFrame = ECStack.size()-1;
@@ -234,32 +238,15 @@ bool Interpreter::callMethod(const string &Name) {
   return false;
 }
 
-static void *CreateArgv(const vector<string> &InputArgv) {
-  // Pointers are 64 bits...
-  uint64_t *Result = new uint64_t[InputArgv.size()+1];
-
-  for (unsigned i = 0; i < InputArgv.size(); ++i) {
-    unsigned Size = InputArgv[i].size()+1;
-    char *Dest = new char[Size];
-    copy(InputArgv[i].begin(), InputArgv[i].end(), Dest);
-    Dest[Size-1] = 0;
-    Result[i] = (uint64_t)Dest;
-  }
-
-  Result[InputArgv.size()] = 0;
-  return Result;
-}
-
-
 // callMainMethod - This is a nasty gross hack that will dissapear when
 // callMethod can parse command line options and stuff for us.
 //
 bool Interpreter::callMainMethod(const string &Name,
-                                 const vector<string> &InputArgv) {
-  vector<Value*> Options = LookupMatchingNames(Name);
+                                 const std::vector<string> &InputArgv) {
+  std::vector<Value*> Options = LookupMatchingNames(Name);
 
-  for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
-    if (!isa<Method>(Options[i])) {
+  for (unsigned i = 0; i < Options.size(); ++i) { // Remove non-fn matches...
+    if (!isa<Function>(Options[i])) {
       Options.erase(Options.begin()+i);
       --i;
     }
@@ -269,10 +256,10 @@ bool Interpreter::callMainMethod(const string &Name,
   if (PickedMeth == 0)
     return true;
 
-  Method *M = cast<Method>(PickedMeth);
-  const MethodType *MT = M->getMethodType();
+  Function *M = cast<Function>(PickedMeth);
+  const FunctionType *MT = M->getFunctionType();
 
-  vector<GenericValue> Args;
+  std::vector<GenericValue> Args;
   switch (MT->getParamTypes().size()) {
   default:
     cout << "Unknown number of arguments to synthesize for '" << Name << "'!\n";
@@ -285,13 +272,12 @@ bool Interpreter::callMainMethod(const string &Name,
       return true;
     }
 
-    GenericValue GV; GV.PointerVal = (uint64_t)CreateArgv(InputArgv);
-    Args.push_back(GV);
+    Args.push_back(CreateArgv(InputArgv));
   }
     // fallthrough
   case 1:
-    if (!MT->getParamTypes()[0]->isIntegral()) {
-      cout << "First argument of '" << Name << "' should be integral!\n";
+    if (!MT->getParamTypes()[0]->isInteger()) {
+      cout << "First argument of '" << Name << "' should be an integer!\n";
       return true;
     } else {
       GenericValue GV; GV.UIntVal = InputArgv.size();
@@ -316,7 +302,7 @@ void Interpreter::list() {
   if (ECStack.empty())
     cout << "Error: No program executing!\n";
   else
-    CW << ECStack[CurFrame].CurMethod;   // Just print the method out...
+    CW << ECStack[CurFrame].CurMethod;   // Just print the function out...
 }
 
 void Interpreter::printStackTrace() {