#include "llvm/Function.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/MCJIT.h"
+#include "llvm/ExecutionEngine/JITMemoryManager.h"
+#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Target/TargetData.h"
using namespace llvm;
PM.run(*M);
// Flush the output buffer so the SmallVector gets its data.
OS.flush();
+
+ // Load the object into the dynamic linker.
+ // FIXME: It would be nice to avoid making yet another copy.
+ MemoryBuffer *MB = MemoryBuffer::getMemBufferCopy(StringRef(Buffer.data(),
+ Buffer.size()));
+ Dyld.loadObject(MB);
}
MCJIT::~MCJIT() {
}
void *MCJIT::getPointerToFunction(Function *F) {
- return 0;
+ Twine Name = TM->getMCAsmInfo()->getGlobalPrefix() + F->getName();
+ return Dyld.getSymbolAddress(Name.str());
}
void *MCJIT::recompileAndRelinkFunction(Function *F) {
#include "llvm/PassManager.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/raw_ostream.h"
SmallVector<char, 4096> Buffer; // Working buffer into which we JIT.
raw_svector_ostream OS;
+ RuntimeDyld Dyld;
+
public:
~MCJIT();
SymbolTable[Name] = Address;
}
+ // We've loaded the section; now mark the functions in it as executable.
+ // FIXME: We really should use the JITMemoryManager for this.
+ sys::Memory::setRangeExecutable(Data.base(), Data.size());
+
delete SectionBases;
return false;
}
SymbolTable[Name] = Address;
}
+ // We've loaded the section; now mark the functions in it as executable.
+ // FIXME: We really should use the JITMemoryManager for this.
+ sys::Memory::setRangeExecutable(Data.base(), Data.size());
+
delete SectionBases;
return false;
}
-
-
bool RuntimeDyldImpl::loadObject(MemoryBuffer *InputBuffer) {
// If the linker is in an error state, don't do anything.
if (hasError())