Implement global variables.  Struct and Pointer initializers are not implemented yet though


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@818 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ExecutionEngine/Interpreter/UserInput.cpp b/lib/ExecutionEngine/Interpreter/UserInput.cpp
index e9fc9db..4c2faf6 100644
--- a/lib/ExecutionEngine/Interpreter/UserInput.cpp
+++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp
@@ -5,6 +5,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Interpreter.h"
+#include "llvm/Bytecode/Reader.h"
 #include "llvm/Assembly/Writer.h"
 #include <algorithm>
 
@@ -81,9 +82,14 @@
 
     switch (E->CID) {
     case Quit:       UserQuit = true;   break;
+    case Load:
+      cin >> Command;
+      loadModule(Command);
+      break;
+    case Flush: flushModule(); break;
     case Print:
       cin >> Command;
-      printValue(Command);
+      print(Command);
       break;
     case Info:
       cin >> Command;
@@ -118,6 +124,43 @@
   } while (!UserQuit);
 }
 
+//===----------------------------------------------------------------------===//
+// loadModule - Load a new module to execute...
+//
+void Interpreter::loadModule(const string &Filename) {
+  if (CurMod && !flushModule()) return;  // Kill current execution
+
+  CurMod = ParseBytecodeFile(Filename);
+  if (CurMod == 0) {
+    cout << "Error parsing '" << Filename << "': No module loaded.\n";
+    return;
+  }
+
+  // TODO: link in support library...
+}
+
+
+//===----------------------------------------------------------------------===//
+// 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;
+  }
+
+  delete CurMod;
+  CurMod = 0;
+  ExitCode = 0;
+  return true;
+}
 
 //===----------------------------------------------------------------------===//
 // setBreakpoint - Enable a breakpoint at the specified location