Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / mini / mini-llvm-loaded.c
index c93a83728120c36d2acf7129423f905f4cb52856..fb1dcac98133843d52cc48ed74aef539240d4340 100644 (file)
@@ -1,99 +1,96 @@
-/*
+/**
+ * \file
  * Handle the differences between the llvm backend beeing embedded
  * or loaded at runtime.
  */
 
 #include "mini.h"
+#include "mini-llvm.h"
 
 #ifdef MONO_LLVM_LOADED
 
-#ifdef __MACH__
-#include <mach-o/dyld.h>
-#endif
-
-typedef void (*MonoLLVMVoidFunc)(void);
-typedef void (*MonoLLVMCFGFunc)(MonoCompile *cfg);
-typedef void (*MonoLLVMEmitCallFunc)(MonoCompile *cfg, MonoCallInst *call);
-typedef void (*MonoLLVMCreateAotFunc)(MonoAssembly *assembly, const char *global_prefix, gboolean emit_dwarf, gboolean static_link);
-typedef void (*MonoLLVMEmitAotFunc)(const char *filename, const char *cu_name);
-typedef void (*MonoLLVMEmitAotInfoFunc)(MonoAotFileInfo *info, gboolean has_jitted_code);
-typedef void (*MonoLLVMEmitAotDataFunc)(const char *symbol, guint8 *data, int data_len);
-typedef void (*MonoLLVMFreeDomainFunc)(MonoDomain *domain);
-
-static MonoLLVMVoidFunc mono_llvm_init_fptr;
-static MonoLLVMVoidFunc mono_llvm_cleanup_fptr;
-static MonoLLVMCFGFunc mono_llvm_emit_method_fptr;
-static MonoLLVMEmitCallFunc mono_llvm_emit_call_fptr;
-static MonoLLVMCreateAotFunc mono_llvm_create_aot_module_fptr;
-static MonoLLVMEmitAotFunc mono_llvm_emit_aot_module_fptr;
-static MonoLLVMCFGFunc mono_llvm_check_method_supported_fptr;
-static MonoLLVMEmitAotInfoFunc mono_llvm_emit_aot_file_info_fptr;
-static MonoLLVMEmitAotDataFunc mono_llvm_emit_aot_data_fptr;
-static MonoLLVMFreeDomainFunc mono_llvm_free_domain_info_fptr;
+typedef struct {
+       void (*init)(void);
+       void (*cleanup)(void);
+       void (*emit_method)(MonoCompile *cfg);
+       void (*emit_call)(MonoCompile *cfg, MonoCallInst *call);
+       void (*create_aot_module)(MonoAssembly *assembly, const char *global_prefix, int initial_got_size, gboolean emit_dwarf, gboolean static_link, gboolean llvm_only);
+       void (*emit_aot_module)(const char *filename, const char *cu_name);
+       void (*check_method_supported)(MonoCompile *cfg);
+       void (*emit_aot_file_info)(MonoAotFileInfo *info, gboolean has_jitted_code);
+       void (*emit_aot_data)(const char *symbol, guint8 *data, int data_len);
+       void (*free_domain_info)(MonoDomain *domain);
+       void (*create_vars)(MonoCompile *cfg);
+} LoadedBackend;
+
+static LoadedBackend backend;
 
 void
 mono_llvm_init (void)
 {
-       mono_llvm_init_fptr ();
+       backend.init ();
 }
 
 void
 mono_llvm_cleanup (void)
 {
-       mono_llvm_cleanup_fptr ();
+       backend.cleanup ();
 }
 
 void
 mono_llvm_emit_method (MonoCompile *cfg)
 {
-       mono_llvm_emit_method_fptr (cfg);
+       backend.emit_method (cfg);
 }
 
 void
 mono_llvm_emit_call (MonoCompile *cfg, MonoCallInst *call)
 {
-       mono_llvm_emit_call_fptr (cfg, call);
+       backend.emit_call (cfg, call);
 }
 
 void
-mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix, gboolean emit_dwarf, gboolean static_link)
+mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix, int initial_got_size, gboolean emit_dwarf, gboolean static_link, gboolean llvm_only)
 {
-       g_assert (mono_llvm_create_aot_module_fptr);
-       mono_llvm_create_aot_module_fptr (assembly, global_prefix, emit_dwarf, static_link);
+       backend.create_aot_module (assembly, global_prefix, initial_got_size, emit_dwarf, static_link, llvm_only);
 }
 
 void
 mono_llvm_emit_aot_module (const char *filename, const char *cu_name)
 {
-       g_assert (mono_llvm_emit_aot_module_fptr);
-       mono_llvm_emit_aot_module_fptr (filename, cu_name);
+       backend.emit_aot_module (filename, cu_name);
 }
 
 void
 mono_llvm_check_method_supported (MonoCompile *cfg)
 {
-       mono_llvm_check_method_supported_fptr (cfg);
+       backend.check_method_supported (cfg);
 }
 
 void
 mono_llvm_free_domain_info (MonoDomain *domain)
 {
-       if (mono_llvm_free_domain_info_fptr)
-               mono_llvm_free_domain_info_fptr (domain);
+       /* This is called even when llvm is not enabled */
+       if (backend.free_domain_info)
+               backend.free_domain_info (domain);
 }
 
 void
 mono_llvm_emit_aot_file_info (MonoAotFileInfo *info, gboolean has_jitted_code)
 {
-       if (mono_llvm_emit_aot_file_info_fptr)
-               mono_llvm_emit_aot_file_info_fptr (info, has_jitted_code);
+       backend.emit_aot_file_info (info, has_jitted_code);
 }
 
 void
 mono_llvm_emit_aot_data (const char *symbol, guint8 *data, int data_len)
 {
-       if (mono_llvm_emit_aot_data_fptr)
-               mono_llvm_emit_aot_data_fptr (symbol, data, data_len);
+       backend.emit_aot_data (symbol, data, data_len);
+}
+
+void
+mono_llvm_create_vars (MonoCompile *cfg)
+{
+       backend.create_vars (cfg);
 }
 
 int
@@ -108,25 +105,27 @@ mono_llvm_load (const char* bpath)
                return FALSE;
        }
 
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_init", (void**)&mono_llvm_init_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_init", (void**)&backend.init);
+       if (err) goto symbol_error;
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_cleanup", (void**)&backend.cleanup);
        if (err) goto symbol_error;
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_cleanup", (void**)&mono_llvm_cleanup_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_method", (void**)&backend.emit_method);
        if (err) goto symbol_error;
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_method", (void**)&mono_llvm_emit_method_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_call", (void**)&backend.emit_call);
        if (err) goto symbol_error;
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_call", (void**)&mono_llvm_emit_call_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_create_aot_module", (void**)&backend.create_aot_module);
        if (err) goto symbol_error;
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_create_aot_module", (void**)&mono_llvm_create_aot_module_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_aot_module", (void**)&backend.emit_aot_module);
        if (err) goto symbol_error;
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_aot_module", (void**)&mono_llvm_emit_aot_module_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_check_method_supported", (void**)&backend.check_method_supported);
        if (err) goto symbol_error;
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_check_method_supported", (void**)&mono_llvm_check_method_supported_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_free_domain_info", (void**)&backend.free_domain_info);
        if (err) goto symbol_error;
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_free_domain_info", (void**)&mono_llvm_free_domain_info_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_aot_file_info", (void**)&backend.emit_aot_file_info);
        if (err) goto symbol_error;
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_aot_file_info", (void**)&mono_llvm_emit_aot_file_info_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_aot_data", (void**)&backend.emit_aot_data);
        if (err) goto symbol_error;
-       err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_aot_data", (void**)&mono_llvm_emit_aot_data_fptr);
+       err = mono_dl_symbol (llvm_lib, "mono_llvm_create_vars", (void**)&backend.create_vars);
        if (err) goto symbol_error;
        return TRUE;
 symbol_error: