28e04d6d6288388a8ca141a481b7262cd1b7ea5a
[mono.git] / mono / mini / mini-cross-helpers.c
1 #include "config.h"
2
3 #include <stdio.h>
4
5 #include "config.h"
6
7 #include "mini.h"
8 #include "tasklets.h"
9 #include <mono/metadata/abi-details.h>
10
11 void
12 mono_dump_metadata_offsets (void);
13
14 void
15 mono_metadata_cross_helpers_run (void);
16
17
18 static void
19 mono_dump_jit_offsets (void)
20 {
21 #ifdef USED_CROSS_COMPILER_OFFSETS
22         g_print ("#error not using native offsets\n");
23 #else
24         mono_dump_metadata_offsets ();
25
26         g_print ("#ifndef DISABLE_JIT_OFFSETS\n");
27         g_print ("#define USED_CROSS_COMPILER_OFFSETS\n");
28 #define DISABLE_METADATA_OFFSETS
29 #define DECL_OFFSET2(struct,field,offset) this_should_not_happen
30 #define DECL_ALIGN2(type,size) this_should_not_happen
31
32 #define DECL_OFFSET(struct,field) g_print ("DECL_OFFSET2(%s,%s,%d)\n", #struct, #field, (int)MONO_STRUCT_OFFSET (struct, field));
33 #define DECL_ALIGN(type)
34 #define DECL_SIZE2(type,size) this_should_not_happen
35 #define DECL_SIZE(type)
36 #include <mono/metadata/object-offsets.h>
37
38         g_print ("#endif //disable jit check\n");
39         g_print ("#endif //cross compiler checks\n");
40         g_print ("#endif //gc check\n");
41         g_print ("#endif //os check\n");
42         g_print ("#endif //arch check\n");
43         g_print ("#endif //USED_CROSS_COMPILER_OFFSETS check\n");
44 #endif
45 }
46
47 void
48 mono_cross_helpers_run (void)
49 {
50 #if defined (HAS_CROSS_COMPILER_OFFSETS) && !defined (MONO_CROSS_COMPILE)
51         gboolean is_broken = FALSE;
52 #endif
53
54 #ifndef USED_CROSS_COMPILER_OFFSETS
55         if (g_getenv ("DUMP_CROSS_OFFSETS"))
56                 mono_dump_jit_offsets ();
57 #endif
58         
59 #if defined (HAS_CROSS_COMPILER_OFFSETS) && !defined (MONO_CROSS_COMPILE)
60         mono_metadata_cross_helpers_run ();
61
62 #define DISABLE_METADATA_OFFSETS
63 #define USE_CROSS_COMPILE_OFFSETS
64 #define DECL_OFFSET(struct,field) this_should_not_happen_for_cross_fields
65 #define DECL_OFFSET2(struct,field,offset) \
66          if ((int)G_STRUCT_OFFSET (struct, field) != offset) { \
67                 g_print (#struct ":" #field " invalid struct offset %d (expected %d)\n",        \
68                         offset, \
69                         (int)G_STRUCT_OFFSET (struct, field));  \
70                 is_broken = TRUE;       \
71         }
72 #define DECL_ALIGN(name,type) this_should_not_happen_for_cross_align
73 #define DECL_ALIGN2(name,size) \
74          if (MONO_ALIGN_ ## name != size) { \
75                 g_print (#name ": invalid alignment %d (expected %d)\n",        \
76                 size,   \
77                 MONO_ALIGN_ ## name);   \
78                 is_broken = TRUE;       \
79         }
80 #define DECL_SIZE(type) this_should_not_happen_for_cross_size
81 #define DECL_SIZE2(name,size) \
82          if (MONO_SIZEOF_ ## name != size) { \
83                 g_print (#name ": invalid size %d (expected %d)\n",     \
84                 size,   \
85                 MONO_SIZEOF_ ## name);  \
86                 is_broken = TRUE;       \
87         }
88
89 #include <mono/metadata/object-offsets.h>
90
91         g_assert (!is_broken);
92 #endif
93 }