-#ifndef MONO_CROSS_COMPILE
-
-class MonoJITMemoryManager : public JITMemoryManager
-{
-private:
- JITMemoryManager *mm;
-
-public:
- /* Callbacks installed by mono */
- AllocCodeMemoryCb *alloc_cb;
- DlSymCb *dlsym_cb;
-
- MonoJITMemoryManager ();
- ~MonoJITMemoryManager ();
-
- void setMemoryWritable (void);
-
- void setMemoryExecutable (void);
-
- void AllocateGOT();
-
- unsigned char *getGOTBase() const {
- return mm->getGOTBase ();
- }
-
- void setPoisonMemory(bool) {
- }
-
- unsigned char *startFunctionBody(const Function *F,
- uintptr_t &ActualSize);
-
- unsigned char *allocateStub(const GlobalValue* F, unsigned StubSize,
- unsigned Alignment);
-
- void endFunctionBody(const Function *F, unsigned char *FunctionStart,
- unsigned char *FunctionEnd);
-
- unsigned char *allocateSpace(intptr_t Size, unsigned Alignment);
-
- uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment);
-
- void deallocateMemForFunction(const Function *F);
-
- unsigned char*startExceptionTable(const Function* F,
- uintptr_t &ActualSize);
-
- void endExceptionTable(const Function *F, unsigned char *TableStart,
- unsigned char *TableEnd,
- unsigned char* FrameRegister);
-
- virtual void deallocateFunctionBody(void*) {
- }
-
- virtual void deallocateExceptionTable(void*) {
- }
-
- virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID,
- StringRef SectionName) {
- // FIXME:
- assert(0);
- return NULL;
- }
-
- virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID,
- StringRef SectionName, bool IsReadOnly) {
- // FIXME:
- assert(0);
- return NULL;
- }
-
- virtual bool applyPermissions(std::string*) {
- // FIXME:
- assert(0);
- return false;
- }
-
- virtual bool finalizeMemory(std::string *ErrMsg = 0) {
- // FIXME:
- assert(0);
- return false;
- }
-
- virtual void* getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure) {
- void *res;
- char *err;
-
- err = dlsym_cb (Name.c_str (), &res);
- if (err) {
- outs () << "Unable to resolve: " << Name << ": " << err << "\n";
- assert(0);
- return NULL;
- }
- return res;
- }
-};
-
-MonoJITMemoryManager::MonoJITMemoryManager ()
-{
- mm = JITMemoryManager::CreateDefaultMemManager ();
-}
-
-MonoJITMemoryManager::~MonoJITMemoryManager ()
-{
- delete mm;
-}
-
-void
-MonoJITMemoryManager::setMemoryWritable (void)
-{
-}
-
-void
-MonoJITMemoryManager::setMemoryExecutable (void)
-{
-}
-
-void
-MonoJITMemoryManager::AllocateGOT()
-{
- mm->AllocateGOT ();
-}
-
-unsigned char *
-MonoJITMemoryManager::startFunctionBody(const Function *F,
- uintptr_t &ActualSize)
-{
- // FIXME: This leaks memory
- if (ActualSize == 0)
- ActualSize = 128;
- return alloc_cb (wrap (F), ActualSize);
-}
-
-unsigned char *
-MonoJITMemoryManager::allocateStub(const GlobalValue* F, unsigned StubSize,
- unsigned Alignment)
-{
- return alloc_cb (wrap (F), StubSize);
-}
-
-void
-MonoJITMemoryManager::endFunctionBody(const Function *F, unsigned char *FunctionStart,
- unsigned char *FunctionEnd)
-{
-}
-
-unsigned char *
-MonoJITMemoryManager::allocateSpace(intptr_t Size, unsigned Alignment)
-{
- return new unsigned char [Size];
-}
-
-uint8_t *
-MonoJITMemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment)
-{
- return new unsigned char [Size];
-}
-
-void
-MonoJITMemoryManager::deallocateMemForFunction(const Function *F)
-{
-}
-
-unsigned char*
-MonoJITMemoryManager::startExceptionTable(const Function* F,
- uintptr_t &ActualSize)
-{
- return startFunctionBody(F, ActualSize);
-}
-
-void
-MonoJITMemoryManager::endExceptionTable(const Function *F, unsigned char *TableStart,
- unsigned char *TableEnd,
- unsigned char* FrameRegister)
-{
-}
-
-#else
-
-class MonoJITMemoryManager {
-};
-
-#endif /* !MONO_CROSS_COMPILE */
-
-class MonoJITEventListener : public JITEventListener {
-
-public:
- FunctionEmittedCb *emitted_cb;
-
- MonoJITEventListener (FunctionEmittedCb *cb) {
- emitted_cb = cb;
- }
-
- virtual void NotifyFunctionEmitted(const Function &F,
- void *Code, size_t Size,
- const EmittedFunctionDetails &Details) {
- /*
- * X86TargetMachine::setCodeModelForJIT() sets the code model to Large on amd64,
- * which means the JIT will generate calls of the form
- * mov reg, <imm>
- * call *reg
- * Our trampoline code can't patch this. Passing CodeModel::Small to createJIT
- * doesn't seem to work, we need Default. A discussion is here:
- * http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-December/027999.html
- * There seems to no way to get the TargeMachine used by an EE either, so we
- * install a profiler hook and reset the code model here.
- * This should be inside an ifdef, but we can't include our config.h either,
- * since its definitions conflict with LLVM's config.h.
- * The LLVM mono branch contains a workaround.
- */
- emitted_cb (wrap (&F), Code, (char*)Code + Size);
- }
-};
-
-class MonoEE {
-public:
- ExecutionEngine *EE;
- MonoJITMemoryManager *mm;
- MonoJITEventListener *listener;
- FunctionPassManager *fpm;
-};
-
-void
-mono_llvm_optimize_method (MonoEERef eeref, LLVMValueRef method)
-{
- MonoEE *mono_ee = (MonoEE*)eeref;
-
- /*
- * The verifier does some checks on the whole module, leading to quadratic behavior.
- */
- //verifyFunction (*(unwrap<Function> (method)));
- mono_ee->fpm->run (*unwrap<Function> (method));
-}
-