[2019-12] [jit] Avoid passing a vtable argument to DIM methods when making calls...
[mono-project.git] / mono / mini / aot-runtime-wasm.c
blobccc5a26510c931dc2ff076855a4bed6b1b5fed76
1 /**
2 * \file
3 * WASM AOT runtime
4 */
6 #include "config.h"
8 #include <sys/types.h>
10 #include "mini.h"
11 #include "interp/interp.h"
13 #ifdef TARGET_WASM
15 static char
16 type_to_c (MonoType *t)
18 if (t->byref)
19 return 'I';
21 handle_enum:
22 switch (t->type) {
23 case MONO_TYPE_BOOLEAN:
24 case MONO_TYPE_CHAR:
25 case MONO_TYPE_I1:
26 case MONO_TYPE_U1:
27 case MONO_TYPE_I2:
28 case MONO_TYPE_U2:
29 case MONO_TYPE_I4:
30 case MONO_TYPE_U4:
31 case MONO_TYPE_I:
32 case MONO_TYPE_U:
33 case MONO_TYPE_PTR:
34 case MONO_TYPE_SZARRAY:
35 case MONO_TYPE_CLASS:
36 case MONO_TYPE_OBJECT:
37 case MONO_TYPE_STRING:
38 return 'I';
39 case MONO_TYPE_R4:
40 return 'F';
41 case MONO_TYPE_R8:
42 return 'D';
43 break;
44 case MONO_TYPE_I8:
45 case MONO_TYPE_U8:
46 return 'L';
47 case MONO_TYPE_VOID:
48 return 'V';
49 case MONO_TYPE_VALUETYPE:
50 if (m_class_is_enumtype (t->data.klass)) {
51 t = mono_class_enum_basetype_internal (t->data.klass);
52 goto handle_enum;
55 return 'I';
56 case MONO_TYPE_GENERICINST:
57 if (m_class_is_valuetype (t->data.klass))
58 return 'S';
59 return 'I';
60 default:
61 g_warning ("CANT TRANSLATE %s", mono_type_full_name (t));
62 return 'X';
66 #if TARGET_SIZEOF_VOID_P == 4
67 #define FIDX(x) ((x) * 2)
68 #else
69 #define FIDX(x) (x)
70 #endif
74 typedef union {
75 gint64 l;
76 struct {
77 gint32 lo;
78 gint32 hi;
79 } pair;
80 } interp_pair;
82 static gint64
83 get_long_arg (InterpMethodArguments *margs, int idx)
85 interp_pair p;
86 p.pair.lo = (gint32)(gssize)margs->iargs [idx];
87 p.pair.hi = (gint32)(gssize)margs->iargs [idx + 1];
88 return p.l;
91 #include "wasm_m2n_invoke.g.h"
93 void
94 mono_wasm_interp_to_native_trampoline (void *target_func, InterpMethodArguments *margs)
96 char cookie [32];
97 int c_count;
99 MonoMethodSignature *sig = margs->sig;
101 c_count = sig->param_count + sig->hasthis + 1;
102 g_assert (c_count < sizeof (cookie)); //ensure we don't overflow the local
104 cookie [0] = type_to_c (sig->ret);
105 if (sig->hasthis)
106 cookie [1] = 'I';
107 for (int i = 0; i < sig->param_count; ++i) {
108 cookie [1 + sig->hasthis + i] = type_to_c (sig->params [i]);
110 cookie [c_count] = 0;
112 icall_trampoline_dispatch (cookie, target_func, margs);
115 #else /* TARGET_WASM */
117 MONO_EMPTY_SOURCE_FILE (aot_runtime_wasm);
119 #endif /* TARGET_WASM */