Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / mini / mini-llvm-loaded.c
1 /**
2  * \file
3  * Handle the differences between the llvm backend beeing embedded
4  * or loaded at runtime.
5  */
6
7 #include "mini.h"
8 #include "mini-llvm.h"
9
10 #ifdef MONO_LLVM_LOADED
11
12 typedef struct {
13         void (*init)(void);
14         void (*cleanup)(void);
15         void (*emit_method)(MonoCompile *cfg);
16         void (*emit_call)(MonoCompile *cfg, MonoCallInst *call);
17         void (*create_aot_module)(MonoAssembly *assembly, const char *global_prefix, int initial_got_size, gboolean emit_dwarf, gboolean static_link, gboolean llvm_only);
18         void (*emit_aot_module)(const char *filename, const char *cu_name);
19         void (*check_method_supported)(MonoCompile *cfg);
20         void (*emit_aot_file_info)(MonoAotFileInfo *info, gboolean has_jitted_code);
21         void (*emit_aot_data)(const char *symbol, guint8 *data, int data_len);
22         void (*free_domain_info)(MonoDomain *domain);
23         void (*create_vars)(MonoCompile *cfg);
24 } LoadedBackend;
25
26 static LoadedBackend backend;
27
28 void
29 mono_llvm_init (void)
30 {
31         backend.init ();
32 }
33
34 void
35 mono_llvm_cleanup (void)
36 {
37         backend.cleanup ();
38 }
39
40 void
41 mono_llvm_emit_method (MonoCompile *cfg)
42 {
43         backend.emit_method (cfg);
44 }
45
46 void
47 mono_llvm_emit_call (MonoCompile *cfg, MonoCallInst *call)
48 {
49         backend.emit_call (cfg, call);
50 }
51
52 void
53 mono_llvm_create_aot_module (MonoAssembly *assembly, const char *global_prefix, int initial_got_size, gboolean emit_dwarf, gboolean static_link, gboolean llvm_only)
54 {
55         backend.create_aot_module (assembly, global_prefix, initial_got_size, emit_dwarf, static_link, llvm_only);
56 }
57
58 void
59 mono_llvm_emit_aot_module (const char *filename, const char *cu_name)
60 {
61         backend.emit_aot_module (filename, cu_name);
62 }
63
64 void
65 mono_llvm_check_method_supported (MonoCompile *cfg)
66 {
67         backend.check_method_supported (cfg);
68 }
69
70 void
71 mono_llvm_free_domain_info (MonoDomain *domain)
72 {
73         /* This is called even when llvm is not enabled */
74         if (backend.free_domain_info)
75                 backend.free_domain_info (domain);
76 }
77
78 void
79 mono_llvm_emit_aot_file_info (MonoAotFileInfo *info, gboolean has_jitted_code)
80 {
81         backend.emit_aot_file_info (info, has_jitted_code);
82 }
83
84 void
85 mono_llvm_emit_aot_data (const char *symbol, guint8 *data, int data_len)
86 {
87         backend.emit_aot_data (symbol, data, data_len);
88 }
89
90 void
91 mono_llvm_create_vars (MonoCompile *cfg)
92 {
93         backend.create_vars (cfg);
94 }
95
96 int
97 mono_llvm_load (const char* bpath)
98 {
99         char *err = NULL;
100         MonoDl *llvm_lib = mono_dl_open_runtime_lib ("mono-llvm", MONO_DL_LAZY, &err);
101
102         if (!llvm_lib) {
103                 g_warning ("llvm load failed: %s\n", err);
104                 g_free (err);
105                 return FALSE;
106         }
107
108         err = mono_dl_symbol (llvm_lib, "mono_llvm_init", (void**)&backend.init);
109         if (err) goto symbol_error;
110         err = mono_dl_symbol (llvm_lib, "mono_llvm_cleanup", (void**)&backend.cleanup);
111         if (err) goto symbol_error;
112         err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_method", (void**)&backend.emit_method);
113         if (err) goto symbol_error;
114         err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_call", (void**)&backend.emit_call);
115         if (err) goto symbol_error;
116         err = mono_dl_symbol (llvm_lib, "mono_llvm_create_aot_module", (void**)&backend.create_aot_module);
117         if (err) goto symbol_error;
118         err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_aot_module", (void**)&backend.emit_aot_module);
119         if (err) goto symbol_error;
120         err = mono_dl_symbol (llvm_lib, "mono_llvm_check_method_supported", (void**)&backend.check_method_supported);
121         if (err) goto symbol_error;
122         err = mono_dl_symbol (llvm_lib, "mono_llvm_free_domain_info", (void**)&backend.free_domain_info);
123         if (err) goto symbol_error;
124         err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_aot_file_info", (void**)&backend.emit_aot_file_info);
125         if (err) goto symbol_error;
126         err = mono_dl_symbol (llvm_lib, "mono_llvm_emit_aot_data", (void**)&backend.emit_aot_data);
127         if (err) goto symbol_error;
128         err = mono_dl_symbol (llvm_lib, "mono_llvm_create_vars", (void**)&backend.create_vars);
129         if (err) goto symbol_error;
130         return TRUE;
131 symbol_error:
132         g_warning ("llvm symbol load failed: %s\n", err);
133         g_free (err);
134         return FALSE;
135 }
136
137 #else
138
139 int
140 mono_llvm_load (const char* bpath)
141 {
142         return TRUE;
143 }
144
145 #endif /* MONO_LLVM_LOADED */
146