Merge pull request #487 from mayerwin/patch-1
[mono.git] / mono / mini / mini-llvm-cpp.cpp
index 5af6af5423e6f418054279c05339b605b2b6b8df..2b90cd692daac6ad903e56bbb23cbbb5ff4cc6e2 100644 (file)
 // possible
 //
 
+#include "config.h"
+//undef those as llvm defines them on its own config.h as well.
+#undef PACKAGE_BUGREPORT
+#undef PACKAGE_NAME
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
+#undef PACKAGE_VERSION
+
 #include <stdint.h>
 
 #include <llvm/Support/raw_ostream.h>
        ((LLVM_MAJOR_VERSION > (major)) ||                                                                      \
         ((LLVM_MAJOR_VERSION == (major)) && (LLVM_MINOR_VERSION >= (minor))))
 
+// extern "C" void LLVMInitializeARMTargetInfo();
+// extern "C" void LLVMInitializeARMTarget ();
+// extern "C" void LLVMInitializeARMTargetMC ();
+
 using namespace llvm;
 
 class MonoJITMemoryManager : public JITMemoryManager
@@ -61,6 +73,7 @@ private:
 public:
        /* Callbacks installed by mono */
        AllocCodeMemoryCb *alloc_cb;
+       DlSymCb *dlsym_cb;
 
        MonoJITMemoryManager ();
        ~MonoJITMemoryManager ();
@@ -105,6 +118,33 @@ public:
 
        virtual void deallocateExceptionTable(void*) {
        }
+
+       virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
+                                                                                unsigned SectionID) {
+               // FIXME:
+               assert(0);
+               return NULL;
+       }
+
+       virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
+                                                                                unsigned SectionID) {
+               // FIXME:
+               assert(0);
+               return NULL;
+       }
+
+       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 ()
@@ -472,18 +512,25 @@ force_pass_linking (void)
 }
 
 LLVMExecutionEngineRef
-mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, FunctionEmittedCb *emitted_cb, ExceptionTableCb *exception_cb)
+mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, FunctionEmittedCb *emitted_cb, ExceptionTableCb *exception_cb, DlSymCb *dlsym_cb)
 {
   std::string Error;
 
   force_pass_linking ();
 
+#ifdef TARGET_ARM
+  LLVMInitializeARMTarget ();
+  LLVMInitializeARMTargetInfo ();
+  LLVMInitializeARMTargetMC ();
+#else
   LLVMInitializeX86Target ();
   LLVMInitializeX86TargetInfo ();
   LLVMInitializeX86TargetMC ();
+#endif
 
   mono_mm = new MonoJITMemoryManager ();
   mono_mm->alloc_cb = alloc_cb;
+  mono_mm->dlsym_cb = dlsym_cb;
 
   //JITExceptionHandling = true;
   // PrettyStackTrace installs signal handlers which trip up libgc