#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;
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...
{ "break" , Break }, { "b", Break },
{ "watch" , Watch },
- { "load" , Load },
{ "flush" , Flush },
{ "trace" , TraceOpt },
- { "profile" , ProfileOpt },
};
static CommandTableElement *CommandTableEnd =
CommandTable+sizeof(CommandTable)/sizeof(CommandTable[0]);
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);
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;
} 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
//
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.
//
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();