Handle value promotion properly to work with tracing better
[oota-llvm.git] / lib / ExecutionEngine / Interpreter / UserInput.cpp
index b35463fc0b1c55f6358c9a19e7bf53100d5325f5..3d2b1de60a45464f9c1b05a5148d2a232b3891d3 100644 (file)
@@ -6,9 +6,9 @@
 
 #include "Interpreter.h"
 #include "llvm/Bytecode/Reader.h"
-#include "llvm/Assembly/Writer.h"
 #include "llvm/DerivedTypes.h"
-#include "llvm/Transforms/Linker.h"
+#include "llvm/Function.h"
+#include "llvm/Transforms/Utils/Linker.h"
 #include <algorithm>
 using std::string;
 using std::cout;
@@ -19,8 +19,8 @@ enum CommandID {
   Print, Info, List, StackTrace, Up, Down,    // Inspection
   Next, Step, Run, Finish, Call,              // Control flow changes
   Break, Watch,                               // Debugging
-  Load, Flush,
-  TraceOpt, ProfileOpt                              // Toggle features
+  Flush,
+  TraceOpt,                                   // Toggle features
 };
 
 // CommandTable - Build a lookup table for the commands available to the user...
@@ -54,11 +54,9 @@ static struct CommandTableElement {
   { "break"    , Break      }, { "b", Break },
   { "watch"    , Watch      },
 
-  { "load"     , Load       },
   { "flush"    , Flush      },
 
   { "trace"    , TraceOpt   },
-  { "profile"  , ProfileOpt },
 };
 static CommandTableElement *CommandTableEnd = 
    CommandTable+sizeof(CommandTable)/sizeof(CommandTable[0]);
@@ -91,11 +89,6 @@ void Interpreter::handleUserInput() {
 
     switch (E->CID) {
     case Quit:       UserQuit = true;   break;
-    case Load:
-      cin >> Command;
-      loadModule(Command);
-      break;
-    case Flush: flushModule(); break;
     case Print:
       cin >> Command;
       print(Command);
@@ -133,11 +126,6 @@ void Interpreter::handleUserInput() {
       cout << "Tracing " << (Trace ? "enabled\n" : "disabled\n");
       break;
 
-    case ProfileOpt:
-      Profile = !Profile;
-      cout << "Profiling " << (Trace ? "enabled\n" : "disabled\n");
-      break;
-
     default:
       cout << "Command '" << Command << "' unimplemented!\n";
       break;
@@ -146,61 +134,6 @@ void Interpreter::handleUserInput() {
   } while (!UserQuit);
 }
 
-//===----------------------------------------------------------------------===//
-// loadModule - Load a new module to execute...
-//
-void Interpreter::loadModule(const string &Filename) {
-  string ErrorMsg;
-  if (CurMod && !flushModule()) return;  // Kill current execution
-
-  CurMod = ParseBytecodeFile(Filename, &ErrorMsg);
-  if (CurMod == 0) {
-    cout << "Error parsing '" << Filename << "': No module loaded: "
-         << ErrorMsg << "\n";
-    return;
-  }
-  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))
-      std::cerr << "Error Linking runtime library into current module: "
-                << ErrorMsg << "\n";
-  } else {
-    std::cerr << "Error loading runtime library '"+RuntimeLib+"': "
-              << ErrorMsg << "\n";
-  }
-#endif
-}
-
-
-//===----------------------------------------------------------------------===//
-// flushModule - Return true if the current program has been unloaded.
-//
-bool Interpreter::flushModule() {
-  if (CurMod == 0) {
-    cout << "Error flushing: No module loaded!\n";
-    return false;
-  }
-
-  if (!ECStack.empty()) {
-    // TODO: if use is not sure, return false
-    cout << "Killing current execution!\n";
-    ECStack.clear();
-    CurFrame = -1;
-  }
-
-  CW.setModule(0);
-  delete CurMod;
-  CurMod = 0;
-  ExitCode = 0;
-  return true;
-}
-
 //===----------------------------------------------------------------------===//
 // setBreakpoint - Enable a breakpoint at the specified location
 //
@@ -239,23 +172,6 @@ bool Interpreter::callMethod(const string &Name) {
   return false;
 }
 
-static void *CreateArgv(const std::vector<string> &InputArgv) {
-  // Pointers are 64 bits...
-  uint64_t *Result = new PointerTy[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] = (PointerTy)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.
 //
@@ -290,13 +206,12 @@ bool Interpreter::callMainMethod(const string &Name,
       return true;
     }
 
-    GenericValue GV; GV.PointerVal = (uint64_t)CreateArgv(InputArgv);
-    Args.push_back(GV);
+    Args.push_back(PTOGV(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();