RSS

(root)/ildjit/libirvirtualmachine : 1 : src/ir_virtual_machine.c

« back to all changes in this revision

Viewing changes to src/ir_virtual_machine.c

Speziale Ettore
2009-11-18 14:01:27
Revision ID: ettore@mars-20091118140127-xrp1dv0igfnqjhl6
Initial import into Bazaar.

Show diffs side-by-side

added added

removed removed

 
1
/*
 
2
 * Copyright (C) 2006 - 2009 Campanoni Simone <simo.xan@gmail.com> , Di Biagio Andrea, Tartara Michele <mikyt@users.sourceforge.net>
 
3
 *
 
4
 * ir_virtual_machine.c - This is a translator from the IR language into the assembly language.
 
5
 
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 */
 
20
#include <stdio.h>
 
21
#include <stdlib.h>
 
22
#include <assert.h>
 
23
#include <errno.h>
 
24
#include <jit/jit.h>
 
25
#include <jit/jit-dump.h>
 
26
#include <string.h>
 
27
#include <time.h>
 
28
#include <jitsystem.h>
 
29
#include <ir_language.h>
 
30
#include <ir_optimization_interface.h>
 
31
#include <compiler_memory_manager.h>
 
32
#include <jit_metadata.h>
 
33
#include <error_codes.h>
 
34
 
 
35
// My headers
 
36
#include <ir_virtual_machine.h>
 
37
#include <ir_virtual_machine_system.h>
 
38
#include <runtime.h>
 
39
#include <config.h>
 
40
// End
 
41
 
 
42
typedef struct {
 
43
        jit_label_t     label;
 
44
        JITUINT32       ID;
 
45
} t_jit_label;
 
46
 
 
47
JITUINT32 fromJITTypeToIRType (jit_type_t jitType);
 
48
static inline t_jit_label * insert_label (XanList *labels, JITUINT32 label_ID);
 
49
JITINT32 check_labels(XanList *labels);
 
50
static inline jit_value_t make_variable (IRVM_t *_this, ir_method_t *method, ir_item_t *item, t_jit_function *jitFunction);
 
51
void insert_tracer (IRVM_t *_this, ir_method_t *method, t_jit_function *jitFunction, JITBOOLEAN exitMethod);
 
52
JITINT32 insertTraceProfiler (t_ir_instruction *inst, JITINT32 prevIndex, t_jit_function *jitFunction, trace_profiler_t *profiler);
 
