//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "jit"
-#include "ExecutionEngine.h"
-#include "GenericValue.h"
+#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "JIT/VM.h"
+#include "Interpreter/Interpreter.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
#include "llvm/Module.h"
+#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/Target/TargetData.h"
#include "Support/Debug.h"
#include "Support/Statistic.h"
+#include "Support/DynamicLinker.h"
#include "Config/dlfcn.h"
-#include "JIT/VM.h"
-#include "Interpreter/Interpreter.h"
Statistic<> NumInitBytes("lli", "Number of bytes of global vars initialized");
+ExecutionEngine::~ExecutionEngine() {
+ delete &CurMod;
+}
+
ExecutionEngine *ExecutionEngine::create (Module *M, bool ForceInterpreter,
- bool DebugMode, bool TraceMode) {
+ bool TraceMode) {
ExecutionEngine *EE = 0;
// If there is nothing that is forcing us to use the interpreter, make a JIT.
- if (!ForceInterpreter && !DebugMode && !TraceMode)
+ if (!ForceInterpreter && !TraceMode)
EE = VM::create(M);
// If we can't make a JIT, make an interpreter instead.
if (EE == 0)
- EE = Interpreter::create(M, DebugMode, TraceMode);
+ EE = Interpreter::create(M, TraceMode);
return EE;
}
}
}
-void *ExecutionEngine::CreateArgv(const std::vector<std::string> &InputArgv) {
- if (getTargetData().getPointerSize() == 8) { // 64 bit target?
- PointerTy *Result = new PointerTy[InputArgv.size()+1];
- DEBUG(std::cerr << "ARGV = " << (void*)Result << "\n");
-
- for (unsigned i = 0; i < InputArgv.size(); ++i) {
- unsigned Size = InputArgv[i].size()+1;
- char *Dest = new char[Size];
- DEBUG(std::cerr << "ARGV[" << i << "] = " << (void*)Dest << "\n");
-
- copy(InputArgv[i].begin(), InputArgv[i].end(), Dest);
- Dest[Size-1] = 0;
-
- // Endian safe: Result[i] = (PointerTy)Dest;
- StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Result+i), Type::LongTy);
- }
- Result[InputArgv.size()] = 0;
- return Result;
-
- } else { // 32 bit target?
- int *Result = new int[InputArgv.size()+1];
- DEBUG(std::cerr << "ARGV = " << (void*)Result << "\n");
-
- for (unsigned i = 0; i < InputArgv.size(); ++i) {
- unsigned Size = InputArgv[i].size()+1;
- char *Dest = new char[Size];
- DEBUG(std::cerr << "ARGV[" << i << "] = " << (void*)Dest << "\n");
-
- copy(InputArgv[i].begin(), InputArgv[i].end(), Dest);
- Dest[Size-1] = 0;
-
- // Endian safe: Result[i] = (PointerTy)Dest;
- StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Result+i), Type::IntTy);
- }
- Result[InputArgv.size()] = 0; // null terminate it
- return Result;
- }
-}
-
/// EmitGlobals - Emit all of the global variables to memory, storing their
/// addresses into GlobalAddress. This must make sure to copy the contents of
/// their initializers into the memory.
DEBUG(std::cerr << "Global '" << I->getName() << "' -> "
<< (void*)GlobalAddress[I] << "\n");
} else {
- // On Sparc, RTLD_SELF is already defined and it's not zero
- // Linux/x86 wants to use a 0, other systems may differ
-#ifndef RTLD_SELF
-#define RTLD_SELF 0
-#endif
- // External variable reference, try to use dlsym to get a pointer to it in
- // the LLI image.
- if (void *SymAddr = dlsym(RTLD_SELF, I->getName().c_str()))
+ // External variable reference. Try to use the dynamic loader to
+ // get a pointer to it.
+ if (void *SymAddr = GetAddressOfSymbol(I->getName().c_str()))
GlobalAddress[I] = SymAddr;
else {
std::cerr << "Could not resolve external global address: "