53
static inline JITINT16 bind_instruction_offset (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
54
JITINT16 fetch_parameters (ir_method_t *method, t_jit_function *jitFunction);
 
55
JITINT32 internal_isRootSetEmpty (ir_method_t *method, t_jit_function *jitFunction);
 
56
void internal_lockVM (IRVM_t *_this);
 
57
void internal_unlockVM (IRVM_t *_this);
 
58
void internal_lockLibjit (IRVM_t *_this);
 
59
void internal_unlockLibjit (IRVM_t *_this);
 
60
void variablesToRootSets (IRVM_t *_this, ir_method_t *method, t_jit_function *jitFunction);
 
61
JITINT32 internal_addRootSetProfile (IRVM_t *_this, ir_method_t *method, t_jit_function *jitFunction);
 
62
void internal_setExceptionHandler (IRVM_t *_this, void * (*exceptionHandler) (int exception_type));
 
63
static inline jit_function_t internal_newLibjitMethod (IRVM_t *_this, void *method, jit_type_t signature);
 
64
static inline void * internal_libjitDriver (jit_function_t function);
 
65
 
 
66
/* IR -> machine code translation functions                     */
 
67
/**
 
68
 * @brief Translates the IR instruction IRLOADREL in its JIT counterpart
 
69
 *
 
70
 * If a static field is being loaded, the first parameter of the IR instruction (inst->param_1) must be an IRMPOINTER containing the address of the field. Otherwise it must be an IROFFSET indicating the number of the local of the function containing the address.
 
71
 */
 
72
static inline JITINT16 translate_ir_load_rel (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
73
static inline JITINT16 translate_ir_ret (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
74
static inline JITINT16 translate_ir_call_indirect_exception_ctor (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
75
static inline JITINT16 translate_ir_newobj (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
76
static inline JITINT16 translate_ir_newarr (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
77
static inline JITINT16 translate_ir_load_elem (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
78
static inline JITINT16 translate_ir_store_elem (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
79
static inline JITINT16 translate_ir_add (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
80
static inline JITINT16 translate_ir_sub (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
81
static inline JITINT16 translate_ir_mul (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
82
static inline JITINT16 translate_ir_div (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
83
static inline JITINT16 translate_ir_rem (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
84
static inline JITINT16 translate_ir_and (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
85
static inline JITINT16 translate_ir_shl (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
86
static inline JITINT16 translate_ir_shr (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
87
static inline JITINT16 translate_ir_not (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
88
static inline JITINT16 translate_ir_or (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
89
static inline JITINT16 translate_ir_xor (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
90
static inline JITINT16 translate_ir_store_rel(IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
91
static inline JITINT16 translate_ir_add_ovf (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
92
static inline JITINT16 translate_ir_sub_ovf (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
93
static inline JITINT16 translate_ir_mul_ovf (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
94
static inline JITINT16 translate_ir_conv (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
95
static inline JITINT16 translate_ir_label(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction);
 
96
static inline JITINT16 translate_ir_branch(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction);
 
97
static inline JITINT16 translate_ir_branchif (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction);
 
98
static inline JITINT16 translate_ir_branchifnot (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction);
 
99
static inline JITINT16 translate_ir_call_finally(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction);
 
100
static inline JITINT16 translate_ir_call_filter(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction);
 
101
static inline JITINT16 translate_ir_start_filter(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction);
 
102
static inline JITINT16 translate_ir_start_finally(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction);
 
103
static inline JITINT16 translate_ir_branch_if_pc_not_in_range(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction);
 
104
static inline JITINT16 translate_ir_eq (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
105
static inline JITINT16 translate_ir_checknull (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
106
static inline JITINT16 translate_ir_lt (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
107
static inline JITINT16 translate_ir_gt (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
108
static inline JITINT16 translate_ir_store (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
109
static inline JITINT16 translate_ir_neg (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
110
static inline JITINT16 translate_ir_call (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
111
static inline JITINT16 translate_ir_vcall (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
112
static inline JITINT16 translate_ir_ncall (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
113
static inline JITINT16 translate_ir_icall (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
114
static inline JITINT16 translate_ir_initmemory (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
115
static inline JITINT16 translate_ir_memory_copy (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
116
static inline JITINT16 translate_ir_alloca (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
117
static inline JITINT16 translate_ir_throw (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
118
static inline JITINT16 translate_ir_get_address (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
119
static inline JITINT16 translate_ir_end_filter (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
120
static inline JITINT16 translate_ir_end_finally(ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
121
static inline JITINT16 translate_ir_start_catcher(ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
122
static inline JITINT16 translate_ir_uses_catcher(IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
123
static inline JITINT16 translate_ir_rethrow_unandled(ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
124
static inline JITINT16 translate_ir_thrown_exception_object(ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
125
static inline JITINT16 translate_ir_isNaN (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
126
static inline JITINT16 translate_ir_isInf(IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction);
 
127
 
 
128
static inline void internal_translateMethodToAssembly (IRVM_t *_this, ir_method_t *method, t_jit_function *jitFunction, JITINT32 enableTraceProfiler, trace_profiler_t *traceProfiler);
 
129
static inline void internal_makeTheMethodCallable (IRVM_t *_this, t_jit_function *jitFunction, ir_method_t *method);
 
130
static inline JITINT32 internal_run (t_jit_function *jitFunction, void **args, void *returnArea);
 
131
static inline jit_type_t internal_fromIRTypeToJITType (IRVM_t *_this, JITUINT32 IRType, ILType *ilType);
 
132
static inline void internal_shutdownIRVM (IRVM_t *_this);
 
133
static inline XanList * internal_getReferencedMethods (IRVM_t *_this, ir_method_t *method);
 
134
static inline void internal_lockMethods (XanList *list);
 
135
static inline void internal_unlockMethods (XanList *list);
 
136
 
 
137
void IRVirtualMachineNew (IRVM_t *_this, t_running_garbage_collector *gc, t_type_checker *type_checker, jit_type_t (*lookupValueType) (ILType *type), void (*fillILTypedReference)(ILType *ilType), ir_method_t * (*getIRMethod) (IR_ITEM_VALUE method), t_jit_function * (*getJITMethod) (IR_ITEM_VALUE method), JITINT32 (*recompilerFunction)(jit_function_t function)){
 
138
        pthread_mutexattr_t     mutex_attr;
 
139
        jit_type_t              params_ctor[1];
 
140
 
 
141
        /* Assertions                   */
 
142
        assert(_this != NULL);
 
143
        assert(gc != NULL);
 
144
        assert(lookupValueType != NULL);
 
145
        assert(fillILTypedReference != NULL);
 
146
        assert(type_checker != NULL);
 
147
 
 
148
        _this->type_checker                     = type_checker;
 
149
        _this->gc                               = gc;
 
150
        _this->lookupValueType                  = lookupValueType;
 
151
        _this->fillILTypedReference             = fillILTypedReference;
 
152
        _this->getIRMethod                      = getIRMethod;
 
153
        _this->getJITMethod                     = getJITMethod;
 
154
        _this->recompilerFunction               = recompilerFunction;
 
155
 
 
156
        pthread_mutexattr_init(&mutex_attr);
 
157
        pthread_mutex_init(&(_this->libjitMutex), &mutex_attr);
 
158
        pthread_mutex_init(&(_this->vmMutex), &mutex_attr);
 
159
 
 
160
        _this->shutdown                         = internal_shutdownIRVM;
 
161
        _this->lock                             = internal_lockLibjit;
 
162
        _this->unlock                           = internal_unlockLibjit;
 
163
        _this->translateMethodToAssembly        = internal_translateMethodToAssembly;
 
164
        _this->makeTheMethodCallable            = internal_makeTheMethodCallable;       
 
165
        _this->run                              = internal_run;
 
166
        _this->setExceptionHandler              = internal_setExceptionHandler;
 
167
        _this->newLibjitMethod                  = internal_newLibjitMethod;
 
168
 
 
169
        /* Create the JIT context                                       */
 
170
        _this->context                          = jit_context_create();
 
171
        assert(_this->context != NULL);
 
172
        if (!jit_context_supports_threads(_this->context)){
 
173
                print_err("IRVIRTUALMACHINE: ERROR: Libjit does not support threads. ", 0);
 
174
                abort();
 
175
        }
 
176
 
 
177
        /* Make the signature of the basic      *
 
178
         * constructor of the exceptions        */
 
179
        params_ctor[0]                                  = jit_type_void_ptr;
 
180
        _this->basicExceptionConstructorJITSignature    = jit_type_create_signature(jit_abi_cdecl, jit_type_void, params_ctor, 1, 1);
 
181
        
 
182
        /* Set the Libjit optimization level    */
 
183
        if ((_this->behavior).optimizations >= 3) {
 
184
                (_this->behavior).libjitOptimizations   = jit_function_get_max_optimization_level();
 
185
        }
 
186
 
 
187
        /* Return                               */
 
188
        return;
 
189
}       
 
190
 
 
191
void internal_setExceptionHandler (IRVM_t *_this, void * (*exceptionHandler) (int exception_type)){
 
192
 
 
193
        /* Assertions                           */
 
194
        assert(_this != NULL);
 
195
        assert(exceptionHandler != NULL);
 
196
 
 
197
        /* Lock Libjit                          */
 
198
        internal_lockLibjit(_this);
 
199
 
 
200
        /* Set a LIBJIT EXCEPTION HANDLER: USED *
 
201
         * TO PROPERLY INITIALIZE EXCEPTION     *
 
202
         * OBJECTS.                             */
 
203
        jit_exception_set_handler(exceptionHandler);
 
204
 
 
205
        /* Unlock Libjit                        */
 
206
        internal_unlockLibjit(_this);
 
207
 
 
208
        /* Return                               */
 
209
        return;
 
210
}
 
211
 
 
212
static inline void internal_makeTheMethodCallable (IRVM_t *_this, t_jit_function *jitFunction, ir_method_t *method){
 
213
 
 
214
        /* Assertions                           */
 
215
        assert(_this != NULL);
 
216
        assert(jitFunction != NULL);
 
217
        assert(jitFunction->entryPoint != NULL);
 
218
        
 
219
        jit_function_setup_entry(jitFunction->function, jitFunction->entryPoint);
 
220
 
 
221
        /* Dump the methods in the target       *
 
222
         * machine code                         */
 
223
        if (    ((_this->behavior).dumpAssembly.dumpAssembly)   &&
 
224
                (!jit_uses_interpreter())                       ){
 
225
                assert((_this->behavior).dumpAssembly.dumpFileAssembly != NULL);
 
226
                method->lock(method);
 
227
                jit_dump_function((_this->behavior).dumpAssembly.dumpFileAssembly, jitFunction->function, method->getCompleteName(method));
 
228
                method->unlock(method);
 
229
        }
 
230
}
 
231
 
 
232
static inline void internal_translateMethodToAssembly (IRVM_t *_this, ir_method_t *method, t_jit_function *jitFunction, JITINT32 enableTraceProfiler, trace_profiler_t *traceProfiler){
 
233
        t_ir_instruction        *currentIRInstruction;
 
234
        JITUINT32               *param;
 
235
        JITUINT32               params_count;
 
236
        JITUINT32               sum_count;
 
237
        XanList                 *labels;
 
238
        XanList                 *methodsReferenced;
 
239
        char                    buf[1024];
 
240
        jit_type_t              profilerStartSign;
 
241
        jit_type_t              profilerStopSign;
 
242
        jit_value_t             argsStart[1];
 
243
        jit_value_t             argsStop[2];
 
244
        JITUINT32               count;
 
245
        JITINT32                labelTraceIndex;
 
246
 
 
247
        /* Assertions                   */
 
248
        assert(method != NULL);
 
249
        assert(_this != NULL);
 
250
        assert(jitFunction != NULL);
 
251
 
 
252
        /* Init the variables           */
 
253
        labels                  = NULL;
 
254
        profilerStartSign       = NULL;
 
255
        profilerStopSign        = NULL;
 
256
        count                   = 0;
 
257
        labelTraceIndex         = 0;
 
258
 
 
259
        /* Lock the VM                  */
 
260
        internal_lockVM(_this);
 
261
 
 
262
        /* Check the locals             */
 
263
        if (jitFunction->locals != NULL){
 
264
                freeFunction(jitFunction->locals);
 
265
                jitFunction->locals   = NULL;
 
266
        }
 
267
        assert(jitFunction->locals == NULL);
 
268
 
 
269
        /* Allocate the list of labels  */
 
270
        labels  = xanListNew(allocFunction, freeFunction, NULL);
 
271
        assert(labels != NULL);
 
272
 
 
273
        /* Lock the method              */
 
274
        method->lock(method);
 
275
 
 
276
        /* Fetch the list of methods    *
 
277
         * referenced by the current one*/
 
278
        methodsReferenced       = internal_getReferencedMethods(_this, method);
 
279
        assert(methodsReferenced != NULL);
 
280
 
 
281
        /* Lock the referenced methods  */
 
282
        internal_lockMethods(methodsReferenced);
 
283
 
 
284
        /* Lock the libjit              */
 
285
        internal_lockLibjit(_this);
 
286
 
 
287
        /* Translate the feedback code  */
 
288
        //translate_enter_method_feedback_code(system, method);
 
289
 
 
290
        /* Fetch the first instruction  */
 
291
        PDEBUG("IRVIRTUALMACHINE: Translate the method into the machine language\n");
 
292
        currentIRInstruction = method->getNextInstruction(method, NULL);
 
293
 
 
294
        /* Profiling                            */
 
295
        if ((_this->behavior).profiler >= 4){
 
296
                jit_type_t      paramsStop[3];
 
297
                jit_type_t      paramsStart[1];
 
298
 
 
299
                /* Make the parameters of the   *
 
300
                 * profiler functions           */
 
301
                paramsStart[0]= jit_type_uint;
 
302
                paramsStop[0] = jit_type_void_ptr;
 
303
                paramsStop[1] = jit_type_void_ptr;
 
304
                paramsStop[2] = jit_type_uint;
 
305
 
 
306
                /* Make the signature of the    *
 
307
                 * profiler functions           */
 
308
                profilerStartSign       = jit_type_create_signature(jit_abi_cdecl, jit_type_void, paramsStart, 1, 0);
 
309
                profilerStopSign        = jit_type_create_signature(jit_abi_cdecl, jit_type_void, paramsStop, 3, 0);
 
310
 
 
311
                /* Make the arguments of the    *
 
312
                 * profiler stop functions      */
 
313
                argsStop[0]     = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr, (JITNUINT) NULL);
 
314
                argsStop[1]     = jit_value_create_nint_constant (jitFunction->function, jit_type_uint, 0);
 
315
 
 
316
                /* Call the profiler stop       *
 
317
                 * functions                    */
 
318
                //jit_insn_call_native(jitFunction->function, "profilerIRStopTime", profilerIRStopTime, profilerStopSign, argsStop, 2, JIT_CALL_NOTHROW); TODO da decommentare
 
319
        }
 
320
 
 
321
        /* Trace profiler */
 
322
        if(enableTraceProfiler){
 
323
                PDEBUG("IRPROFILER: ENABLE TRACE PROFILER\n");
 
324
                PDEBUG("IRPROFILER: CALL TO THE OPTIMIZATOR\n");
 
325
                (_this->optimizer).callMethodOptimization(&(_this->optimizer), method, &(_this->ir_system),BASIC_BLOCK_IDENTIFIER);
 
326
                PDEBUG("IRPROFILER: CALL TO THE TRACE GENERATOR\n");
 
327
                traceProfiler->generateTraces(traceProfiler);
 
328
        }
 
329
 
 
330
        /* Create the locals            */
 
331
        params_count    = method->getParametersNumber(method);
 
332
        PDEBUG("IRVIRTUALMACHINE:               Make %d variables\n", method->getMaxVariables(method));
 
333
        PDEBUG("IRVIRTUALMACHINE:                       %d locals\n", method->getLocalsNumber(method));
 
334
        PDEBUG("IRVIRTUALMACHINE:                       %d parameters\n", params_count);
 
335
        if (method->getMaxVariables(method) > 0){
 
336
                jitFunction->locals             = (jit_value_t *) allocFunction(sizeof(jit_value_t) * (method->getMaxVariables(method) + 1));
 
337
                assert(jitFunction->locals != NULL);
 
338
                memset(jitFunction->locals, 0, sizeof(jit_value_t) * (method->getMaxVariables(method)));
 
339
        }
 
340
 
 
341
        /* Create the variables         */
 
342
        PDEBUG("IRVIRTUALMACHINE:               Create %d locals\n", method->getLocalsNumber(method));
 
343
        param = NULL;
 
344
        sum_count = params_count + method->getLocalsNumber(method);
 
345
        for(count = params_count; count < sum_count; count++) {
 
346
                jit_type_t      JITvalueType;
 
347
                ILType          *valueType;
 
348
                ILType          iltype;
 
349
                #ifdef DEBUG
 
350
                jit_type_t      type;
 
351
                #endif
 
352
                param = method->getNextLocal(method, param);
 
353
                assert(param != NULL);
 
354
                switch (*param){
 
355
                        case IRINT64:
 
356
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as INT64\n", count);
 
357
                                jitFunction->locals[count]              = jit_value_create(jitFunction->function, jit_type_long);
 
358
                                #ifdef DEBUG
 
359
                                type = jit_value_get_type(jitFunction->locals[count]);
 
360
                                assert(type == jit_type_long);
 
361
                                #endif
 
362
                                break;
 
363
                        case IRINT32:
 
364
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as INT32\n", count);
 
365
                                jitFunction->locals[count]              = jit_value_create(jitFunction->function, jit_type_int);
 
366
                                #ifdef DEBUG
 
367
                                type = jit_value_get_type(jitFunction->locals[count]);
 
368
                                assert(type == jit_type_int);
 
369
                                #endif
 
370
                                break;
 
371
                        case IRINT16:
 
372
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as INT16\n", count);
 
373
                                jitFunction->locals[count]              = jit_value_create(jitFunction->function, jit_type_short);
 
374
                                #ifdef DEBUG
 
375
                                type = jit_value_get_type(jitFunction->locals[count]);
 
376
                                assert(type == jit_type_short);
 
377
                                #endif
 
378
                                break;
 
379
                        case IRINT8:
 
380
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as INT8\n", count);
 
381
                                jitFunction->locals[count]              = jit_value_create(jitFunction->function, jit_type_sbyte);
 
382
                                #ifdef DEBUG
 
383
                                type                    = jit_value_get_type(jitFunction->locals[count]);
 
384
                                assert(type == jit_type_sbyte);
 
385
                                #endif
 
386
                                break;
 
387
                        case IRNINT:
 
388
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as NINT\n", count);
 
389
                                jitFunction->locals[count]              = jit_value_create(jitFunction->function, jit_type_nint);
 
390
                                #ifdef DEBUG
 
391
                                type = jit_value_get_type(jitFunction->locals[count]);
 
392
                                assert(type == jit_type_nint);
 
393
                                #endif
 
394
                                break;
 
395
                        case IRUINT64:
 
396
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as UINT64\n", count);
 
397
                                jitFunction->locals[count] = jit_value_create(jitFunction->function, jit_type_ulong);
 
398
                                #ifdef DEBUG
 
399
                                type = jit_value_get_type(jitFunction->locals[count]);
 
400
                                assert(type == jit_type_ulong);
 
401
                                #endif
 
402
                                break;
 
403
                        case IRUINT32:
 
404
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as UINT32\n", count);
 
405
                                jitFunction->locals[count] = jit_value_create(jitFunction->function, jit_type_uint);
 
406
                                #ifdef DEBUG
 
407
                                type = jit_value_get_type(jitFunction->locals[count]);
 
408
                                assert(type == jit_type_uint);
 
409
                                #endif
 
410
                                break;
 
411
                        case IRUINT16:
 
412
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as UINT16\n", count);
 
413
                                jitFunction->locals[count]              = jit_value_create(jitFunction->function, jit_type_ushort);
 
414
                                #ifdef DEBUG
 
415
                                type = jit_value_get_type(jitFunction->locals[count]);
 
416
                                assert(type == jit_type_ushort);
 
417
                                #endif
 
418
                                break;
 
419
                        case IRUINT8:
 
420
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as UINT8\n", count);
 
421
                                jitFunction->locals[count]              = jit_value_create(jitFunction->function, jit_type_ubyte);
 
422
                                #ifdef DEBUG
 
423
                                type            = jit_value_get_type(jitFunction->locals[count]);
 
424
                                assert(type == jit_type_ubyte);
 
425
                                #endif
 
426
                                break;
 
427
                        case IRNUINT:
 
428
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as NUINT\n", count);
 
429
                                jitFunction->locals[count]              = jit_value_create(jitFunction->function, jit_type_nuint);
 
430
                                #ifdef DEBUG
 
431
                                type = jit_value_get_type(jitFunction->locals[count]);
 
432
                                assert(type == jit_type_nuint);
 
433
                                #endif
 
434
                                break;
 
435
                        case IRFLOAT32:
 
436
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as FLOAT32\n", count);
 
437
                                jitFunction->locals[count] = jit_value_create(jitFunction->function, jit_type_float32);
 
438
                                #ifdef DEBUG
 
439
                                type = jit_value_get_type(jitFunction->locals[count]);
 
440
                                assert(type == jit_type_float32);
 
441
                                #endif
 
442
                                break;
 
443
                        case IRFLOAT64:
 
444
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as FLOAT64\n", count);
 
445
                                jitFunction->locals[count] = jit_value_create(jitFunction->function, jit_type_float64);
 
446
                                #ifdef DEBUG
 
447
                                type = jit_value_get_type(jitFunction->locals[count]);
 
448
                                assert(type == jit_type_float64);
 
449
                                #endif
 
450
                                break;
 
451
                        case IRNFLOAT:
 
452
                                if (sizeof(JITNUINT) == 4){
 
453
                                        PDEBUG("IRVIRTUALMACHINE:                       Make local %d as FLOAT32\n", count);
 
454
                                        jitFunction->locals[count] = jit_value_create(jitFunction->function, jit_type_float32);
 
455
                                        #ifdef DEBUG
 
456
                                        type = jit_value_get_type(jitFunction->locals[count]);
 
457
                                        assert(type == jit_type_float32);
 
458
                                        #endif
 
459
                                } else {
 
460
                                        PDEBUG("IRVIRTUALMACHINE:                       Make local %d as FLOAT64\n", count);
 
461
                                        jitFunction->locals[count] = jit_value_create(jitFunction->function, jit_type_float64);
 
462
                                        #ifdef DEBUG
 
463
                                        type = jit_value_get_type(jitFunction->locals[count]);
 
464
                                        assert(type == jit_type_float64);
 
465
                                        #endif
 
466
                                }
 
467
                                break;
 
468
                        case IROBJECT:
 
469
                        case IRUPOINTER:
 
470
                        case IRMPOINTER:
 
471
                        case IRTPOINTER:
 
472
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as POINTER\n", count);
 
473
                                jitFunction->locals[count] = jit_value_create   (jitFunction->function, jit_type_void_ptr);
 
474
                                #ifdef DEBUG
 
475
                                type = jit_value_get_type(jitFunction->locals[count]);
 
476
                                assert(type == jit_type_void_ptr);
 
477
                                #endif
 
478
                                break;
 
479
                        case IRVALUETYPE:
 
480
                                assert(method->local_signature->decoded_locals != NULL);
 
481
                                assert(((method->local_signature->decoded_locals) + (count - params_count)) != NULL);
 
482
                                assert((method->local_signature->decoded_locals[count - params_count]).type != NULL);
 
483
                                assert(((method->local_signature->decoded_locals[count - params_count]).type)->type == ELEMENT_TYPE_VALUETYPE);
 
484
                                assert(((method->local_signature->decoded_locals[count - params_count]).type)->type_infos != NULL);
 
485
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as VALUETYPE\n", count);
 
486
 
 
487
                                /* retrieve the IL type associated with the valuetype */
 
488
                                valueType = (ILType *)((method->local_signature->decoded_locals[count - params_count]).type)->type_infos;
 
489
                                assert(valueType != NULL);
 
490
                                assert(valueType->ID != NULL);
 
491
                                assert(valueType->binary != NULL);
 
492
 
 
493
                                /* retrieve the JIT type associated with the valuetype */
 
494
                                JITvalueType    = _this->lookupValueType(valueType);
 
495
                                assert(JITvalueType != NULL);
 
496
 
 
497
                                /* create the JIT variable for the current valuetype */
 
498
                                jitFunction->locals[count] = jit_value_create(jitFunction->function, JITvalueType);
 
499
                                assert(jitFunction->locals[count] != NULL);
 
500
 
 
501
                                #ifdef DEBUG
 
502
                                type = jit_value_get_type(jitFunction->locals[count]);
 
503
                                assert(type == JITvalueType);
 
504
                                #endif
 
505
                                break;
 
506
                        case IRTYPEDREF:
 
507
                                PDEBUG("IRVIRTUALMACHINE:                       Make local %d as TYPEDREFERENCE\n", count);
 
508
                                
 
509
                                /* retrieve the IL type associated with the valuetype */
 
510
                                _this->fillILTypedReference(&iltype);
 
511
                                assert(iltype.ID != NULL);
 
512
                                assert(iltype.binary != NULL);
 
513
                                
 
514
                                /* retrieve the JIT type associated with the valuetype */
 
515
                                JITvalueType    = _this->lookupValueType(&iltype);
 
516
                                assert(JITvalueType != NULL);
 
517
                                
 
518
                                /* create the JIT variable for the current valuetype */
 
519
                                jitFunction->locals[count] = jit_value_create(jitFunction->function, JITvalueType);
 
520
                                assert(jitFunction->locals[count] != NULL);
 
521
                                
 
522
                                #ifdef DEBUG
 
523
                                type = jit_value_get_type(jitFunction->locals[count]);
 
524
                                assert(type == JITvalueType);
 
525
                                #endif
 
526
                                break;
 
527
                        default:
 
528
                                PDEBUG("%d \n", (*param));
 
529
                                snprintf(buf, sizeof(buf), "IRVIRTUALMACHINE: ERROR = Type of local %u is not known. ", count - method->getParametersNumber(method));
 
530
                                print_err(buf, 0);
 
531
                                abort();
 
532
                }
 
533
                assert((jitFunction->locals[count]) != NULL);
 
534
        }
 
535
 
 
536
        /* Fetch the parameters         */
 
537
        fetch_parameters(method, jitFunction);
 
538
 
 
539
        /* Set the tracer               */
 
540
        if ((_this->behavior).tracer){
 
541
                if (method->getInstructionType(method, currentIRInstruction) != IRUSESCATCHER){
 
542
                        PDEBUG("IRVIRTUALMACHINE:               Insert the tracer call\n");
 
543
                        insert_tracer(_this, method, jitFunction, JITFALSE);
 
544
                }
 
545
        }
 
546
 
 
547
        /* Insert the native start call */
 
548
        #ifdef MORPHEUS
 
549
        internal_insert_native_start_function(method);
 
550
        #endif
 
551
 
 
552
        /* Update the root set                  */
 
553
        method->updateRootSet(method);
 
554
 
 
555
        /* Translate the IR method to   *
 
556
         * the libjit method            */
 
557
        #ifdef PRINTDEBUG
 
558
        count   = 0;
 
559
        #endif
 
560
        while (currentIRInstruction != NULL){
 
561
                assert(currentIRInstruction != NULL);
 
562
 
 
563
                #ifdef PRINTDEBUG
 
564
                PDEBUG("IRVIRTUALMACHINE: Instruction %d\n", count);
 
565
                count++;
 
566
                #endif
 
567
 
 
568
                /* Profiling                            */
 
569
                if ((_this->behavior).profiler >= 4){
 
570
                        argsStart[0] = jit_value_create_nint_constant (jitFunction->function, jit_type_uint , (JITNUINT) currentIRInstruction->type);
 
571
                        //jit_insn_call_native(jitFunction->function, "profilerIRStopTime" , profilerIRStopTime, profilerStopSign , argsStop, 2, JIT_CALL_NOTHROW); TODO da decommentare
 
572
                        //jit_insn_call_native(jitFunction->function, "profilerIRStartTime" , profilerIRStartTime, profilerStartSign , argsStart, 1, JIT_CALL_NOTHROW); TODO da decommentare
 
573
                }
 
574
 
 
575
                /* Trace Profiler */
 
576
                if(enableTraceProfiler){
 
577
                        PDEBUG("IRPROFILER: INSERT TRACE PROFILER NATIVE CALLS\n");
 
578
                        labelTraceIndex = insertTraceProfiler(currentIRInstruction, labelTraceIndex, jitFunction, traceProfiler);
 
579
                }
 
580
 
 
581
                /* Bind the offset information to the jit       *
 
582
                 * instruction                                  */
 
583
                bind_instruction_offset(_this, method, currentIRInstruction, jitFunction);
 
584
 
 
585
                /* Convert the current IR instruction   */
 
586
                switch (currentIRInstruction->type){
 
587
                        case IRADD:
 
588
                                translate_ir_add(_this, method, currentIRInstruction, jitFunction);
 
589
                                break;
 
590
                        case IRADDOVF:
 
591
                                translate_ir_add_ovf(_this, method, currentIRInstruction, jitFunction);
 
592
                                break;
 
593
                        case IRAND:
 
594
                                translate_ir_and(_this, method, currentIRInstruction, jitFunction);
 
595
                                break;
 
596
                        case IRBRANCH:
 
597
                                translate_ir_branch(method, currentIRInstruction, labels, jitFunction);
 
598
                                break;
 
599
                        case IRBRANCHIF:
 
600
                                translate_ir_branchif(_this, method, currentIRInstruction, labels, jitFunction);
 
601
                                break;
 
602
                        case IRBRANCHIFNOT:
 
603
                                translate_ir_branchifnot(_this, method, currentIRInstruction, labels, jitFunction);
 
604
                                break;
 
605
                        case IRCALL:
 
606
                                translate_ir_call(_this, method, currentIRInstruction, jitFunction);
 
607
                                break;
 
608
                        case IRCHECKNULL:
 
609
                                translate_ir_checknull(_this, method, currentIRInstruction, jitFunction);
 
610
                                break;
 
611
                        case IRCONV:
 
612
                                translate_ir_conv(_this, method, currentIRInstruction, jitFunction);
 
613
                                break;
 
614
                        case IRDIV:
 
615
                                translate_ir_div(_this, method, currentIRInstruction, jitFunction);
 
616
                                break;
 
617
                        case IREQ:
 
618
                                translate_ir_eq(_this, method, currentIRInstruction, jitFunction);
 
619
                                break;
 
620
                        case IRGETADDRESS:
 
621
                                translate_ir_get_address(_this, method, currentIRInstruction, jitFunction);
 
622
                                break;
 
623
                        case IRGT:
 
624
                                translate_ir_gt(_this, method, currentIRInstruction, jitFunction);
 
625
                                break;
 
626
                        case IRLABEL:
 
627
                                translate_ir_label(method, currentIRInstruction, labels, jitFunction);
 
628
                                break;
 
629
                        case IRLOADELEM:
 
630
                                translate_ir_load_elem(_this, method, currentIRInstruction, jitFunction);
 
631
                                break;
 
632
                        case IRLOADREL:
 
633
                                translate_ir_load_rel(_this, method, currentIRInstruction, jitFunction);
 
634
                                break;
 
635
                        case IRLT:
 
636
                                translate_ir_lt(_this, method, currentIRInstruction, jitFunction);
 
637
                                break;
 
638
                        case IRNOP:
 
639
                                break;
 
640
                        case IRNOT:
 
641
                                translate_ir_not(_this, method, currentIRInstruction, jitFunction);
 
642
                                break;
 
643
                        case IRNCALL:
 
644
                                translate_ir_ncall(_this, method, currentIRInstruction, jitFunction);
 
645
                                break;
 
646
                        case IRNEG:
 
647
                                translate_ir_neg(_this, method, currentIRInstruction, jitFunction);
 
648
                                break;
 
649
                        case IRNEWARR:
 
650
                                translate_ir_newarr(_this, method, currentIRInstruction, jitFunction);
 
651
                                break;
 
652
                        case IRNEWOBJ:
 
653
                                translate_ir_newobj(_this, method, currentIRInstruction, jitFunction);
 
654
                                break;
 
655
                        case IRMUL:
 
656
                                translate_ir_mul(_this, method, currentIRInstruction, jitFunction);
 
657
                                break;
 
658
                        case IRMULOVF:
 
659
                                translate_ir_mul_ovf(_this, method, currentIRInstruction, jitFunction);
 
660
                                break;
 
661
                        case IROR:
 
662
                                translate_ir_or(_this, method, currentIRInstruction, jitFunction);
 
663
                                break;
 
664
                        case IRREM:
 
665
                                translate_ir_rem(_this, method, currentIRInstruction, jitFunction);
 
666
                                break;
 
667
                        case IRRET:
 
668
                                translate_ir_ret(_this, method, currentIRInstruction, jitFunction);
 
669
                                break;
 
670
                        case IRSHL:
 
671
                                translate_ir_shl(_this, method, currentIRInstruction, jitFunction);
 
672
                                break;
 
673
                        case IRSHR:
 
674
                                translate_ir_shr(_this, method, currentIRInstruction, jitFunction);
 
675
                                break;
 
676
                        case IRSUB:
 
677
                                translate_ir_sub(_this, method, currentIRInstruction, jitFunction);
 
678
                                break;
 
679
                        case IRSUBOVF:
 
680
                                translate_ir_sub_ovf(_this, method, currentIRInstruction, jitFunction);
 
681
                                break;
 
682
                        case IRSTORE:
 
683
                                translate_ir_store(_this, method, currentIRInstruction, jitFunction);
 
684
                                break;
 
685
                        case IRSTOREELEM:
 
686
                                translate_ir_store_elem(_this, method, currentIRInstruction, jitFunction);
 
687
                                break;
 
688
                        case IRSTOREREL:
 
689
                                translate_ir_store_rel(_this, method, currentIRInstruction, jitFunction);
 
690
                                break;
 
691
                        case IRVCALL:
 
692
                                translate_ir_vcall(_this, method, currentIRInstruction, jitFunction);
 
693
                                break;
 
694
                        case IRXOR:
 
695
                                translate_ir_xor(_this, method, currentIRInstruction, jitFunction);
 
696
                                break;
 
697
                        case IRCALLFINALLY:
 
698
                                translate_ir_call_finally(method, currentIRInstruction, labels, jitFunction);
 
699
                                break;
 
700
                        case IRTHROW:
 
701
                                translate_ir_throw(_this, method, currentIRInstruction, jitFunction);
 
702
                                break;
 
703
                        case IRSTARTFILTER:
 
704
                                translate_ir_start_filter(method, currentIRInstruction, labels, jitFunction);
 
705
                                break;
 
706
                        case IRENDFILTER:
 
707
                                translate_ir_end_filter(_this, method, currentIRInstruction, jitFunction);
 
708
                                break;
 
709
                        case IRSTARTFINALLY:
 
710
                                translate_ir_start_finally(method, currentIRInstruction, labels, jitFunction);
 
711
                                break;
 
712
                        case IRENDFINALLY:
 
713
                                translate_ir_end_finally(method, currentIRInstruction, jitFunction);
 
714
                                break;
 
715
                        case IRSTARTCATCHER:
 
716
                                translate_ir_start_catcher(method, currentIRInstruction, jitFunction);
 
717
                                break;
 
718
                        case IRUSESCATCHER:
 
719
                                translate_ir_uses_catcher(_this, method, currentIRInstruction, jitFunction);
 
720
                                break;
 
721
                        case IRBRANCHIFPCNOTINRANGE:
 
722
                                translate_ir_branch_if_pc_not_in_range(method, currentIRInstruction, labels, jitFunction);
 
723
                                break;
 
724
                        case IRRETHROWUNHANDLED:
 
725
                                translate_ir_rethrow_unandled(method , currentIRInstruction, jitFunction);
 
726
                                break;
 
727
                        case IRCALLFILTER:
 
728
                                translate_ir_call_filter(method, currentIRInstruction, labels, jitFunction);
 
729
                                break;
 
730
                        case IRTHROWNEXCEPTIONOBJECT:
 
731
                                translate_ir_thrown_exception_object(method, currentIRInstruction, jitFunction);
 
732
                                break;
 
733
                        case IRISNAN:
 
734
                                translate_ir_isNaN(_this, method, currentIRInstruction, jitFunction);
 
735
                                break;
 
736
                        case IRISINF:
 
737
                                translate_ir_isInf(_this, method, currentIRInstruction, jitFunction);
 
738
                                break;
 
739
                        case IRCALLINDIRECTCCTOR:
 
740
                                translate_ir_call_indirect_exception_ctor(_this, method, currentIRInstruction, jitFunction);
 
741
                                break;
 
742
                        case IRICALL:
 
743
                                translate_ir_icall(_this, method, currentIRInstruction, jitFunction);
 
744
                                break;
 
745
                        case IRINITMEMORY:
 
746
                                translate_ir_initmemory(_this, method, currentIRInstruction, jitFunction);
 
747
                                break;
 
748
                        case IRMEMCPY:
 
749
                                translate_ir_memory_copy(_this, method, currentIRInstruction, jitFunction);
 
750
                                break;
 
751
                        case IRALLOCA:
 
752
                                translate_ir_alloca(_this, method, currentIRInstruction, jitFunction);
 
753
                                break;
 
754
                        default :
 
755
                                snprintf(buf, sizeof(buf), "IRVIRTUALMACHINE: ERROR= IR instruction %d not knwon\n", currentIRInstruction->type);
 
756
                                print_err(buf, 0);
 
757
                                abort();
 
758
                }
 
759
                PDEBUG("IRVIRTUALMACHINE:                       Translated\n");
 
760
 
 
761
                /* Insert call for trace profiler after label */
 
762
                if((enableTraceProfiler) && (labelTraceIndex >= 0)){
 
763
                        labelTraceIndex = insertTraceProfiler(currentIRInstruction, labelTraceIndex, jitFunction, traceProfiler);
 
764
                }
 
765
 
 
766
                /* Profiling                            */
 
767
                if ((_this->behavior).profiler >= 4){
 
768
                        //jit_insn_call_native(jitFunction->function, "profilerIRStopTime", profilerIRStopTime, profilerStopSign, argsStop, 2, JIT_CALL_NOTHROW); TODO da decommentare
 
769
                }
 
770
 
 
771
                /* Fetch the next item          */
 
772
                assert(currentIRInstruction != NULL);
 
773
                currentIRInstruction = method->getNextInstruction(method, currentIRInstruction);
 
774
        }
 
775
 
 
776
        /* Check the labels             */
 
777
#ifdef PRINTDEBUG
 
778
        check_labels(labels);
 
779
#endif
 
780
 
 
781
        /* Refresh the root set         */
 
782
        variablesToRootSets(_this, method, jitFunction);
 
783
 
 
784
        /* Free the signature           */
 
785
        if ((_this->behavior).profiler >= 4){
 
786
                jit_type_free(profilerStartSign);
 
787
                jit_type_free(profilerStopSign);
 
788
        }
 
789
 
 
790
        /* Dump the assembly            */
 
791
        if ((_this->behavior).dumpAssembly.dumpAssembly){
 
792
                assert((_this->behavior).dumpAssembly.dumpFileJIT != NULL);
 
793
                jit_dump_function((_this->behavior).dumpAssembly.dumpFileJIT, jitFunction->function, method->getName(method));
 
794
        }
 
795
 
 
796
        /* Compile the function         */
 
797
        PDEBUG("IRVIRTUALMACHINE:               Compile the method\n");
 
798
        jitFunction->entryPoint = NULL;
 
799
        if (jit_function_compile_entry(jitFunction->function, &(jitFunction->entryPoint)) == 0){
 
800
                print_err("IRVIRTUALMACHINE: ERROR = During compiling the function. ", 0);
 
801
                abort();
 
802
        }
 
803
        assert(jitFunction->entryPoint != NULL);
 
804
 
 
805
        /* Unlock Libjit                                */
 
806
        internal_unlockLibjit(_this);   
 
807
 
 
808
        /* Unlock the methods referenced*/
 
809
        internal_unlockMethods(methodsReferenced);
 
810
 
 
811
        /* Unlock the method                            */
 
812
        method->unlock(method);
 
813
        
 
814
        /* Free the memory              */
 
815
        labels->destroyList(labels);
 
816
        methodsReferenced->destroyList(methodsReferenced);
 
817
 
 
818
        /* Unlock the VM                                */
 
819
        internal_unlockVM(_this);
 
820
 
 
821
        /* Return                                       */
 
822
        PDEBUG("IRVIRTUALMACHINE:               Exit from the build phase\n");
 
823
        return;
 
824
}
 
825
 
 
826
static inline jit_type_t internal_fromIRTypeToJITType (IRVM_t *_this, JITUINT32 IRType, ILType *ilType){
 
827
        jit_type_t      type;
 
828
        char            buf[1024];
 
829
 
 
830
        /* Assertions                   */
 
831
        assert(_this != NULL);
 
832
 
 
833
        /* initialize the local variable */
 
834
        type = NULL;
 
835
 
 
836
        /* Make the type conversion     */
 
837
        switch (IRType){
 
838
                case IRINT8:
 
839
                        type    = jit_type_sbyte;
 
840
                        break;
 
841
                case IRINT16:
 
842
                        type    = jit_type_short;
 
843
                        break;
 
844
                case IRINT32:
 
845
                        type    = jit_type_int;
 
846
                        break;
 
847
                case IRINT64:
 
848
                        type    = jit_type_long;
 
849
                        break;
 
850
                case IRNINT:
 
851
                        type    = jit_type_nint;
 
852
                        break;
 
853
                case IRUINT8:
 
854
                        type    = jit_type_ubyte;
 
855
                        break;
 
856
                case IRUINT16:
 
857
                        type    = jit_type_ushort;
 
858
                        break;
 
859
                case IRUINT32:
 
860
                        type    = jit_type_uint;
 
861
                        break;
 
862
                case IRUINT64:
 
863
                        type    = jit_type_ulong;
 
864
                        break;
 
865
                case IRNUINT:
 
866
                        type    = jit_type_nuint;
 
867
                        break;
 
868
                case IRFLOAT32:
 
869
                        type    = jit_type_float32;
 
870
                        break;
 
871
                case IRFLOAT64:
 
872
                        type    = jit_type_float64;
 
873
                        break;
 
874
                case IRNFLOAT:
 
875
                        type    = jit_type_nfloat;
 
876
                        break;
 
877
                case IRUPOINTER:
 
878
                case IRMPOINTER:
 
879
                case IRTPOINTER:
 
880
                case IRCLASSID:
 
881
                case IRMETHODID:
 
882
                case IROBJECT:
 
883
                        type    = jit_type_void_ptr;
 
884
                        break;
 
885
                case IRVALUETYPE:
 
886
                case IRTYPEDREF:
 
887
                        assert(ilType != NULL);
 
888
                        assert(ilType->ID != NULL);
 
889
                        assert(ilType->binary != NULL);
 
890
                        type    = _this->lookupValueType(ilType);
 
891
                        break;
 
892
                case IRVOID:
 
893
                        type    = jit_type_void;
 
894
                        break;
 
895
                default :
 
896
                        snprintf(buf, sizeof(char)*1024, "IRVIRTUALMACHINE: fromIRTypeToJitType: ERROR = IR type %u is not known. ", IRType);
 
897
                        print_err(buf, 0);
 
898
                        abort();
 
899
        }
 
900
 
 
901
        /* Return               */
 
902
        return type;
 
903
}
 
904
 
 
905
void insert_tracer (IRVM_t *_this, ir_method_t *method, t_jit_function *jitFunction, JITBOOLEAN exitMethod){
 
906
        jit_type_t      sign;
 
907
        jit_type_t      params[2];
 
908
        jit_value_t     args[2];
 
909
 
 
910
        /* Assertions                                   */
 
911
        assert(_this != NULL);
 
912
        assert(_this->type_checker != NULL);
 
913
        assert(method != NULL);
 
914
        assert(jitFunction != NULL);
 
915
 
 
916
        /* Create the parameters                        */
 
917
        params[0] = jit_type_void_ptr;
 
918
        params[1] = jit_type_void_ptr;
 
919
 
 
920
        /* Create the signature                         */
 
921
        sign = jit_type_create_signature(jit_abi_cdecl, jit_type_void, params, 2, 0);
 
922
        assert(sign != NULL);
 
923
 
 
924
        /* Create the arguments                         */
 
925
        args[0] = jit_value_create_nint_constant(jitFunction->function, jit_type_void_ptr, (JITNUINT) _this);
 
926
        args[1] = jit_value_create_nint_constant(jitFunction->function, jit_type_void_ptr, (JITNUINT) method);
 
927
 
 
928
        /* Call the tracer                              */
 
929
        if (exitMethod == 0){
 
930
                jit_insn_call_native(jitFunction->function , "tracer_startMethod", tracer_startMethod, sign, args, 2, JIT_CALL_NOTHROW);
 
931
        } else {
 
932
                jit_insn_call_native(jitFunction->function , "tracer_exitMethod", tracer_exitMethod, sign, args, 2, JIT_CALL_NOTHROW);
 
933
        }
 
934
 
 
935
        /* Free the signature                           */
 
936
        jit_type_free(sign);
 
937
 
 
938
        /* Return                                       */
 
939
        return;
 
940
}
 
941
 
 
942
JITINT32 insertTraceProfiler (t_ir_instruction *inst, JITINT32 prevIndex, t_jit_function *jitFunction, trace_profiler_t *profiler){
 
943
        jit_type_t              sign;
 
944
        jit_type_t              params[1];
 
945
        jit_value_t             args[1];
 
946
        JITUINT32               index;
 
947
        JITUINT32               traceNumber;
 
948
        trace_t                 *trace;
 
949
        JITUINT32               instID;
 
950
 
 
951
        /* Assertions                           */
 
952
        assert(profiler != NULL);
 
953
 
 
954
        if(prevIndex >= 0){
 
955
                PDEBUG("IRPROFILER: REAL INSERT START AFTER LABEL FOR INSTRUCTION %d\n", prevIndex);
 
956
                index = prevIndex;
 
957
                trace = profiler->getTrace(profiler, index);
 
958
 
 
959
                params[0] = jit_type_void_ptr;
 
960
                sign = jit_type_create_signature(jit_abi_cdecl, jit_type_void, params, 1, 0);
 
961
                args[0] = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr, (JITNUINT) trace);
 
962
 
 
963
                jit_insn_call_native(jitFunction->function , "trace_startTraceProfiling", trace_startTraceProfiling, sign, args, 1, JIT_CALL_NOTHROW);
 
964
 
 
965
                #ifdef PRINTDEBUG
 
966
                trace->printTrace(trace, stderr);
 
967
                #endif
 
968
 
 
969
                return -1;
 
970
        }
 
971
 
 
972
        PDEBUG("IRPROFILER: SEARCH IF INSERT NATIVE CALL ");
 
973
 
 
974
        traceNumber     = profiler->getTraceNumber(profiler);
 
975
        instID          = inst->ID;
 
976
 
 
977
        PDEBUG("FOR INSTRUCTION %d : ", instID);
 
978
 
 
979
        for(index = 0; index < traceNumber; index ++){
 
980
                trace = profiler->getTrace(profiler, index);
 
981
 
 
982
 
 
983
                if(trace->getFirstInstID(trace) == instID){
 
984
 
 
985
                        PDEBUG("INSERT START CALL AT TRACE %d (%p, %u)\n", index, trace, (JITNUINT) trace);
 
986
 
 
987
                        return index;
 
988
 
 
989
                } else if(trace->getLastInstID(trace) == instID){
 
990
                        PDEBUG("INSERT END CALL AT TRACE %d (%p, %u)\n", index, trace, (JITNUINT) trace);
 
991
 
 
992
                        params[0] = jit_type_void_ptr;
 
993
                        sign = jit_type_create_signature(jit_abi_cdecl, jit_type_void, params, 1, 0);
 
994
                        args[0] = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr, (JITNUINT) trace);
 
995
 
 
996
                        jit_insn_call_native(jitFunction->function , "trace_stopTraceProfiling", trace_stopTraceProfiling, sign, args, 1, JIT_CALL_NOTHROW);
 
997
 
 
998
 
 
999
                        #ifdef PRINTDEBUG
 
1000
                        trace->printTrace(trace, stderr);
 
1001
                        #endif
 
1002
 
 
1003
                        return -1;
 
1004
 
 
1005
                }
 
1006
        }
 
1007
 
 
1008
        PDEBUG("INSTRUCTION SKIP\n");
 
1009
        return -1;
 
1010
}
 
1011
 
 
1012
static inline jit_value_t make_variable (IRVM_t *_this, ir_method_t *method, ir_item_t *item, t_jit_function *jitFunction){
 
1013
        jit_value_t     param;
 
1014
        jit_value_t     var;
 
1015
        char            buf[1024];
 
1016
        ILType          iltype;
 
1017
        ILType          *ilt;
 
1018
        jit_type_t      JITvalueType;
 
1019
 
 
1020
        /* Assertions           */
 
1021
        assert(_this != NULL);
 
1022
        assert(method != NULL);
 
1023
        assert(item != NULL);
 
1024
        assert(jitFunction != NULL);
 
1025
 
 
1026
        /* Init the variables   */
 
1027
        param   = NULL;
 
1028
        ilt     = NULL;
 
1029
 
 
1030
        switch (item->type){
 
1031
                case IROFFSET:
 
1032
                        PDEBUG("Variable %lld", item->value);
 
1033
                        assert(item->value < method->getMaxVariables(method));
 
1034
                        if (jitFunction->locals[item->value] == NULL){
 
1035
                                jitFunction->locals[item->value]        = jit_value_create(jitFunction->function, internal_fromIRTypeToJITType(_this, item->internal_type, (item->value_type_infos).type_infos));
 
1036
                        }
 
1037
                        assert (jitFunction->locals[item->value] != NULL);
 
1038
                        param   = jitFunction->locals[item->value];
 
1039
                        PDEBUG("; ");
 
1040
                        return param;
 
1041
                case IRINT8:
 
1042
                        PDEBUG("INT8 %lld", item->value);
 
1043
                        param = jit_value_create_nint_constant(jitFunction->function, jit_type_sbyte, (JITINT32) item->value);
 
1044
                        break;
 
1045
                case IRINT16:
 
1046
                        PDEBUG("INT16 %lld", item->value);
 
1047
                        param = jit_value_create_nint_constant(jitFunction->function, jit_type_short, (JITINT32) item->value);
 
1048
                        break;
 
1049
                case IRINT32:
 
1050
                        PDEBUG("INT32 %lld", item->value);
 
1051
                        param = jit_value_create_nint_constant(jitFunction->function, jit_type_int, (JITINT32) item->value);
 
1052
                        break;
 
1053
                case IRINT64:
 
1054
                        PDEBUG("INT64 %lld", item->value);
 
1055
                        param = jit_value_create_long_constant(jitFunction->function, jit_type_long, (JITINT64) item->value);
 
1056
                        break;
 
1057
                case IRNINT:
 
1058
                        PDEBUG("NINT %lld", item->value);
 
1059
                        param = jit_value_create_nint_constant(jitFunction->function, jit_type_nint, (JITINT32) item->value);
 
1060
                        break;
 
1061
                case IRUINT8:
 
1062
                        PDEBUG("UINT8 %lld", item->value);
 
1063
                        param = jit_value_create_nint_constant(jitFunction->function, jit_type_ubyte, (JITINT32) item->value);
 
1064
                        break;
 
1065
                case IRUINT16:
 
1066
                        PDEBUG("UINT16 %lld", item->value);
 
1067
                        param = jit_value_create_nint_constant(jitFunction->function, jit_type_ushort, (JITINT32) item->value);
 
1068
                        break;
 
1069
                case IRUINT32:
 
1070
                        PDEBUG("UINT32 %lld", item->value);
 
1071
                        param = jit_value_create_nint_constant(jitFunction->function, jit_type_uint, (JITUINT32) item->value);
 
1072
                        break;
 
1073
                case IRUINT64:
 
1074
                        PDEBUG("UINT64 %lld", item->value);
 
1075
                        param = jit_value_create_long_constant (jitFunction->function, jit_type_ulong , (JITUINT64) item->value);
 
1076
                        break;
 
1077
                case IRNUINT:
 
1078
                        PDEBUG("NUINT %lld", item->value);
 
1079
                        param = jit_value_create_nint_constant (jitFunction->function, jit_type_nint , (JITINT32) item->value);
 
1080
                        break;
 
1081
                case IRFLOAT32:
 
1082
                        PDEBUG("FLOAT32 %f", item->fvalue);
 
1083
                        param = jit_value_create_float32_constant(jitFunction->function, jit_type_float32 , (JITFLOAT32) item->fvalue);
 
1084
                        break;
 
1085
                case IRFLOAT64:
 
1086
                        PDEBUG("FLOAT64 %f", item->fvalue);
 
1087
                        param = jit_value_create_float64_constant(jitFunction->function, jit_type_float64 , (JITFLOAT64) item->fvalue);
 
1088
                        break;
 
1089
                case IRNFLOAT:
 
1090
                        if (sizeof(JITNUINT) == 4){
 
1091
                                PDEBUG("FLOAT32 %f", item->fvalue);
 
1092
                                param = jit_value_create_float32_constant(jitFunction->function, jit_type_float32 , (JITFLOAT32) item->fvalue);
 
1093
                        } else {
 
1094
                                PDEBUG("FLOAT64 %f", item->fvalue);
 
1095
                                param = jit_value_create_float64_constant(jitFunction->function, jit_type_float64 , (JITFLOAT64) item->fvalue);
 
1096
                        }
 
1097
                        break;
 
1098
                case IRUPOINTER:
 
1099
                        PDEBUG("UPOINTER %p", (void *) (JITNUINT) item->value);
 
1100
                        param = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr , (JITNUINT) item->value);
 
1101
                        break;
 
1102
                case IRMPOINTER:
 
1103
                        PDEBUG("MPOINTER %p", (void *) (JITNUINT) item->value);
 
1104
                        param = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr , (JITNUINT) item->value);
 
1105
                        break;
 
1106
                case IRTPOINTER:
 
1107
                        PDEBUG("TPOINTER %p", (void *) (JITNUINT) item->value);
 
1108
                        param = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr , (JITNUINT) item->value);
 
1109
                        break;
 
1110
                case IROBJECT:
 
1111
                        PDEBUG("OBJECT %p", (void *) (JITNUINT) item->value);
 
1112
                        param = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr , (JITNUINT) item->value);
 
1113
                        break;
 
1114
                case IRCLASSID:
 
1115
                        PDEBUG("CLASSID %p", (void *) (JITNUINT) item->value);
 
1116
                        param = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr , (JITNUINT) item->value);
 
1117
                        break;
 
1118
                case IRMETHODID:
 
1119
                        PDEBUG("METHODID %p", (void *) (JITNUINT) item->value);
 
1120
                        param = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr , (JITNUINT) item->value);
 
1121
                        break;
 
1122
                case IRTYPEDREF:
 
1123
                        PDEBUG("TYPEDREFERENCE %p", (void *) (JITNUINT) item->value);
 
1124
                        
 
1125
                        /* retrieve the IL type associated with the valuetype */
 
1126
                        _this->fillILTypedReference(&iltype);
 
1127
                        assert(iltype.ID != NULL);
 
1128
                        assert(iltype.binary != NULL);
 
1129
                        
 
1130
                        /* retrieve the JIT type associated with the valuetype */
 
1131
                        JITvalueType    = _this->lookupValueType(&iltype);
 
1132
                        assert(JITvalueType != NULL);
 
1133
                        
 
1134
                        /* create the JIT variable for the current valuetype */
 
1135
                        param = jit_value_create(jitFunction->function, JITvalueType);
 
1136
                        
 
1137
                        ilt = &iltype;
 
1138
                        break;
 
1139
                default:
 
1140
                        snprintf(buf, sizeof(char) * 1024, "IRVIRTUALMACHINE: make_variable: ERROR= Type %d not known. ", item->type);
 
1141
                        print_err(buf, 0);
 
1142
                        abort();
 
1143
        }
 
1144
        assert(param != NULL);
 
1145
 
 
1146
        /* Make the variable            */
 
1147
        var     = jit_value_create(jitFunction->function, internal_fromIRTypeToJITType(_this, item->internal_type, ilt));
 
1148
        assert(var != NULL);
 
1149
        jit_insn_store(jitFunction->function, var, param);
 
1150
 
 
1151
        PDEBUG("; ");
 
1152
        return var;
 
1153
}
 
1154
 
 
1155
JITINT32 check_labels(XanList *labels){
 
1156
        XanListItem     *item;
 
1157
        t_jit_label     *label;
 
1158
 
 
1159
        PDEBUG("IRVIRTUALMACHINE:               Check the %d labels\n", labels->length(labels));
 
1160
        item = labels->first(labels);
 
1161
        if (labels == NULL) {
 
1162
                PDEBUG("IRVIRTUALMACHINE:                       There isn't label\n");
 
1163
                return 0;
 
1164
        }
 
1165
 
 
1166
        /* Check if the label is in the list    */
 
1167
        while (item != NULL){
 
1168
                label = (t_jit_label *) item->data;
 
1169
                assert(label != NULL);
 
1170
                if (label->label == jit_label_undefined){
 
1171
                        PDEBUG("IRVIRTUALMACHINE:                       Label %d is undefined\n", label->ID);
 
1172
                } else {
 
1173
                        PDEBUG("IRVIRTUALMACHINE:                       Label %d is OK\n", label->ID);
 
1174
                }
 
1175
                item = labels->next(labels, item);
 
1176
        }
 
1177
 
 
1178
        PDEBUG("IRVIRTUALMACHINE:                       Labels OK\n");
 
1179
        return 0;
 
1180
}
 
1181
 
 
1182
static inline t_jit_label * insert_label (XanList *labels, JITUINT32 label_ID){
 
1183
        XanListItem     *item;
 
1184
        t_jit_label     *label;
 
1185
 
 
1186
        /* Init the variables                   */
 
1187
        PDEBUG("IRVIRTUALMACHINE: INSERT_LABEL: %d Labels present\n", labels->length(labels));
 
1188
        item    = NULL;
 
1189
        label   = NULL;
 
1190
        
 
1191
        /* Check if the label is in the list    */
 
1192
        item    = labels->first(labels);
 
1193
        while (item != NULL){
 
1194
                label   = (t_jit_label *) item->data;
 
1195
                assert(label != NULL);
 
1196
                if (label->ID == label_ID){
 
1197
                        PDEBUG("IRVIRTUALMACHINE: INSERT_LABEL:                 Found the target label\n");
 
1198
                        return label;
 
1199
                }
 
1200
                item = labels->next(labels, item);
 
1201
        }
 
1202
 
 
1203
        /* The label is not in the list         */
 
1204
        PDEBUG("IRVIRTUALMACHINE: INSERT_LABEL:         The target label is not found\n");
 
1205
        PDEBUG("IRVIRTUALMACHINE: INSERT_LABEL:         Insert the new label\n");
 
1206
        label           = (t_jit_label *) allocFunction(sizeof(t_jit_label));
 
1207
        label->ID       = label_ID;
 
1208
        label->label    = jit_label_undefined;
 
1209
        labels->append(labels, label);
 
1210
 
 
1211
        return label;
 
1212
}
 
1213
 
 
1214
static inline JITINT16 translate_ir_neg (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
1215
        jit_value_t             param;
 
1216
 
 
1217
        /* Assertions                   */
 
1218
        assert(method != NULL);
 
1219
        assert(inst != NULL);
 
1220
        assert(jitFunction != NULL);
 
1221
        assert((inst->result).type == IROFFSET);
 
1222
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = neg(", (inst->result).value);
 
1223
 
 
1224
        /* Create the first parameter   */
 
1225
        param = make_variable (_this, method, &(inst->param_1), jitFunction);
 
1226
        assert(param != NULL);
 
1227
        PDEBUG(")\n");
 
1228
 
 
1229
        /* Create the neg instruction           */
 
1230
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1231
                jit_value_t     temp;
 
1232
                temp    = jit_insn_neg(jitFunction->function, param);
 
1233
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1234
        } else {
 
1235
                jitFunction->locals[(inst->result).value] = jit_insn_neg(jitFunction->function, param);
 
1236
        }
 
1237
 
 
1238
        /* Return                               */
 
1239
        return 0;
 
1240
}
 
1241
 
 
1242
static inline JITINT16 translate_ir_store_elem (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
1243
        jit_value_t     field_number;
 
1244
        jit_value_t     value;
 
1245
        jit_value_t     array;
 
1246
        jit_type_t      type;
 
1247
        #ifdef PRINTDEBUG
 
1248
        jit_value_t     args[2];
 
1249
        #endif
 
1250
 
 
1251
        /* Assertions                                   */
 
1252
        assert(_this != NULL);
 
1253
        assert(method != NULL);
 
1254
        assert(jitFunction != NULL);
 
1255
        assert(inst != NULL);
 
1256
        assert((inst->param_1).type == IROFFSET);
 
1257
        assert((inst->param_4).type == IRTYPE);
 
1258
        assert((inst->result).type == NOPARAM);
 
1259
 
 
1260
        /* Init the variables                           */
 
1261
        value           = NULL;
 
1262
        type            = NULL;
 
1263
        field_number    = NULL;
 
1264
 
 
1265
        /* Print the array              */
 
1266
        #ifdef PRINTDEBUG
 
1267
        PDEBUG("IRVIRTUALMACHINE: store_elem:   Call the printArray\n");
 
1268
        args[0] = jitFunction->locals[(inst->param_1).value];
 
1269
        args[1] = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr, (JITNUINT) "Before store_elem");
 
1270
        jit_insn_call_native(   jitFunction->function, "printArray" , _this->gc->printArray , _this->gc->signPrintArray , args, 2, JIT_CALL_NOTHROW);
 
1271
        #endif
 
1272
 
 
1273
        /* Print the instruction                        */
 
1274
        PDEBUG("IRVIRTUALMACHINE:               store_elem(Array in variable %lld, Element number in ", (inst->param_1).value);
 
1275
 
 
1276
        /* Fetch the array                              */
 
1277
        array           = make_variable(_this, method, &(inst->param_1), jitFunction);
 
1278
 
 
1279
        /* Create the field number                      */
 
1280
        field_number = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1281
        assert(field_number != NULL);
 
1282
        PDEBUG(", Value in ");
 
1283
 
 
1284
        /* Create the value to store                    */
 
1285
        value           = make_variable(_this, method, &(inst->param_3), jitFunction);
 
1286
        assert(value != NULL);
 
1287
        PDEBUG(", Type array element ");
 
1288
 
 
1289
        /* Fetch the type of the value to store         */
 
1290
        type    = jit_value_get_type(value);
 
1291
        assert(type != NULL);
 
1292
 
 
1293
        /* Check that the value has the same type of    *
 
1294
         * the elements of the array                    */
 
1295
        switch ((inst->param_4).value){
 
1296
                case IRUINT8:
 
1297
                        PDEBUG("Value = UINT8 %lld)\n", (inst->param_2).value);
 
1298
                        if (type != jit_type_ubyte){
 
1299
                                value = jit_insn_convert(jitFunction->function, value, jit_type_ubyte, 0);
 
1300
                        }
 
1301
                        break;
 
1302
                case IRUINT16:
 
1303
                        PDEBUG("Value = UINT16 %lld)\n", (inst->param_2).value);
 
1304
                        if (type != jit_type_ushort){
 
1305
                                value = jit_insn_convert(jitFunction->function, value, jit_type_ushort, 0);
 
1306
                        }
 
1307
                        break;
 
1308
                case IRUINT32:
 
1309
                        PDEBUG("Value = UINT32 %lld)\n", (inst->param_2).value);
 
1310
                        if (type != jit_type_uint){
 
1311
                                value = jit_insn_convert(jitFunction->function, value, jit_type_uint, 0);
 
1312
                        }
 
1313
                        break;
 
1314
                case IRUINT64:
 
1315
                        PDEBUG("Value = UINT64 %lld)\n", (inst->param_2).value);
 
1316
                        if (type != jit_type_ulong){
 
1317
                                value = jit_insn_convert(jitFunction->function, value, jit_type_ulong, 0);
 
1318
                        }
 
1319
                        break;
 
1320
                case IRINT8:
 
1321
                        PDEBUG("Value = INT8 %lld)\n", (inst->param_2).value);
 
1322
                        if (type != jit_type_sbyte){
 
1323
                                value = jit_insn_convert(jitFunction->function, value, jit_type_sbyte, 0);
 
1324
                        }
 
1325
                        break;
 
1326
                case IRINT16:
 
1327
                        PDEBUG("Value = INT16 %lld)\n", (inst->param_2).value);
 
1328
                        if (type != jit_type_short){
 
1329
                                value = jit_insn_convert(jitFunction->function, value, jit_type_short, 0);
 
1330
                        }
 
1331
                        break;
 
1332
                case IRINT32:
 
1333
                        PDEBUG("Value = INT32 %lld)\n", (inst->param_2).value);
 
1334
                        if (type != jit_type_int){
 
1335
                                value = jit_insn_convert(jitFunction->function, value, jit_type_int, 0);
 
1336
                        }
 
1337
                        break;
 
1338
                case IRINT64:
 
1339
                        PDEBUG("Value = INT64 %lld)\n", (inst->param_2).value);
 
1340
                        if (type != jit_type_long){
 
1341
                                value = jit_insn_convert(jitFunction->function, value, jit_type_long, 0);
 
1342
                        }
 
1343
                        break;
 
1344
                case IRNINT:
 
1345
                        PDEBUG("Value = IRNINT %lld)\n", (inst->param_2).value);
 
1346
                        if (type != jit_type_int) {
 
1347
                                value = jit_insn_convert(jitFunction->function, value, jit_type_int, 0);
 
1348
                        }
 
1349
                        break;
 
1350
                case IRFLOAT32:
 
1351
                        PDEBUG("Value = FLOAT32 %f)\n", (JITFLOAT32) (inst->param_2).fvalue);
 
1352
                        if (type != jit_type_float32){
 
1353
                                value = jit_insn_convert(jitFunction->function,
 
1354
                                                value, jit_type_float32, 0);
 
1355
                        }
 
1356
                        break;
 
1357
                case IRFLOAT64:
 
1358
                        PDEBUG("Value = FLOAT64 %f)\n", (JITFLOAT64) (inst->param_2).fvalue);
 
1359
                        if (type != jit_type_float64){
 
1360
                                value = jit_insn_convert(jitFunction->function, value, jit_type_float64, 0);
 
1361
                        }
 
1362
                        break;
 
1363
                case IRNFLOAT:
 
1364
                        if (sizeof(JITNUINT) == 4){
 
1365
                                PDEBUG("Value = FLOAT32 %f)\n", (JITFLOAT32) (inst->param_2).fvalue);
 
1366
                                if (type != jit_type_float32){
 
1367
                                        value = jit_insn_convert(jitFunction->function, value, jit_type_float32, 0);
 
1368
                                }
 
1369
                        } else {
 
1370
                                PDEBUG("Value = FLOAT64 %f)\n", (JITFLOAT64) (inst->param_2).fvalue);
 
1371
                                if (type != jit_type_float64){
 
1372
                                        value = jit_insn_convert(jitFunction->function, value, jit_type_float64, 0);
 
1373
                                }
 
1374
                        }
 
1375
                        break;
 
1376
                case IRUPOINTER:
 
1377
                        PDEBUG("Value = UPOINTER 0x%p)\n", (void *) (JITNUINT) (inst->param_2).value);
 
1378
                        if (type != jit_type_void_ptr)
 
1379
                        {
 
1380
                                value = jit_insn_convert(jitFunction->function,
 
1381
                                                value, jit_type_void_ptr, 0);
 
1382
                        }
 
1383
                        break;
 
1384
                case IRMPOINTER:
 
1385
                        PDEBUG("Value = MPOINTER 0x%p)\n", (void *) (JITNUINT) (inst->param_2).value);
 
1386
                        if (type != jit_type_void_ptr)
 
1387
                        {
 
1388
                                value = jit_insn_convert(jitFunction->function,
 
1389
                                                value, jit_type_void_ptr, 0);
 
1390
                        }
 
1391
                        break;
 
1392
                case IRTPOINTER:
 
1393
                        PDEBUG("Value = TPOINTER 0x%p)\n", (void *) (JITNUINT) (inst->param_2).value);
 
1394
                        if (type != jit_type_void_ptr)
 
1395
                        {
 
1396
                                value = jit_insn_convert(jitFunction->function,
 
1397
                                                value, jit_type_void_ptr, 0);
 
1398
                        }
 
1399
                        break;
 
1400
                case IROBJECT:
 
1401
                        PDEBUG("Value = OBJECT 0x%p)\n", (void *) (JITNUINT) (inst->param_2).value);
 
1402
                        if (type != jit_type_void_ptr)
 
1403
                        {
 
1404
                                value = jit_insn_convert(jitFunction->function,
 
1405
                                                value, jit_type_void_ptr, 0);
 
1406
                        }
 
1407
                        break;
 
1408
                case IRVALUETYPE:
 
1409
                        PDEBUG("Value = VALUETYPE 0x%p)\n", (void *) (JITNUINT) (inst->param_2).value);
 
1410
                        /* Nothing to be done here */
 
1411
                        break;
 
1412
                default:
 
1413
                        print_err("IRVIRTUALMACHINE: translate_ir_store_elem: ERROR = Type of the parameter 2 is not known. ", 0);
 
1414
                        abort();
 
1415
        }
 
1416
        assert(value != NULL);
 
1417
        assert(field_number != NULL);
 
1418
 
 
1419
        /* Create the Store_elem instruction    */
 
1420
        if (jit_insn_store_elem(jitFunction->function , array , field_number, value) == 0) {
 
1421
                print_err("IRVIRTUALMACHINE: store_elem: ERROR = The jit_insn_store_elem return an error. ", 0);
 
1422
                abort();
 
1423
        }
 
1424
 
 
1425
        /* Print the array              */
 
1426
        #ifdef PRINTDEBUG
 
1427
        PDEBUG("IRVIRTUALMACHINE: store_elem:   Call the printArray\n");
 
1428
        args[0] = jitFunction->locals[(inst->param_1).value];
 
1429
        args[1] = jit_value_create_nint_constant(jitFunction->function, jit_type_void_ptr, (JITNUINT) "After store_elem");
 
1430
        jit_insn_call_native(jitFunction->function, "printArray" , _this->gc->printArray , _this->gc->signPrintArray, args, 2, JIT_CALL_NOTHROW);
 
1431
        #endif
 
1432
 
 
1433
        /* Return                       */
 
1434
        return 0;
 
1435
}
 
1436
 
 
1437
static inline JITINT16 translate_ir_load_elem (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
1438
        JITUINT32       typeSlot;
 
1439
        char            buffer[1024];
 
1440
        jit_value_t     field_number;
 
1441
        jit_value_t     array;
 
1442
        jit_type_t      arraySlotType;
 
1443
 
 
1444
        /* Assertions                                   */
 
1445
        assert(_this != NULL);
 
1446
        assert(method != NULL);
 
1447
        assert(jitFunction != NULL);
 
1448
        assert(inst != NULL);
 
1449
        assert((inst->result).type == IROFFSET);
 
1450
        assert((inst->param_1).type == IROFFSET);
 
1451
        assert((inst->param_3).type == IRTYPE);
 
1452
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = load_elem(Array = Variable %lld, Field = ", (inst->result).value, (inst->param_1).value);
 
1453
 
 
1454
        /* Initialize the variables                     */
 
1455
        arraySlotType   = NULL;
 
1456
        field_number    = NULL;
 
1457
        array           = NULL;
 
1458
        typeSlot        = 0;
 
1459
 
 
1460
        /* Fetch the array                              */
 
1461
        array           = make_variable(_this, method, &(inst->param_1), jitFunction);
 
1462
 
 
1463
        /* Create the field number                      */
 
1464
        field_number    = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1465
        PDEBUG(", IRTYPE = ");
 
1466
 
 
1467
        /* Compute the type of the single slot          */
 
1468
        typeSlot        = (inst->param_3).value;
 
1469
 
 
1470
        /* Make the JIT type                            */
 
1471
        switch(typeSlot){
 
1472
                case IRINT8:
 
1473
                        PDEBUG("IRINT8\n");
 
1474
                        arraySlotType   = jit_type_sbyte;
 
1475
                        break;
 
1476
                case IRINT16:
 
1477
                        arraySlotType   = jit_type_short;
 
1478
                        PDEBUG("IRINT16\n");
 
1479
                        break;
 
1480
                case IRINT32:
 
1481
                        PDEBUG("IRINT32\n");
 
1482
                        arraySlotType   = jit_type_int;
 
1483
                        break;
 
1484
                case IRINT64:
 
1485
                        PDEBUG("IRINT64\n");
 
1486
                        arraySlotType   = jit_type_long;
 
1487
                        break;
 
1488
                case IRUINT8:
 
1489
                        PDEBUG("IRUINT8\n");
 
1490
                        arraySlotType   = jit_type_ubyte;
 
1491
                        break;
 
1492
                case IRUINT16:
 
1493
                        PDEBUG("IRUINT16\n");
 
1494
                        arraySlotType   = jit_type_ushort;
 
1495
                        break;
 
1496
                case IRUINT32:
 
1497
                        PDEBUG("IRUINT32\n");
 
1498
                        arraySlotType   = jit_type_uint;
 
1499
                        break;
 
1500
                case IRUINT64:
 
1501
                        PDEBUG("IRUINT64\n");
 
1502
                        arraySlotType   = jit_type_ulong;
 
1503
                        break;
 
1504
                case IRFLOAT32:
 
1505
                        PDEBUG("IRFLOAT32\n");
 
1506
                        arraySlotType   = jit_type_float32;
 
1507
                        break;
 
1508
                case IRFLOAT64:
 
1509
                        PDEBUG("IRFLOAT64\n");
 
1510
                        arraySlotType   = jit_type_float64;
 
1511
                        break;
 
1512
                case IRNINT:
 
1513
                        PDEBUG("IRNINT\n");
 
1514
                        arraySlotType   = jit_type_nint;
 
1515
                        break;
 
1516
                case IRNUINT:
 
1517
                        PDEBUG("IRNUINT\n");
 
1518
                        arraySlotType   = jit_type_nuint;
 
1519
                        break;
 
1520
                case IRNFLOAT:
 
1521
                        if (sizeof(JITNUINT) == 4) {
 
1522
                                PDEBUG("IRFLOAT32\n");
 
1523
                                arraySlotType   = jit_type_float32;
 
1524
                        } else {
 
1525
                                PDEBUG("IRFLOAT64\n");
 
1526
                                arraySlotType   = jit_type_float64;
 
1527
                        }
 
1528
                        break;
 
1529
                case IRUPOINTER:
 
1530
                        PDEBUG("IRUPOINTER\n");
 
1531
                        arraySlotType   = jit_type_void_ptr;
 
1532
                        break;
 
1533
                case IRMPOINTER:
 
1534
                        PDEBUG("IRMPOINTER\n");
 
1535
                        arraySlotType   = jit_type_void_ptr;
 
1536
                        break;
 
1537
                case IRTPOINTER:
 
1538
                        PDEBUG("IRTPOINTER\n");
 
1539
                        arraySlotType   = jit_type_void_ptr;
 
1540
                        break;
 
1541
                case IROBJECT:
 
1542
                        PDEBUG("IROBJECT\n");
 
1543
                        arraySlotType   = jit_type_void_ptr;
 
1544
                        break;
 
1545
                default:
 
1546
                        snprintf(buffer, sizeof(buffer), "IRVIRTUALMACHINE: load_elem: ERROR = Type %d is not known. ", typeSlot);
 
1547
                        print_err(buffer, 0);
 
1548
                        abort();
 
1549
        }
 
1550
 
 
1551
        /* Make the JIT instruction     */
 
1552
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1553
                jit_value_t     temp;
 
1554
                temp    = jit_insn_load_elem (jitFunction->function , array , field_number, arraySlotType);
 
1555
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1556
        } else {
 
1557
                jitFunction->locals[(inst->result).value]       = jit_insn_load_elem (jitFunction->function , array, field_number, arraySlotType);
 
1558
        }
 
1559
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
1560
 
 
1561
        /* Print the array              */
 
1562
        #if 0
 
1563
        ifdef PRINTDEBUG
 
1564
        jit_value_t     args[2];
 
1565
        PDEBUG("IRVIRTUALMACHINE: load_elem:    Call the printArray\n");
 
1566
        args[0] = jitFunction->locals[(inst->param_1).value];
 
1567
        args[1] = jit_value_create_nint_constant(jitFunction->function , jit_type_void_ptr, (JITNUINT) "load_elem");
 
1568
        jit_insn_call_native(jitFunction->function, "printArray" , _this->gc->printArray , _this->gc->signPrintArray , args, 3, JIT_CALL_NOTHROW);
 
1569
        #endif
 
1570
 
 
1571
        /* Return                       */
 
1572
        return 0;
 
1573
}
 
1574
 
 
1575
static inline JITINT16 translate_ir_newobj (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
1576
        jit_value_t     args[3];
 
1577
        ILClassID       classID;
 
1578
 
 
1579
        /* Assertions           */
 
1580
        assert(_this != NULL);
 
1581
        assert(inst != NULL);
 
1582
        assert((inst->param_1).type == IRCLASSID);
 
1583
        assert((inst->param_2).type == IRUINT32);
 
1584
        assert((inst->param_2).internal_type == IRUINT32);
 
1585
 
 
1586
        /* Fetch the class      */
 
1587
        classID = (ILClassID) (JITNUINT)(inst->param_1).value;
 
1588
        assert(classID != NULL);
 
1589
 
 
1590
        #ifdef PRINTDEBUG
 
1591
        char *type_name;
 
1592
        char *type_name_space;
 
1593
        type_name = get_string(&((inst->binary->metadata).streams_metadata.string_stream)
 
1594
                        , ((t_row_type_def_table *) classID)->type_name);
 
1595
        type_name_space = get_string(&((inst->binary->metadata).streams_metadata.string_stream)
 
1596
                        , ((t_row_type_def_table *) classID)->type_name_space);
 
1597
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = newobj(%s.%s)\n"
 
1598
                        , (inst->result).value, type_name_space, type_name);
 
1599
        PDEBUG("IRVIRTUALMACHINE:                       Call the allocObject function of the garbage Collector\n");
 
1600
        #endif
 
1601
 
 
1602
        /* Create the arguments                         */
 
1603
        args[0] = jit_value_create_nint_constant(jitFunction->function, jit_type_void_ptr, (JITNUINT) inst->binary);
 
1604
        args[1] = jit_value_create_nint_constant(jitFunction->function, jit_type_void_ptr, (JITNUINT) classID);
 
1605
        args[2] = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1606
 
 
1607
        /* Call the Allocator                           */
 
1608
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1609
                jit_value_t     temp;
 
1610
                temp    = jit_insn_call_native(jitFunction->function , "allocObject", _this->gc->allocObject , _this->gc->signAllocObject, args, 3, JIT_CALL_NOTHROW);
 
1611
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1612
        } else {
 
1613
                jitFunction->locals[(inst->result).value] = jit_insn_call_native(jitFunction->function , "allocObject", _this->gc->allocObject , _this->gc->signAllocObject, args, 3, JIT_CALL_NOTHROW);
 
1614
        }
 
1615
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
1616
 
 
1617
        /* Return                                       */
 
1618
        return 0;
 
1619
}
 
1620
 
 
1621
static inline JITINT16 translate_ir_label (ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction) {
 
1622
        t_jit_label             *label;
 
1623
 
 
1624
        /* Assertions           */
 
1625
        assert(method != NULL);
 
1626
        assert(inst != NULL);
 
1627
 
 
1628
        PDEBUG("IRVIRTUALMACHINE:               Label \"L%lld\"\n", (inst->param_1).value);
 
1629
        assert((inst->param_1).type == IRLABELITEM);
 
1630
        PDEBUG("IRVIRTUALMACHINE:                       %d Labels present\n", labels->length(labels));
 
1631
        PDEBUG("IRVIRTUALMACHINE:                       Insert a label\n");
 
1632
        label = insert_label(labels, (inst->param_1).value);
 
1633
        assert(label != NULL);
 
1634
        jit_insn_label(jitFunction->function, &(label->label));
 
1635
        PDEBUG("IRVIRTUALMACHINE:                       %d Labels present\n", labels->length(labels));
 
1636
 
 
1637
        return 0;
 
1638
}
 
1639
 
 
1640
static inline JITINT16 translate_ir_xor (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
1641
        jit_value_t             param_1;
 
1642
        jit_value_t             param_2;
 
1643
 
 
1644
        /* Assertions           */
 
1645
        assert(_this != NULL);
 
1646
        assert(method != NULL);
 
1647
        assert(inst != NULL);
 
1648
        assert((inst->result).type == IROFFSET);
 
1649
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = xor(", (inst->result).value);
 
1650
 
 
1651
        /* Create the first parameter   */
 
1652
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
1653
        PDEBUG(", ");
 
1654
        assert(param_1 != NULL);
 
1655
 
 
1656
        /* Create the second parameter  */
 
1657
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1658
        PDEBUG(")\n");
 
1659
        assert(param_2 != NULL);
 
1660
 
 
1661
        /* Create the xor instruction           */
 
1662
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1663
                jit_value_t     temp;
 
1664
                temp    = jit_insn_xor (jitFunction->function, param_1, param_2);
 
1665
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1666
        } else {
 
1667
                jitFunction->locals[(inst->result).value] = jit_insn_xor (jitFunction->function, param_1, param_2);
 
1668
        }
 
1669
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
1670
 
 
1671
        /* Return                       */
 
1672
        return 0;
 
1673
}
 
1674
 
 
1675
static inline JITINT16 translate_ir_and (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
1676
        jit_value_t             param_1;
 
1677
        jit_value_t             param_2;
 
1678
 
 
1679
        /* Assertions           */
 
1680
        assert(_this != NULL);
 
1681
        assert(method != NULL);
 
1682
        assert(inst != NULL);
 
1683
        assert((inst->result).type == IROFFSET);
 
1684
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = and(", (inst->result).value);
 
1685
 
 
1686
        /* Create the first parameter   */
 
1687
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
1688
        PDEBUG(", ");
 
1689
        assert(param_1 != NULL);
 
1690
 
 
1691
        /* Create the second parameter  */
 
1692
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1693
        PDEBUG(")\n");
 
1694
        assert(param_2 != NULL);
 
1695
 
 
1696
        /* Create the and instruction           */
 
1697
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1698
                jit_value_t     temp;
 
1699
                temp    = jit_insn_and (jitFunction->function, param_1, param_2);
 
1700
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1701
        } else {
 
1702
                jitFunction->locals[(inst->result).value] = jit_insn_and (jitFunction->function, param_1, param_2);
 
1703
        }
 
1704
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
1705
 
 
1706
        /* Return                               */
 
1707
        return 0;
 
1708
}
 
1709
 
 
1710
static inline JITINT16 translate_ir_or (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
1711
        jit_value_t             param_1;
 
1712
        jit_value_t             param_2;
 
1713
 
 
1714
        /* Assertions           */
 
1715
        assert(_this != NULL);
 
1716
        assert(method != NULL);
 
1717
        assert(inst != NULL);
 
1718
        assert((inst->result).type == IROFFSET);
 
1719
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = or(", (inst->result).value);
 
1720
 
 
1721
        /* Create the first parameter   */
 
1722
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
1723
        PDEBUG(", ");
 
1724
        assert(param_1 != NULL);
 
1725
 
 
1726
        /* Create the second parameter  */
 
1727
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1728
        PDEBUG(")\n");
 
1729
        assert(param_2 != NULL);
 
1730
 
 
1731
        /* Create the aor instruction           */
 
1732
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1733
                jit_value_t     temp;
 
1734
                temp    = jit_insn_or (jitFunction->function, param_1, param_2);
 
1735
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1736
        } else {
 
1737
                jitFunction->locals[(inst->result).value] = jit_insn_or (jitFunction->function, param_1, param_2);
 
1738
        }
 
1739
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
1740
 
 
1741
        /* Return                               */
 
1742
        return 0;
 
1743
}
 
1744
 
 
1745
static inline JITINT16 translate_ir_mul (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
1746
        jit_value_t             param_1;
 
1747
        jit_value_t             param_2;
 
1748
 
 
1749
        /* Assertions           */
 
1750
        assert(_this != NULL);
 
1751
        assert(method != NULL);
 
1752
        assert(inst != NULL);
 
1753
        assert((inst->result).type == IROFFSET);
 
1754
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = mul(", (inst->result).value);
 
1755
 
 
1756
        /* Create the first parameter   */
 
1757
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
1758
        PDEBUG(", ");
 
1759
        assert(param_1 != NULL);
 
1760
 
 
1761
        /* Create the second parameter  */
 
1762
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1763
        PDEBUG(")\n");
 
1764
        assert(param_2 != NULL);
 
1765
 
 
1766
        /* Create the lt instruction            */
 
1767
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1768
                jit_value_t     temp;
 
1769
                temp    = jit_insn_mul (jitFunction->function, param_1, param_2);
 
1770
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1771
        } else {
 
1772
                jitFunction->locals[(inst->result).value] = jit_insn_mul (jitFunction->function, param_1, param_2);
 
1773
        }
 
1774
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
1775
 
 
1776
        /* Return                               */
 
1777
        return 0;
 
1778
}
 
1779
 
 
1780
static inline JITINT16 translate_ir_div (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
1781
        jit_value_t             param_1;
 
1782
        jit_value_t             param_2;
 
1783
 
 
1784
        /* Assertions           */
 
1785
        assert(method != NULL);
 
1786
        assert(inst != NULL);
 
1787
        assert((inst->result).type == IROFFSET);
 
1788
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = div(", (inst->result).value);
 
1789
 
 
1790
        /* Create the first parameter   */
 
1791
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
1792
        PDEBUG(", ");
 
1793
        assert(param_1 != NULL);
 
1794
 
 
1795
        /* Create the second parameter  */
 
1796
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1797
        PDEBUG(")\n");
 
1798
        assert(param_2 != NULL);
 
1799
 
 
1800
        /* Create the div instruction           */
 
1801
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1802
                jit_value_t     temp;
 
1803
                temp    = jit_insn_div (jitFunction->function, param_1, param_2);
 
1804
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1805
        } else {
 
1806
                jitFunction->locals[(inst->result).value] = jit_insn_div (jitFunction->function, param_1, param_2);
 
1807
        }
 
1808
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
1809
 
 
1810
        /* Return                               */
 
1811
        return 0;
 
1812
}
 
1813
 
 
1814
static inline JITINT16 translate_ir_sub (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
1815
        jit_value_t             param_1;
 
1816
        jit_value_t             param_2;
 
1817
 
 
1818
        /* Assertions           */
 
1819
        assert(_this != NULL);
 
1820
        assert(method != NULL);
 
1821
        assert(inst != NULL);
 
1822
        assert((inst->result).type == IROFFSET);
 
1823
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = sub(", (inst->result).value);
 
1824
 
 
1825
        /* Create the first parameter   */
 
1826
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
1827
        PDEBUG(", ");
 
1828
        assert(param_1 != NULL);
 
1829
 
 
1830
        /* Create the second parameter  */
 
1831
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1832
        PDEBUG(")\n");
 
1833
        assert(param_2 != NULL);
 
1834
 
 
1835
        /* Create the sub instruction           */
 
1836
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1837
                jit_value_t     temp;
 
1838
                temp    = jit_insn_sub(jitFunction->function, param_1, param_2);
 
1839
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1840
        } else {
 
1841
                jitFunction->locals[(inst->result).value] = jit_insn_sub(jitFunction->function, param_1, param_2);
 
1842
        }
 
1843
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
1844
 
 
1845
        /* Return                               */
 
1846
        return 0;
 
1847
}
 
1848
 
 
1849
static inline JITINT16 translate_ir_add (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
1850
        jit_value_t             param_1;
 
1851
        jit_value_t             param_2;
 
1852
 
 
1853
        /* Assertions           */
 
1854
        assert(_this != NULL);
 
1855
        assert(method != NULL);
 
1856
        assert(inst != NULL);
 
1857
        assert((inst->result).type == IROFFSET);
 
1858
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = add(", (inst->result).value);
 
1859
 
 
1860
        /* Create the first parameter   */
 
1861
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
1862
        PDEBUG(", ");
 
1863
        assert(param_1 != NULL);
 
1864
 
 
1865
        /* Create the second parameter  */
 
1866
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
1867
        PDEBUG(")\n");
 
1868
        assert(param_2 != NULL);
 
1869
 
 
1870
        /* Create the add instruction           */
 
1871
        if (jitFunction->locals[(inst->result).value] != NULL){
 
1872
                jit_value_t     temp;
 
1873
                temp    = jit_insn_add(jitFunction->function, param_1, param_2);
 
1874
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
1875
        } else {
 
1876
                jitFunction->locals[(inst->result).value] = jit_insn_add(jitFunction->function, param_1, param_2);
 
1877
        }
 
1878
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
1879
 
 
1880
        /* Return                               */
 
1881
        return 0;
 
1882
}
 
1883
 
 
1884
static inline JITINT16 translate_ir_branch(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction){
 
1885
        t_jit_label     *label;
 
1886
 
 
1887
        /* Assertions           */
 
1888
        assert(method != NULL);
 
1889
        assert(inst != NULL);
 
1890
        assert(labels != NULL);
 
1891
 
 
1892
        PDEBUG("IRVIRTUALMACHINE:               branch(Label \"L%lld\")\n", (inst->param_1).value);
 
1893
        assert((inst->param_1).type == IRLABELITEM);
 
1894
        label   = insert_label(labels, (inst->param_1).value);
 
1895
        assert(label != NULL);
 
1896
        jit_insn_branch(jitFunction->function, &(label->label));
 
1897
 
 
1898
        return 0;
 
1899
}
 
1900
 
 
1901
static inline JITINT16 translate_ir_branch_if_pc_not_in_range(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction){
 
1902
        t_jit_label     *label_from;
 
1903
        t_jit_label     *label_to;
 
1904
        t_jit_label     *label_target;
 
1905
 
 
1906
        /* Assertions           */
 
1907
        assert(method != NULL);
 
1908
        assert(inst != NULL);
 
1909
        assert((inst->param_1).type == IRLABELITEM);
 
1910
        assert((inst->param_2).type == IRLABELITEM);
 
1911
        assert((inst->param_3).type == IRLABELITEM);
 
1912
        PDEBUG("IRVIRTUALMACHINE:               branch_if_pc_not_in_range(Label_from \"L%lld\" , Label_to \"L%lld\" , Label_target \"L%lld\")\n", (inst->param_1).value, (inst->param_2).value, (inst->param_3).value);
 
1913
 
 
1914
        label_from = insert_label(labels, (inst->param_1).value);
 
1915
        assert(label_from != NULL);
 
1916
        label_to = insert_label(labels, (inst->param_2).value);
 
1917
        assert(label_to != NULL);
 
1918
        label_target = insert_label(labels, (inst->param_3).value);
 
1919
        assert(label_target != NULL);
 
1920
 
 
1921
        jit_insn_branch_if_pc_not_in_range (jitFunction->function, (label_from->label), (label_to->label), &(label_target->label));
 
1922
 
 
1923
        return 0;
 
1924
}
 
1925
 
 
1926
static inline JITINT16 translate_ir_start_filter (ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction) {
 
1927
        t_jit_label     *label;
 
1928
 
 
1929
        /* Assertions           */
 
1930
        assert(method != NULL);
 
1931
        assert(inst != NULL);
 
1932
        assert((inst->result).type == IROFFSET);
 
1933
        assert((inst->param_1).type == IRLABELITEM);
 
1934
        assert((inst->param_2).type == NOPARAM);
 
1935
        assert((inst->param_3).type == NOPARAM);
 
1936
        assert((inst->param_4).type == NOPARAM);
 
1937
 
 
1938
        PDEBUG("IRVIRTUALMACHINE:               start_filter (Label \"L%lld\")\n", (inst->param_1).value);
 
1939
        label = insert_label(labels, (inst->param_1).value);
 
1940
        assert(label != NULL);
 
1941
        jitFunction->locals[(inst->result).value] = jit_insn_start_filter(jitFunction->function, &(label->label), jit_type_void_ptr);
 
1942
 
 
1943
        return 0;
 
1944
}
 
1945
 
 
1946
static inline JITINT16 translate_ir_start_finally(ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction) {
 
1947
        t_jit_label     *label;
 
1948
 
 
1949
        /* Assertions           */
 
1950
        assert(method != NULL);
 
1951
        assert(inst != NULL);
 
1952
        assert((inst->param_1).type == IRLABELITEM);
 
1953
        assert((inst->param_2).type == NOPARAM);
 
1954
        assert((inst->param_3).type == NOPARAM);
 
1955
        assert((inst->param_4).type == NOPARAM);
 
1956
        assert((inst->result).type == NOPARAM);
 
1957
 
 
1958
        PDEBUG("IRVIRTUALMACHINE:               start_finally (Label \"L%lld\")\n", (inst->param_1).value);
 
1959
        label = insert_label(labels, (inst->param_1).value);
 
1960
        assert(label != NULL);
 
1961
        jit_insn_start_finally(jitFunction->function, &(label->label));
 
1962
 
 
1963
        return 0;
 
1964
}
 
1965
 
 
1966
static inline JITINT16 translate_ir_end_finally(ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
1967
        /* Assertions           */
 
1968
        assert(method != NULL);
 
1969
        assert(inst != NULL);
 
1970
        assert(((inst->param_1).type == NOPARAM) || ((inst->param_1).type == IRLABELITEM));
 
1971
        assert((inst->param_2).type == IRLABELITEM);
 
1972
        assert((inst->param_3).type == NOPARAM);
 
1973
        assert((inst->param_4).type == NOPARAM);
 
1974
        assert((inst->result).type == NOPARAM);
 
1975
 
 
1976
        PDEBUG("IRVIRTUALMACHINE:               end_finally \n");
 
1977
        jit_insn_return_from_finally(jitFunction->function);
 
1978
 
 
1979
        return 0;
 
1980
}
 
1981
 
 
1982
static inline JITINT16 translate_ir_call_indirect_exception_ctor (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
1983
        jit_value_t     param_1;
 
1984
        jit_value_t     param_2;
 
1985
 
 
1986
        /* Assertions   */
 
1987
        assert(inst != NULL);
 
1988
        assert(method != NULL);
 
1989
        assert(jitFunction != NULL);
 
1990
        assert(jitFunction->locals != NULL);
 
1991
        assert(_this != NULL);
 
1992
        assert(_this->basicExceptionConstructorJITSignature != NULL);
 
1993
        assert((inst->param_1).type == IROFFSET);
 
1994
        assert((inst->param_2).type == IROFFSET);
 
1995
        assert((inst->param_3).type == NOPARAM);
 
1996
        assert((inst->param_4).type == NOPARAM);
 
1997
        assert((inst->result).type == NOPARAM);
 
1998
        PDEBUG("IRVIRTUALMACHINE:               call the exception constructor via indirect call \n");
 
1999
 
 
2000
        /* Fetch the parameters                                 */
 
2001
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2002
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
2003
        assert(param_1 != NULL);
 
2004
        assert(param_2 != NULL);
 
2005
 
 
2006
        /* Call the constructor on the exception-object         */
 
2007
        jit_insn_call_indirect_vtable(jitFunction->function, param_1, _this->basicExceptionConstructorJITSignature, &param_2, 1, JIT_CALL_NOTHROW);
 
2008
 
 
2009
        /* Return                                               */
 
2010
        return 0;
 
2011
}
 
2012
 
 
2013
static inline JITINT16 translate_ir_start_catcher (ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
2014
 
 
2015
        /* Assertions           */
 
2016
        assert(method != NULL);
 
2017
        assert(inst != NULL);
 
2018
        assert((inst->param_1).type == NOPARAM);
 
2019
        assert((inst->param_2).type == NOPARAM);
 
2020
        assert((inst->param_3).type == NOPARAM);
 
2021
        assert((inst->param_4).type == NOPARAM);
 
2022
        assert((inst->result).type == NOPARAM);
 
2023
 
 
2024
 
 
2025
        /* create the jit-instruction that marks the start of the catcher */
 
2026
        PDEBUG("IRVIRTUALMACHINE:               start_catcher : jit_insn_start_catcher \n");
 
2027
        jit_insn_start_catcher(jitFunction->function);
 
2028
 
 
2029
        return 0;
 
2030
}
 
2031
 
 
2032
static inline JITINT16 translate_ir_uses_catcher(IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
2033
 
 
2034
        /* Assertions           */
 
2035
        assert(method != NULL);
 
2036
        assert(inst != NULL);
 
2037
        assert((inst->param_1).type == NOPARAM);
 
2038
        assert((inst->param_2).type == NOPARAM);
 
2039
        assert((inst->param_3).type == NOPARAM);
 
2040
        assert((inst->param_4).type == NOPARAM);
 
2041
        assert((inst->result).type == NOPARAM);
 
2042
 
 
2043
        PDEBUG("IRVIRTUALMACHINE:               uses_catcher \n");
 
2044
        jit_insn_uses_catcher(jitFunction->function);
 
2045
 
 
2046
        /* Set the tracer               */
 
2047
        if ((_this->behavior).tracer){
 
2048
                PDEBUG("IRVIRTUALMACHINE:               Insert the tracer call\n");
 
2049
                insert_tracer(_this, method, jitFunction, JITFALSE);
 
2050
        }
 
2051
 
 
2052
        /* Return                       */
 
2053
        return 0;
 
2054
}
 
2055
 
 
2056
static inline JITINT16 translate_ir_rethrow_unandled(ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
2057
 
 
2058
        /* Assertions           */
 
2059
        assert(method != NULL);
 
2060
        assert(inst != NULL);
 
2061
        assert((inst->param_1).type == NOPARAM);
 
2062
        assert((inst->param_2).type == NOPARAM);
 
2063
        assert((inst->param_3).type == NOPARAM);
 
2064
        assert((inst->param_4).type == NOPARAM);
 
2065
        assert((inst->result).type == NOPARAM);
 
2066
 
 
2067
        PDEBUG("IRVIRTUALMACHINE:               rethrow_unhandled \n");
 
2068
        jit_insn_rethrow_unhandled(jitFunction->function);
 
2069
 
 
2070
        return 0;
 
2071
}
 
2072
 
 
2073
static inline JITINT16 translate_ir_end_filter (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
2074
        jit_value_t             param_1;
 
2075
 
 
2076
        /* Assertions           */
 
2077
        assert(_this != NULL);
 
2078
        assert(method != NULL);
 
2079
        assert(inst != NULL);
 
2080
        assert((inst->param_1).type != NOPARAM);
 
2081
        assert((inst->param_2).type == NOPARAM);
 
2082
        assert((inst->param_2).type == NOPARAM);
 
2083
        assert((inst->param_2).type == NOPARAM);
 
2084
        assert((inst->result).type == NOPARAM);
 
2085
        PDEBUG("IRVIRTUALMACHINE:               end_filter \n");
 
2086
 
 
2087
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2088
 
 
2089
        jit_insn_return_from_filter (jitFunction->function, param_1);
 
2090
 
 
2091
        return 0;
 
2092
}
 
2093
 
 
2094
static inline JITINT16 translate_ir_call_filter (ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction) {
 
2095
        t_jit_label     *label;
 
2096
        jit_value_t     filter_parameter;
 
2097
 
 
2098
        /* Assertions           */
 
2099
        assert(method != NULL);
 
2100
        assert(inst != NULL);
 
2101
        assert((inst->result).type == IROFFSET);
 
2102
        assert((inst->param_1).type == IRLABELITEM);
 
2103
        assert((inst->param_2).type == NOPARAM);
 
2104
        assert((inst->param_3).type == NOPARAM);
 
2105
        assert((inst->param_4).type == NOPARAM);
 
2106
        assert((inst->result).type == NOPARAM);
 
2107
 
 
2108
        PDEBUG("IRVIRTUALMACHINE:               call_filter(Label \"L%lld\")\n", (inst->param_1).value);
 
2109
        label = insert_label(labels, (inst->param_1).value);
 
2110
        assert(label != NULL);
 
2111
        filter_parameter = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr, (JITNUINT)0);
 
2112
 
 
2113
        if (jitFunction->locals[(inst->result).value] != NULL){
 
2114
                jit_value_t     temp;
 
2115
                temp    = jit_insn_call_filter(jitFunction->function, &(label->label), filter_parameter, jit_type_int);
 
2116
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
2117
        } else {
 
2118
                jitFunction->locals[(inst->result).value] = jit_insn_call_filter(jitFunction->function, &(label->label), filter_parameter, jit_type_int);
 
2119
        }
 
2120
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2121
 
 
2122
        /* Return                       */
 
2123
        return 0;
 
2124
}
 
2125
 
 
2126
static inline JITINT16 translate_ir_call_finally (ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction) {
 
2127
        t_jit_label     *label;
 
2128
 
 
2129
        /* Assertions           */
 
2130
        assert(method != NULL);
 
2131
        assert(inst != NULL);
 
2132
        assert((inst->param_1).type == IRLABELITEM);
 
2133
        assert((inst->param_2).type == NOPARAM);
 
2134
        assert((inst->param_3).type == NOPARAM);
 
2135
        assert((inst->param_4).type == NOPARAM);
 
2136
        assert((inst->result).type == NOPARAM);
 
2137
 
 
2138
        PDEBUG("IRVIRTUALMACHINE:               call_finally(Label \"L%lld\")\n", (inst->param_1).value);
 
2139
        label = insert_label(labels, (inst->param_1).value);
 
2140
        assert(label != NULL);
 
2141
        jit_insn_call_finally(jitFunction->function, &(label->label));
 
2142
 
 
2143
        return 0;
 
2144
}
 
2145
 
 
2146
static inline JITINT16 translate_ir_throw (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
2147
        jit_value_t             param_1;
 
2148
 
 
2149
        /* Assertions           */
 
2150
        assert(_this != NULL);
 
2151
        assert(method != NULL);
 
2152
        assert(inst != NULL);
 
2153
        assert((inst->param_1).type == IROFFSET);
 
2154
 
 
2155
        PDEBUG("IRVIRTUALMACHINE:               rethrow \n");
 
2156
 
 
2157
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2158
 
 
2159
        /* RETHROW IT USING THE THROW INSTRUCTION */
 
2160
        jit_insn_throw (jitFunction->function, param_1);
 
2161
 
 
2162
        /* Return                               */
 
2163
        return 0;
 
2164
}
 
2165
 
 
2166
static inline JITINT16 translate_ir_conv (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
2167
        jit_value_t     param;
 
2168
        jit_type_t      type;
 
2169
        #ifdef DEBUG
 
2170
        jit_type_t      _type;
 
2171
        #endif
 
2172
 
 
2173
        /* Assertions                   */
 
2174
        assert(_this != NULL);
 
2175
        assert(inst != NULL);
 
2176
        assert(method != NULL);
 
2177
        assert((inst->result).type == IROFFSET);
 
2178
        assert((inst->param_1).type != NOPARAM);
 
2179
        assert((inst->param_2).type == IRTYPE);
 
2180
 
 
2181
        /* Init the variables           */
 
2182
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = conv(", (inst->result).value);
 
2183
        type = NULL;
 
2184
 
 
2185
        /* Create the first parameter   */
 
2186
        param           = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2187
        assert(param != NULL);
 
2188
        PDEBUG(", ");
 
2189
 
 
2190
        /* Fetch the type of the value to store         */
 
2191
        #ifdef DEBUG
 
2192
        _type   = jit_value_get_type(param);
 
2193
        assert(_type != NULL);
 
2194
        #endif
 
2195
 
 
2196
        /* Create the type              */
 
2197
        switch ((inst->param_2).value){
 
2198
                case IRINT8:
 
2199
                        PDEBUG("INT8)\n");
 
2200
                        type = jit_type_sbyte;
 
2201
                        break;
 
2202
                case IRINT16:
 
2203
                        PDEBUG("INT16)\n");
 
2204
                        type = jit_type_short;
 
2205
                        break;
 
2206
                case IRINT32:
 
2207
                        PDEBUG("INT32)\n");
 
2208
                        type = jit_type_int;
 
2209
                        break;
 
2210
                case IRINT64:
 
2211
                        PDEBUG("INT64)\n");
 
2212
                        type = jit_type_long;
 
2213
                        break;
 
2214
                case IRNINT:
 
2215
                        PDEBUG("Native INT)\n");
 
2216
                        type = jit_type_nint;
 
2217
                        break;
 
2218
                case IRUINT8:
 
2219
                        PDEBUG("UINT8)\n");
 
2220
                        type = jit_type_ubyte;
 
2221
                        break;
 
2222
                case IRUINT16:
 
2223
                        PDEBUG("UINT16)\n");
 
2224
                        type = jit_type_ushort;
 
2225
                        break;
 
2226
                case IRUINT32:
 
2227
                        PDEBUG("UINT32)\n");
 
2228
                        type = jit_type_uint;
 
2229
                        break;
 
2230
                case IRUINT64:
 
2231
                        PDEBUG("UINT64)\n");
 
2232
                        type = jit_type_ulong;
 
2233
                        break;
 
2234
                case IRNUINT:
 
2235
                        PDEBUG("Native UINT)\n");
 
2236
                        type = jit_type_nuint;
 
2237
                        break;
 
2238
                case IRFLOAT32:
 
2239
                        PDEBUG("FLOAT32)\n");
 
2240
                        type = jit_type_float32;
 
2241
                        break;
 
2242
                case IRFLOAT64:
 
2243
                        PDEBUG("FLOAT64)\n");
 
2244
                        type = jit_type_float64;
 
2245
                        break;
 
2246
                case IRNFLOAT:
 
2247
                        if (sizeof(JITNFLOAT) == 4){
 
2248
                                PDEBUG("FLOAT32)\n");
 
2249
                                type = jit_type_float32;
 
2250
                        } else {
 
2251
                                PDEBUG("FLOAT64)\n");
 
2252
                                type = jit_type_float64;
 
2253
                        }
 
2254
                        break;
 
2255
                case IROBJECT:
 
2256
                case IRUPOINTER:
 
2257
                case IRMPOINTER:
 
2258
                case IRVALUETYPE:
 
2259
                        PDEBUG("UPOINTER)\n");
 
2260
                        type = jit_type_void_ptr;
 
2261
                        break;
 
2262
                default:
 
2263
                        print_err("IRVIRTUALMACHINE: ERROR = Conversion type is not known. ", 0);
 
2264
                        abort();
 
2265
        }
 
2266
 
 
2267
        /* Create the instruction               */
 
2268
        if (jitFunction->locals[(inst->result).value] != NULL){
 
2269
                jit_value_t     temp;
 
2270
                temp    = jit_insn_convert (jitFunction->function, param, type, (inst->param_3).value);
 
2271
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
2272
        } else {
 
2273
                jitFunction->locals[(inst->result).value] = jit_insn_convert (jitFunction->function, param, type, (inst->param_3).value);
 
2274
        }
 
2275
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2276
 
 
2277
        /* Return                               */
 
2278
        return 0;
 
2279
}
 
2280
 
 
2281
static inline JITINT16 translate_ir_ncall (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
2282
        ir_method_t             *jumpMethod;
 
2283
        t_jit_function          *jumpMethodJIT;
 
2284
        XanListItem             *item;
 
2285
        ir_item_t               *param;
 
2286
        jit_value_t             *args;
 
2287
        JITUINT32               args_number;
 
2288
        JITUINT32               count;
 
2289
 
 
2290
        /* Assertions                   */
 
2291
        assert(_this != NULL);
 
2292
        assert(method != NULL);
 
2293
        assert(inst != NULL);
 
2294
        assert(inst->binary != NULL);
 
2295
        assert(inst->binary->name != NULL);
 
2296
        assert((inst->param_1).type == IRMETHODID);
 
2297
        assert(jitFunction->function != NULL);
 
2298
 
 
2299
        /* Init the variables           */
 
2300
        jumpMethod      = NULL;
 
2301
        item            = NULL;
 
2302
        param           = NULL;
 
2303
        args            = NULL;
 
2304
 
 
2305
        /* Search the jump method       */
 
2306
        jumpMethod      = _this->getIRMethod((inst->param_1).value);
 
2307
        assert(jumpMethod != NULL);
 
2308
        jumpMethodJIT   = _this->getJITMethod((inst->param_1).value);
 
2309
        assert(jumpMethodJIT != NULL);
 
2310
        assert(jumpMethodJIT->jit_signature != NULL);
 
2311
        assert(jumpMethodJIT->nfunction != NULL);
 
2312
 
 
2313
#ifdef PRINTDEBUG
 
2314
        switch ((inst->result).type){
 
2315
                case IROFFSET:
 
2316
                        PDEBUG("IRVIRTUALMACHINE: IR_NCALL:     Variable %lld = ncall(Method = %s Binary = %s: " , (inst->result).value, jumpMethod->getName(jumpMethod) , inst->binary->name);
 
2317
                        break;
 
2318
                case IRVOID:
 
2319
                        PDEBUG("IRVIRTUALMACHINE: IR_NCALL: ncall(Method = %s Binary = %s: " , jumpMethod->getName(jumpMethod), inst->binary->name);
 
2320
                        break;
 
2321
                default:
 
2322
                        print_err("IRVIRTUALMACHINE: IR_NCALL: ERROR = Result type not known. ", 0);
 
2323
                        abort();
 
2324
        }
 
2325
#endif
 
2326
 
 
2327
        /* Create the arguments                 */
 
2328
        args_number     = jumpMethod->getParametersNumber(jumpMethod);
 
2329
 
 
2330
        /* Alloc the JIT arguments              */
 
2331
        if (args_number > 0){
 
2332
                args    = (jit_value_t *) allocFunction(sizeof(jit_value_t) * args_number);
 
2333
 
 
2334
                /* Fetch the first formal parameter     */
 
2335
                item            = inst->callParameters->first(inst->callParameters);
 
2336
                assert(item != NULL);
 
2337
        } else {
 
2338
                args    = NULL;
 
2339
                assert(inst->callParameters != NULL);
 
2340
                assert(inst->callParameters->length(inst->callParameters) == 0);
 
2341
        }
 
2342
 
 
2343
        /* Create all the formal arguments      */
 
2344
        count=0;
 
2345
        while (item != NULL){
 
2346
                param           = (ir_item_t *) inst->callParameters->data(inst->callParameters, item);
 
2347
                assert(param != NULL);
 
2348
 
 
2349
                /* Create the argument          */
 
2350
                args[count] = make_variable(_this, method, param, jitFunction);
 
2351
                PDEBUG(", ");
 
2352
                assert(args[count] != NULL);
 
2353
 
 
2354
                /* Fetch the next parameter     */
 
2355
                count++;
 
2356
                item            = inst->callParameters->next(inst->callParameters, item);
 
2357
        }
 
2358
        assert(count == args_number);
 
2359
        PDEBUG(")\n");
 
2360
 
 
2361
        /* Create the JIT call instruction      */
 
2362
        PDEBUG("IRVIRTUALMACHINE: IR_NCALL:     Insert the JIT call instruction\n");
 
2363
        switch ((inst->result).type){
 
2364
                case IROFFSET:
 
2365
                        if (jitFunction->locals[(inst->result).value] != NULL){
 
2366
                                jit_value_t     temp;
 
2367
                                temp    = jit_insn_call_native(jitFunction->function, jumpMethod->getName(jumpMethod), jumpMethodJIT->nfunction, jumpMethodJIT->jit_signature, args, args_number, 0);
 
2368
                                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
2369
                        } else {
 
2370
                                jitFunction->locals[(inst->result).value] = jit_insn_call_native(jitFunction->function, jumpMethod->getName(jumpMethod), jumpMethodJIT->nfunction, jumpMethodJIT->jit_signature, args, args_number, 0);
 
2371
                        }
 
2372
                        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2373
                        break;
 
2374
                case IRVOID:
 
2375
                        jit_insn_call_native(jitFunction->function, jumpMethod->getName(jumpMethod), jumpMethodJIT->nfunction, jumpMethodJIT->jit_signature, args, args_number, 0);
 
2376
                        break;
 
2377
                default:
 
2378
                        print_err("IRVIRTUALMACHINE: IR_NCALL: ERROR = Result type not known. ", 0);
 
2379
                        abort();
 
2380
        }
 
2381
 
 
2382
        /* Return                                               */
 
2383
        PDEBUG("IRVIRTUALMACHINE: IR_NCALL: End\n");
 
2384
        return 0;
 
2385
}
 
2386
 
 
2387
static inline JITINT16 translate_ir_icall (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
2388
        jit_type_t      signature;
 
2389
        jit_type_t      returnType;
 
2390
        jit_type_t      *jit_param_types;
 
2391
        jit_value_t     *jit_param_values;
 
2392
        JITUINT32       param_size;
 
2393
        JITUINT32       count;
 
2394
        XanListItem     *current_parameter;
 
2395
 
 
2396
        /* Assertions                   */
 
2397
#ifdef DEBUG
 
2398
        assert(method != NULL);
 
2399
        assert(_this != NULL);
 
2400
        assert(inst != NULL);
 
2401
        assert((inst->param_1).type == IRTYPE);
 
2402
        if ((inst->param_1).value == IRVOID){
 
2403
                assert((inst->result).type == NOPARAM);
 
2404
        } else {
 
2405
                assert((inst->result).type == IROFFSET);
 
2406
        }
 
2407
#endif
 
2408
#ifdef PRINTDEBUG
 
2409
        PDEBUG("IRVIRTUALMACHINE: translate_ir_icall: Start\n");
 
2410
        if ((char *) ((JITNUINT)((inst->param_2).value)) != NULL){
 
2411
                PDEBUG("IRVIRTUALMACHINE: translate_ir_icall:   Function        = %s\n" , (char *) ((JITNUINT)((inst->param_2).value)) );
 
2412
        }
 
2413
#endif
 
2414
 
 
2415
        /* initialize the local variables */
 
2416
        signature               = NULL;
 
2417
        returnType              = NULL;
 
2418
        jit_param_types         = NULL;
 
2419
        jit_param_values        = NULL;
 
2420
        current_parameter       = NULL;
 
2421
        param_size              = 0;
 
2422
        count                   = 0;
 
2423
 
 
2424
        /* retrieve the return_type */
 
2425
        PDEBUG("IRVIRTUALMACHINE: translate_ir_icall:   Make the JIT signature\n");
 
2426
        PDEBUG("IRVIRTUALMACHINE: translate_ir_icall:           Make the return type\n");
 
2427
        returnType = internal_fromIRTypeToJITType(_this, (inst->param_1).value, (inst->param_1).value_type_infos.type_infos);
 
2428
        assert(returnType != NULL);
 
2429
 
 
2430
        /* there are some parameters */
 
2431
        PDEBUG("IRVIRTUALMACHINE: translate_ir_icall:           Make the call parameters\n");
 
2432
        if (    (inst->callParameters != NULL)                                  &&
 
2433
                (inst->callParameters->length(inst->callParameters) > 0)        ){
 
2434
                param_size              = inst->callParameters->length(inst->callParameters);
 
2435
                assert(param_size != 0);
 
2436
                current_parameter       = inst->callParameters->first(inst->callParameters);
 
2437
                assert(current_parameter != NULL);
 
2438
                jit_param_types         = (jit_type_t *) allocFunction(sizeof(jit_type_t) * param_size);
 
2439
                jit_param_values        = (jit_value_t *) allocFunction(sizeof(jit_value_t) * param_size);
 
2440
        }
 
2441
 
 
2442
        /* create the type for each function parameter */
 
2443
        for (count = 0; count < param_size; count++){
 
2444
                jit_type_t      current_parameter_type;
 
2445
                jit_value_t     current_parameter_value;
 
2446
                ir_item_t       *current_stack_item;
 
2447
                PDEBUG("IRVIRTUALMACHINE: translate_ir_icall:                   Parameter %u: ", count);
 
2448
 
 
2449
                /* retrieve the t_stack_item of the current parameter */
 
2450
                assert(current_parameter != NULL);
 
2451
                current_stack_item      = (ir_item_t *) inst->callParameters->data(inst->callParameters, current_parameter);
 
2452
                assert(current_stack_item != NULL);
 
2453
 
 
2454
                /* retrieve the type & the value of the current parameter */
 
2455
                current_parameter_type          = internal_fromIRTypeToJITType(_this, current_stack_item->internal_type, (current_stack_item->value_type_infos).type_infos);
 
2456
                current_parameter_value         = make_variable(_this, method, current_stack_item, jitFunction);
 
2457
                PDEBUG("\n");
 
2458
 
 
2459
                /* Assertions                                           */
 
2460
#ifdef PRINTDEBUG
 
2461
                jit_type_t      type;
 
2462
                type = jit_value_get_type(current_parameter_value);
 
2463
                PDEBUG("IRVIRTUALMACHINE: translate_ir_icall:                           IR Type: %u\n", current_stack_item->internal_type);
 
2464
                PDEBUG("IRVIRTUALMACHINE: translate_ir_icall:                           JIT Type: %u\n", fromJITTypeToIRType(type));
 
2465
                assert(current_parameter_type != NULL);
 
2466
                assert(current_parameter_value != NULL);
 
2467
#endif
 
2468
 
 
2469
                /* Update the values            */
 
2470
                jit_param_types[count]  = current_parameter_type;
 
2471
                jit_param_values[count] = current_parameter_value;
 
2472
 
 
2473
                /* Fetch the next parameter     */
 
2474
                current_parameter       = inst->callParameters->next(inst->callParameters, current_parameter);
 
2475
        }
 
2476
 
 
2477
        /* create the signature */
 
2478
        signature = jit_type_create_signature( jit_abi_cdecl, returnType, jit_param_types, param_size, 1);
 
2479
        assert(signature != NULL);
 
2480
 
 
2481
        /*
 
2482
                Here we must discriminate if we're doing a native or an indirect invocation.
 
2483
                We check the nfunc field of the structure to determine the invocation:
 
2484
                if this field is not NULL, we've a native invocation so we must use 'jit_insn_call_native'
 
2485
                if it is NULL, the invocation is indirect, so we must reference to 'jit_insn_call_indirect'
 
2486
 
 
2487
                With respect to the implementation of IRICALL
 
2488
                1) return type
 
2489
                2) function name
 
2490
                3) not used before implementing the calli instruction, now it stores a function pointer (ir_item_t)
 
2491
 
 
2492
                In the general case, the third parameter is thus the function pointer, which it's not provided exploiting nfunc.
 
2493
 
 
2494
                The callParameters field contains the argument list for the method to invoke
 
2495
        */
 
2496
        if (returnType != jit_type_void) {
 
2497
                assert( ((JITINT8 *) ((JITNUINT)((inst->param_2).value))) != NULL );
 
2498
                if (inst->nfunc != NULL) {
 
2499
                        if (jitFunction->locals[(inst->result).value] != NULL) {
 
2500
                                jit_value_t     temp;
 
2501
                                temp    = jit_insn_call_native(jitFunction->function, (char *) ((JITNUINT)((inst->param_2).value)), inst->nfunc, signature, jit_param_values, param_size, 0);
 
2502
                                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
2503
                        } else {
 
2504
                                jitFunction->locals[(inst->result).value] = jit_insn_call_native(jitFunction->function, (char *) ((JITNUINT)((inst->param_2).value)), inst->nfunc, signature, jit_param_values, param_size, 0);
 
2505
                        }
 
2506
                        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2507
                } else {
 
2508
                        jit_value_t     function_pointer;
 
2509
                        function_pointer        = make_variable(_this, method, &(inst->param_3), jitFunction);
 
2510
                        assert(function_pointer != NULL);
 
2511
                        if (jitFunction->locals[(inst->result).value] != NULL) {
 
2512
                                jit_value_t     temp;
 
2513
                                temp = jit_insn_call_indirect(jitFunction->function, function_pointer, signature, jit_param_values, param_size, 0);
 
2514
                                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
2515
                        } else {
 
2516
                                jitFunction->locals[(inst->result).value] = jit_insn_call_indirect(jitFunction->function, function_pointer, signature, jit_param_values, param_size, 0);
 
2517
                        }
 
2518
                        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2519
                }
 
2520
        } else{
 
2521
                if (inst->nfunc != NULL) {
 
2522
                        jit_insn_call_native(jitFunction->function, (char *) ((JITNUINT)((inst->param_2).value)), inst->nfunc, signature, jit_param_values, param_size, 0);
 
2523
                } else {
 
2524
                        jit_value_t     function_pointer;
 
2525
                        function_pointer        = make_variable(_this, method, &(inst->param_3), jitFunction);
 
2526
                        assert(function_pointer != NULL);
 
2527
                        jit_insn_call_indirect(jitFunction->function, function_pointer, signature, jit_param_values, param_size, 0);
 
2528
                }
 
2529
        }
 
2530
 
 
2531
        /* Return                       */
 
2532
        return 0;
 
2533
}
 
2534
 
 
2535
static inline JITINT16 translate_ir_call (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
2536
        ir_method_t             *ir_jump_method;
 
2537
        t_jit_function          *jumpMethodJIT;
 
2538
        XanListItem             *item;
 
2539
        ir_item_t               *param;
 
2540
        jit_value_t             *args;
 
2541
        JITUINT32               args_number;
 
2542
        JITUINT32               count;
 
2543
        JITINT32                call_flags;
 
2544
        jit_type_t              jit_signature;
 
2545
 
 
2546
        /* Assertions                   */
 
2547
        assert(_this != NULL);
 
2548
        assert(method != NULL);
 
2549
        assert(inst != NULL);
 
2550
        assert(inst->binary != NULL);
 
2551
        assert(inst->binary->name != NULL);
 
2552
        assert((inst->param_1).type == IRMETHODID);
 
2553
        assert((inst->param_2).type == IRINT32);
 
2554
        assert((inst->param_3).type == NOPARAM || (inst->param_3).type == IRUPOINTER);
 
2555
        assert((inst->param_4).type == NOPARAM);
 
2556
        assert(jitFunction->function != NULL);
 
2557
 
 
2558
        /* Init the variables           */
 
2559
        args            = NULL;
 
2560
        ir_jump_method  = NULL;
 
2561
        item            = NULL;
 
2562
        param           = NULL;
 
2563
        args_number     = 0;
 
2564
        count           = 0;
 
2565
        call_flags      = 0;
 
2566
 
 
2567
        /* Search the jump method       */
 
2568
        jumpMethodJIT   = _this->getJITMethod((inst->param_1).value);
 
2569
        assert(jumpMethodJIT != NULL);
 
2570
        assert(jumpMethodJIT->jit_signature != NULL);
 
2571
 
 
2572
        /* Fetch the IR jump method     */
 
2573
        ir_jump_method = _this->getIRMethod((inst->param_1).value);
 
2574
        assert(ir_jump_method != NULL);
 
2575
        assert(ir_jump_method->getSignature(ir_jump_method) != NULL);
 
2576
        
 
2577
        jit_signature = jumpMethodJIT->jit_signature;
 
2578
 
 
2579
        /* Print the instruction        */
 
2580
#ifdef PRINTDEBUG
 
2581
        switch ((inst->result).type){
 
2582
                case IROFFSET:
 
2583
                        PDEBUG("IRVIRTUALMACHINE: IR_CALL:              Variable %lld = call(Method = %s Binary = %s)\n", (inst->result).value, ir_jump_method->getName(ir_jump_method), inst->binary->name);
 
2584
                        break;
 
2585
                case IRVOID:
 
2586
                        PDEBUG("IRVIRTUALMACHINE: IR_CALL:      call(Method = %s Binary = %s)\n", ir_jump_method->getName(ir_jump_method), inst->binary->name);
 
2587
                        break;
 
2588
                default:
 
2589
                        print_err("IRVIRTUALMACHINE: IR_CALL: ERROR = Result type not known. ", 0);
 
2590
                        abort();
 
2591
        }
 
2592
#endif
 
2593
 
 
2594
        /* Create the arguments                 */
 
2595
        PDEBUG("IRVIRTUALMACHINE: IR_CALL:                      Set the arguments\n");
 
2596
        if (    (inst->callParameters == NULL)                                  ||
 
2597
                (inst->callParameters->length(inst->callParameters) == 0)       ){
 
2598
 
 
2599
                /* The method hasn't some parameters    */
 
2600
                PDEBUG("IRVIRTUALMACHINE: IR_CALL:                              No arguments\n");
 
2601
                args            = NULL;
 
2602
                args_number     = 0;
 
2603
        } else {
 
2604
 
 
2605
                /* The method has some parameters       */
 
2606
                args_number     = inst->callParameters->length(inst->callParameters);
 
2607
                PDEBUG("IRVIRTUALMACHINE: IR_CALL:                              %d arguments\n", args_number);
 
2608
                args            = (jit_value_t *) allocFunction(sizeof(jit_value_t) * args_number);
 
2609
                item            = inst->callParameters->first(inst->callParameters);
 
2610
                assert(item != NULL);
 
2611
                count           = 0;
 
2612
 
 
2613
                /* Create the arguments                 */
 
2614
                while (item != NULL) {
 
2615
                        param           = (ir_item_t *) inst->callParameters->data(inst->callParameters, item);
 
2616
                        assert(param != NULL);
 
2617
 
 
2618
                        /* Create the argument          */
 
2619
                        PDEBUG("IRVIRTUALMACHINE: IR_CALL:                                      Argument %d : ", count);
 
2620
                        args[count] = make_variable(_this, method, param, jitFunction);
 
2621
                        PDEBUG("\n");
 
2622
                        assert(args[count] != NULL);
 
2623
 
 
2624
                        /* Fetch the next parameter     */
 
2625
                        count++;
 
2626
                        item            = inst->callParameters->next(inst->callParameters, item);
 
2627
                }
 
2628
        }
 
2629
 
 
2630
        /* Fetch the call flags                 */
 
2631
        if ((inst->param_2).value == 1){
 
2632
                call_flags      = JIT_CALL_TAIL;
 
2633
        }
 
2634
 
 
2635
        /* Create the JIT call instruction      */
 
2636
        PDEBUG("IRVIRTUALMACHINE: IR_CALL:                      Insert the JIT call instruction\n");
 
2637
        switch ((inst->result).type){
 
2638
                case IROFFSET:
 
2639
                        PDEBUG("IRVIRTUALMACHINE: IR_CALL:      Variable %lld = call(Token = 0x%llX Binary = %s)\n",
 
2640
                               (inst->result).value, (inst->param_1).value, inst->binary->name);
 
2641
 
 
2642
 
 
2643
                        if (jitFunction->locals[(inst->result).value] != NULL){
 
2644
                                jit_value_t     temp;
 
2645
                                temp    = jit_insn_call(jitFunction->function, ir_jump_method->getName(ir_jump_method), jumpMethodJIT->function, jit_signature, args, args_number, call_flags);
 
2646
                                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
2647
                        } else {
 
2648
                                jitFunction->locals[(inst->result).value] = jit_insn_call(jitFunction->function, ir_jump_method->getName(ir_jump_method), jumpMethodJIT->function, jit_signature, args, args_number, call_flags);
 
2649
                        }
 
2650
                        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2651
                        break;
 
2652
                case IRVOID:
 
2653
                        PDEBUG("IRVIRTUALMACHINE: IR_CALL:                              call(Token = 0x%llX Binary = %s)\n",
 
2654
                               (inst->param_1).value, inst->binary->name);
 
2655
 
 
2656
                        /* Call the method                                      */
 
2657
                        jit_insn_call(jitFunction->function, ir_jump_method->getName(ir_jump_method), jumpMethodJIT->function, jit_signature, args, args_number, call_flags);
 
2658
                        break;
 
2659
                default:
 
2660
                        print_err("IRVIRTUALMACHINE: ERROR = Result type not known. ", 0);
 
2661
                        abort();
 
2662
        }
 
2663
 
 
2664
        /* Return                               */
 
2665
        PDEBUG("IRVIRTUALMACHINE: IR_CALL:      End\n");
 
2666
        return 0;
 
2667
}
 
2668
 
 
2669
static inline JITINT16 translate_ir_ret (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction) {
 
2670
        jit_value_t result;
 
2671
 
 
2672
        /* Assertions                           */
 
2673
        assert(method != NULL);
 
2674
        assert(inst   != NULL);
 
2675
        PDEBUG("IRVIRTUALMACHINE: translate_ir_ret:     Start\n");
 
2676
 
 
2677
        /* Init the variable                    */
 
2678
        result = NULL;
 
2679
 
 
2680
        /* Set the tracer                       */
 
2681
        if ((_this->behavior).tracer){
 
2682
                insert_tracer(_this, method, jitFunction, JITTRUE);
 
2683
        }
 
2684
 
 
2685
        /* Check if we have to profile the root *
 
2686
         * set                                  */
 
2687
        if (internal_addRootSetProfile(_this, method, jitFunction)){
 
2688
                jit_insn_call_native(jitFunction->function, "popLastRootSet", _this->gc->popLastRootSet, _this->gc->signPopLastRootSet, NULL, 0, 0);
 
2689
        }
 
2690
 
 
2691
        /* Translate the feedback code  */
 
2692
        //translate_exit_method_feedback_code(system, method);
 
2693
 
 
2694
        switch ((method->signature).result_type){
 
2695
                case IRVOID:
 
2696
                        assert((inst->param_1).type == NOPARAM);
 
2697
                        PDEBUG("IRVIRTUALMACHINE:               Return(VOID)\n");
 
2698
                        break;
 
2699
                default:
 
2700
                        assert((inst->param_1).type != NOPARAM);
 
2701
                        /* Check where the value is     */
 
2702
                        switch ((inst->param_1).type){
 
2703
                                case IROFFSET:
 
2704
                                        PDEBUG("IRVIRTUALMACHINE:               Return(Variable %lld)\n", (inst->param_1).value);
 
2705
                                        if (jitFunction->locals[(inst->param_1).value] == NULL){
 
2706
                                                jitFunction->locals[(inst->param_1).value]      = jit_value_create(jitFunction->function, internal_fromIRTypeToJITType(_this, (inst->param_1).internal_type, (inst->param_1).value_type_infos.type_infos));
 
2707
                                                assert(jitFunction->locals[(inst->param_1).value] != NULL);
 
2708
                                        }
 
2709
                                        result = jitFunction->locals[(inst->param_1).value];
 
2710
                                        break;
 
2711
                                case IRINT32:
 
2712
                                        PDEBUG("IRVIRTUALMACHINE:               Return(INT32 %lld)\n", (inst->param_1).value);
 
2713
                                        result = jit_value_create_nint_constant (jitFunction->function, jit_type_int, (JITINT32) (inst->param_1).value);
 
2714
                                        break;
 
2715
                                case IRINT64:
 
2716
                                        PDEBUG("IRVIRTUALMACHINE:               Return(INT64 %lld)\n", (inst->param_1).value);
 
2717
                                        result = jit_value_create_long_constant (jitFunction->function, jit_type_long, (JITINT64) (inst->param_1).value);
 
2718
                                        break;
 
2719
                                case IRUINT32:
 
2720
                                        PDEBUG("IRVIRTUALMACHINE:               Return(UINT32 %lld)\n", (inst->result).value);
 
2721
                                        result = jit_value_create_nint_constant (jitFunction->function, jit_type_uint, (JITUINT32) (inst->param_1).value);
 
2722
                                        break;
 
2723
                                case IRUINT64:
 
2724
                                        PDEBUG("IRVIRTUALMACHINE:               Return(UINT64 %lld)\n", (inst->result).value );
 
2725
                                        result = jit_value_create_long_constant(jitFunction->function, jit_type_ulong, (JITUINT64) (inst->param_1).value);
 
2726
                                        break;
 
2727
                                case IRFLOAT32:
 
2728
                                        PDEBUG("IRVIRTUALMACHINE:               Return(FLOAT32 %f)\n", (inst->result).fvalue);
 
2729
                                        result = jit_value_create_float32_constant (jitFunction->function, jit_type_float32, (JITFLOAT32) (inst->param_1).fvalue);
 
2730
                                        break;
 
2731
                                case IRFLOAT64:
 
2732
                                        PDEBUG("IRVIRTUALMACHINE:               Return(FLOAT64 %f)\n", (inst->result).fvalue);
 
2733
                                        result = jit_value_create_float64_constant (jitFunction->function, jit_type_float64, (JITFLOAT64) (inst->param_1).fvalue);
 
2734
                                        break;
 
2735
                                case IRNFLOAT:
 
2736
                                        if (sizeof(JITNUINT) == 4){
 
2737
                                                PDEBUG("IRVIRTUALMACHINE:               Return(FLOAT32 %f)\n", (inst->result).fvalue);
 
2738
                                                result = jit_value_create_float32_constant (jitFunction->function, jit_type_float32, (JITFLOAT32) (inst->param_1).fvalue);
 
2739
                                        } else {
 
2740
                                                PDEBUG("IRVIRTUALMACHINE:               Return(FLOAT64 %f)\n", (inst->result).fvalue);
 
2741
                                                result = jit_value_create_float64_constant (jitFunction->function, jit_type_float64, (JITFLOAT64) (inst->param_1).fvalue);
 
2742
                                        }
 
2743
                                        break;
 
2744
                                case IRUPOINTER:
 
2745
                                        PDEBUG("IRVIRTUALMACHINE:               Return(Unmanaged_POINTER %p)\n", (void *)(JITNUINT)(inst->param_1).value);
 
2746
                                        result = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr, (inst->param_1).value);
 
2747
                                        break;
 
2748
                                case IRMPOINTER:
 
2749
                                        PDEBUG("IRVIRTUALMACHINE:               Return(Managed_POINTER %p)\n", (void *)(JITNUINT)(inst->param_1).value);
 
2750
                                        result = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr, (inst->param_1).value);
 
2751
                                        break;
 
2752
                                case IRTPOINTER:
 
2753
                                        PDEBUG("IRVIRTUALMACHINE:               Return(Transient_POINTER %p)\n", (void *)(JITNUINT)(inst->param_1).value);
 
2754
                                        result = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr, (inst->param_1).value);
 
2755
                                        break;
 
2756
                                case IROBJECT:
 
2757
                                        PDEBUG("IRVIRTUALMACHINE:               Return(OBJECT %p)\n", (void *)(JITNUINT)(inst->param_1).value);
 
2758
                                        result = jit_value_create_nint_constant (jitFunction->function, jit_type_void_ptr, (inst->param_1).value);
 
2759
                                        break;
 
2760
                                default:
 
2761
                                        print_err("IRVIRTUALMACHINE: ERROR = Result type is not known. ", 0);
 
2762
                                        abort();
 
2763
                        }
 
2764
                        assert(result != NULL);
 
2765
        }
 
2766
 
 
2767
        /* Insert the native stop call      */
 
2768
        #ifdef MORPHEUS
 
2769
        internal_insert_native_stop_function(method);
 
2770
        #endif
 
2771
 
 
2772
        /* Create the return instruction        */
 
2773
        jit_insn_return(jitFunction->function, result);
 
2774
 
 
2775
        PDEBUG("IRVIRTUALMACHINE: translate_ir_ret:     End\n");
 
2776
        return 0;
 
2777
}
 
2778
 
 
2779
static inline JITINT16 translate_ir_eq (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
2780
        jit_value_t             param_1;
 
2781
        jit_value_t             param_2;
 
2782
        jit_value_t             temp;
 
2783
        jit_value_t             temp2;
 
2784
 
 
2785
        /* Assertions           */
 
2786
        assert(_this != NULL);
 
2787
        assert(method != NULL);
 
2788
        assert(inst != NULL);
 
2789
        assert((inst->result).type == IROFFSET);
 
2790
 
 
2791
        /* Create the first parameter   */
 
2792
        PDEBUG("IRVIRTUALMACHINE: IREQ:         Variable %lld = equal(", (inst->result).value);
 
2793
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2794
        PDEBUG(", ");
 
2795
        assert(param_1 != NULL);
 
2796
 
 
2797
        /* Create the second parameter  */
 
2798
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
2799
        PDEBUG(")\n");
 
2800
        assert(param_2 != NULL);
 
2801
 
 
2802
        /* Create the equal instruction         */
 
2803
        temp    = jit_insn_eq(jitFunction->function, param_1, param_2);
 
2804
        temp2   = jit_insn_to_bool(jitFunction->function, temp);
 
2805
        assert(temp2 != NULL);
 
2806
 
 
2807
        /* Store the result                     */
 
2808
        if (jitFunction->locals[(inst->result).value] != NULL){
 
2809
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp2);
 
2810
        } else {
 
2811
                jitFunction->locals[(inst->result).value] = temp2;
 
2812
        }
 
2813
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2814
 
 
2815
        /* Return                               */
 
2816
        return 0;
 
2817
}
 
2818
 
 
2819
static inline JITINT16 translate_ir_branchifnot (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction){
 
2820
        t_jit_label             *label;
 
2821
        jit_value_t             param_1;
 
2822
 
 
2823
        /* Assertions                   */
 
2824
        assert(method != NULL);
 
2825
        assert(inst != NULL);
 
2826
        assert(_this != NULL);
 
2827
        assert((inst->param_2).type == IRLABELITEM);
 
2828
        PDEBUG("IRVIRTUALMACHINE:               branch_if_not(Variable %lld, Label \"L%lld\")\n",(inst->param_1).value, (inst->param_2).value);
 
2829
 
 
2830
        /* Insert the label             */
 
2831
        label   = insert_label(labels, (inst->param_2).value);
 
2832
        assert(label != NULL);
 
2833
 
 
2834
        /* Create the condition         */
 
2835
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2836
        assert(param_1 != NULL);
 
2837
 
 
2838
        /* Create the jump              */
 
2839
        jit_insn_branch_if_not(jitFunction->function, param_1, &(label->label));
 
2840
 
 
2841
        /* Return                       */
 
2842
        return 0;
 
2843
}
 
2844
 
 
2845
static inline JITINT16 translate_ir_branchif (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, XanList *labels, t_jit_function *jitFunction){
 
2846
        t_jit_label     *label;
 
2847
        jit_value_t     param_1;
 
2848
 
 
2849
        /* Assertions           */
 
2850
        assert(_this != NULL);
 
2851
        assert(method != NULL);
 
2852
        assert(inst != NULL);
 
2853
        assert((inst->param_2).type == IRLABELITEM);
 
2854
 
 
2855
        PDEBUG("IRVIRTUALMACHINE:               branch_if(Variable %lld, Label \"L%lld\")\n", (inst->param_1).value, (inst->param_2).value);
 
2856
        label = insert_label(labels, (inst->param_2).value);
 
2857
        assert(label != NULL);
 
2858
 
 
2859
        /* Make the condition of the branch                     */
 
2860
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2861
        assert(param_1 != NULL);
 
2862
 
 
2863
        /* Generate the jump                                    */
 
2864
        jit_insn_branch_if(jitFunction->function , param_1, &(label->label));
 
2865
 
 
2866
        /* Return                                               */
 
2867
        return 0;
 
2868
}
 
2869
 
 
2870
static inline JITINT16 translate_ir_gt (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
2871
        jit_value_t             param_1;
 
2872
        jit_value_t             param_2;
 
2873
        jit_value_t             temp;
 
2874
        jit_value_t             temp2;
 
2875
 
 
2876
        /* Assertions           */
 
2877
        assert(_this != NULL);
 
2878
        assert(method != NULL);
 
2879
        assert(inst != NULL);
 
2880
        assert((inst->result).type == IROFFSET);
 
2881
 
 
2882
        /* Create the first parameter   */
 
2883
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = gt(", (inst->result).value);
 
2884
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2885
        PDEBUG(", ");
 
2886
        assert(param_1 != NULL);
 
2887
 
 
2888
        /* Create the second parameter  */
 
2889
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
2890
        PDEBUG(")\n");
 
2891
        assert(param_2 != NULL);
 
2892
 
 
2893
        /* Create the gt instruction            */
 
2894
        temp    = jit_insn_gt(jitFunction->function, param_1, param_2);
 
2895
        temp2   = jit_insn_to_bool(jitFunction->function, temp);
 
2896
        assert(temp2 != NULL);
 
2897
 
 
2898
        /* Store the result                     */
 
2899
        if (jitFunction->locals[(inst->result).value] != NULL){
 
2900
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp2);
 
2901
        } else {
 
2902
                jitFunction->locals[(inst->result).value] = temp2;
 
2903
        }
 
2904
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2905
 
 
2906
        /* Return                               */
 
2907
        return 0;
 
2908
}
 
2909
 
 
2910
static inline JITINT16 translate_ir_not (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
2911
        jit_value_t             param_1;
 
2912
 
 
2913
        /* Assertions           */
 
2914
        assert(_this != NULL);
 
2915
        assert(method != NULL);
 
2916
        assert(inst != NULL);
 
2917
        assert((inst->result).type == IROFFSET);
 
2918
 
 
2919
        /* Create the first parameter   */
 
2920
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = not (", (inst->result).value);
 
2921
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2922
        assert(param_1 != NULL);
 
2923
        PDEBUG(")\n");
 
2924
 
 
2925
        /* Create the lt instruction            */
 
2926
        if (jitFunction->locals[(inst->result).value] != NULL){
 
2927
                jit_value_t     temp;
 
2928
                temp    = jit_insn_not(jitFunction->function, param_1);
 
2929
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
2930
        } else {
 
2931
                jitFunction->locals[(inst->result).value] = jit_insn_not(jitFunction->function, param_1);
 
2932
        }
 
2933
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2934
 
 
2935
        /* Return                               */
 
2936
        return 0;
 
2937
}
 
2938
 
 
2939
static inline JITINT16 translate_ir_lt (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
2940
        jit_value_t             param_1;
 
2941
        jit_value_t             param_2;
 
2942
        jit_value_t             temp;
 
2943
        jit_value_t             temp2;
 
2944
 
 
2945
        /* Assertions           */
 
2946
        assert(method != NULL);
 
2947
        assert(inst != NULL);
 
2948
        assert((inst->result).type == IROFFSET);
 
2949
 
 
2950
        /* Create the first parameter   */
 
2951
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = lt(", (inst->result).value);
 
2952
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2953
        PDEBUG(", ");
 
2954
        assert(param_1 != NULL);
 
2955
 
 
2956
        /* Create the second parameter  */
 
2957
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
2958
        PDEBUG(")\n");
 
2959
        assert(param_2 != NULL);
 
2960
 
 
2961
        /* Create the lt instruction            */
 
2962
        temp    = jit_insn_lt(jitFunction->function, param_1, param_2);
 
2963
        temp2   = jit_insn_to_bool(jitFunction->function, temp);
 
2964
        assert(temp2 != NULL);
 
2965
 
 
2966
        /* Store the result                     */
 
2967
        if (jitFunction->locals[(inst->result).value] != NULL){
 
2968
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp2);
 
2969
        } else {
 
2970
                jitFunction->locals[(inst->result).value] = temp2;
 
2971
        }
 
2972
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
2973
 
 
2974
        /* Return                               */
 
2975
        return 0;
 
2976
}
 
2977
 
 
2978
static inline JITINT16 translate_ir_store (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
2979
        jit_value_t temp;
 
2980
 
 
2981
        /* Assertions                                           */
 
2982
        assert(method != NULL);
 
2983
        assert(_this != NULL);
 
2984
        assert(inst != NULL);
 
2985
        assert((inst->param_1).type == IROFFSET);
 
2986
        #ifdef DEBUG
 
2987
        if ((inst->param_1).internal_type == IRVALUETYPE){
 
2988
                assert(  (inst->param_1).value_type_infos.type_infos != NULL
 
2989
                      || (inst->param_1).value_type_infos.isByref != 0);
 
2990
        }
 
2991
        #endif
 
2992
        PDEBUG("IRVIRTUALMACHINE: translate_ir_store: Start\n");
 
2993
 
 
2994
        /* Init the variables                                   */
 
2995
        temp    = NULL;
 
2996
 
 
2997
        /* Check the parameters                                 */
 
2998
        jitFunction->locals[(inst->param_1).value]      = make_variable(_this, method, &(inst->param_1), jitFunction);
 
2999
        assert(jitFunction->locals[(inst->param_1).value] != NULL);
 
3000
 
 
3001
        /* Create the second parameter                          */
 
3002
        PDEBUG("IRVIRTUALMACHINE:               store(Variable %lld, ", (inst->param_1).value);
 
3003
        temp    = make_variable(_this, method, &(inst->param_2), jitFunction);
 
3004
        PDEBUG(")\n");
 
3005
        assert(temp != NULL);
 
3006
 
 
3007
        /* Create the store instruction                         */
 
3008
        jit_insn_store(jitFunction->function, jitFunction->locals[(inst->param_1).value], temp);
 
3009
 
 
3010
        PDEBUG("IRVIRTUALMACHINE: translate_ir_store: End\n");
 
3011
 
 
3012
        /* Return                                               */
 
3013
        return 0;
 
3014
}
 
3015
 
 
3016
static inline JITINT16 translate_ir_rem (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
3017
        jit_value_t             param_1;
 
3018
        jit_value_t             param_2;
 
3019
 
 
3020
        /* Assertions           */
 
3021
        assert(_this != NULL);
 
3022
        assert(method != NULL);
 
3023
        assert(inst != NULL);
 
3024
        assert((inst->result).type == IROFFSET);
 
3025
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = rem(", (inst->result).value);
 
3026
 
 
3027
        /* Create the first parameter   */
 
3028
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
3029
        PDEBUG(", ");
 
3030
        assert(param_1 != NULL);
 
3031
 
 
3032
        /* Create the second parameter  */
 
3033
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
3034
        PDEBUG(")\n");
 
3035
        assert(param_2 != NULL);
 
3036
 
 
3037
        /* Create the instruction               */
 
3038
        if (jitFunction->locals[(inst->result).value] != NULL){
 
3039
                jit_value_t     temp;
 
3040
                temp    = jit_insn_rem (jitFunction->function, param_1, param_2);
 
3041
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
3042
        } else {
 
3043
                jitFunction->locals[(inst->result).value] = jit_insn_rem (jitFunction->function, param_1, param_2);
 
3044
        }
 
3045
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
3046
 
 
3047
        /* Return                               */
 
3048
        return 0;
 
3049
}
 
3050
 
 
3051
JITINT16 fetch_parameters (ir_method_t *method, t_jit_function *jitFunction){
 
3052
        JITUINT32               count;
 
3053
 
 
3054
        /* Assertions                           */
 
3055
        assert(method != NULL);
 
3056
        assert(jitFunction != NULL);
 
3057
 
 
3058
        if (method->getParametersNumber(method) == 0) return 0;
 
3059
        assert(jitFunction->locals != NULL);
 
3060
 
 
3061
        PDEBUG("IRVIRTUALMACHINE:               Fetch the parameters\n");
 
3062
        for (count=0; count < method->getParametersNumber(method); count++) {
 
3063
                PDEBUG("IRVIRTUALMACHINE:                       Parameter %d\n", count);
 
3064
                jitFunction->locals[count]      = jit_value_get_param(jitFunction->function, count);
 
3065
        }
 
3066
 
 
3067
        /* Return                               */
 
3068
        return 0;
 
3069
}
 
3070
 
 
3071
static inline JITINT16 translate_ir_add_ovf (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
3072
        jit_value_t             param_1;
 
3073
        jit_value_t             param_2;
 
3074
 
 
3075
        /* Assertions           */
 
3076
        assert(method != NULL);
 
3077
        assert(inst != NULL);
 
3078
        assert((inst->result).type == IROFFSET);
 
3079
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = add_ovf(", (inst->result).value);
 
3080
 
 
3081
        /* Create the first parameter   */
 
3082
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
3083
        PDEBUG(", ");
 
3084
        assert(param_1 != NULL);
 
3085
 
 
3086
        /* Create the second parameter  */
 
3087
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
3088
        PDEBUG(")\n");
 
3089
        assert(param_2 != NULL);
 
3090
 
 
3091
        /* Create the add_ovf instruction               */
 
3092
        if (jitFunction->locals[(inst->result).value] != NULL){
 
3093
                jit_value_t     temp;
 
3094
                temp    = jit_insn_add_ovf (jitFunction->function, param_1, param_2);
 
3095
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
3096
        } else {
 
3097
                jitFunction->locals[(inst->result).value] = jit_insn_add_ovf (jitFunction->function, param_1, param_2);
 
3098
        }
 
3099
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
3100
 
 
3101
        /* Return                                       */
 
3102
        return 0;
 
3103
}
 
3104
 
 
3105
static inline JITINT16 translate_ir_sub_ovf (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
3106
        jit_value_t             param_1;
 
3107
        jit_value_t             param_2;
 
3108
 
 
3109
        /* Assertions           */
 
3110
        assert(method != NULL);
 
3111
        assert(inst != NULL);
 
3112
        assert((inst->result).type == IROFFSET);
 
3113
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = sub_ovf(", (inst->result).value);
 
3114
 
 
3115
        /* Create the first parameter   */
 
3116
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
3117
        PDEBUG(", ");
 
3118
        assert(param_1 != NULL);
 
3119
 
 
3120
        /* Create the second parameter  */
 
3121
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
3122
        PDEBUG(")\n");
 
3123
        assert(param_2 != NULL);
 
3124
 
 
3125
        /* Create the instruction               */
 
3126
        if (jitFunction->locals[(inst->result).value] != NULL){
 
3127
                jit_value_t     temp;
 
3128
                temp    = jit_insn_sub_ovf (jitFunction->function, param_1, param_2);
 
3129
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
3130
        } else {
 
3131
                jitFunction->locals[(inst->result).value] = jit_insn_sub_ovf (jitFunction->function, param_1, param_2);
 
3132
        }
 
3133
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
3134
 
 
3135
        /* Return                               */
 
3136
        return 0;
 
3137
}
 
3138
 
 
3139
static inline JITINT16 translate_ir_mul_ovf (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
3140
        jit_value_t             param_1;
 
3141
        jit_value_t             param_2;
 
3142
 
 
3143
        /* Assertions           */
 
3144
        assert(method != NULL);
 
3145
        assert(inst != NULL);
 
3146
        assert((inst->result).type == IROFFSET);
 
3147
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = mul_ovf(", (inst->result).value);
 
3148
 
 
3149
        /* Create the first parameter   */
 
3150
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
3151
        PDEBUG(", ");
 
3152
        assert(param_1 != NULL);
 
3153
 
 
3154
        /* Create the second parameter  */
 
3155
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
3156
        PDEBUG(")\n");
 
3157
        assert(param_2 != NULL);
 
3158
 
 
3159
        /* Create the instruction               */
 
3160
        if (jitFunction->locals[(inst->result).value] != NULL){
 
3161
                jit_value_t     temp;
 
3162
                temp    = jit_insn_mul_ovf (jitFunction->function, param_1, param_2);
 
3163
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
3164
        } else {
 
3165
                jitFunction->locals[(inst->result).value] = jit_insn_mul_ovf (jitFunction->function, param_1, param_2);
 
3166
        }
 
3167
        assert(jitFunction->locals[(inst->result).value] != NULL);
 
3168
 
 
3169
        /* Return                               */
 
3170
        return 0;
 
3171
}
 
3172
 
 
3173
static inline JITINT16 translate_ir_shl (IRVM_t *_this, ir_method_t *method, t_ir_instruction *inst, t_jit_function *jitFunction){
 
3174
        jit_value_t             param_1;
 
3175
        jit_value_t             param_2;
 
3176
 
 
3177
        /* Assertions           */
 
3178
        assert(method != NULL);
 
3179
        assert(inst != NULL);
 
3180
        assert((inst->result).type == IROFFSET);
 
3181
        PDEBUG("IRVIRTUALMACHINE:               Variable %lld = shl(", (inst->result).value);
 
3182
 
 
3183
        /* Create the first parameter   */
 
3184
        param_1 = make_variable(_this, method, &(inst->param_1), jitFunction);
 
3185
        PDEBUG(", ");
 
3186
        assert(param_1 != NULL);
 
3187
 
 
3188
        /* Create the second parameter  */
 
3189
        param_2 = make_variable(_this, method, &(inst->param_2), jitFunction);
 
3190
        PDEBUG(")\n");
 
3191
        assert(param_2 != NULL);
 
3192
 
 
3193
        /* Create the shl instruction           */
 
3194
        if (jitFunction->locals[(inst->result).value] != NULL){
 
3195
                jit_value_t     temp;
 
3196
                temp    = jit_insn_shl (jitFunction->function, param_1, param_2);
 
3197
                jit_insn_store(jitFunction->function, jitFunction->locals[(inst->result).value], temp);
 
3198
  &nbs