2
* Copyright (C) 2009 Campanoni Simone, Di Biagio Andrea, Farina Roberto, Tartara Michele
4
* iljit - This is a Just-in-time for the CIL language specified with the ECMA-335
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.
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.
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
28
#include <ir_language.h>
29
#include <error_codes.h>
30
#include <metadata/metadata_types.h>
31
#include <metadata_manager_support.h>
32
#include <ecma_constant.h>
33
#include <cil_opcodes.h>
34
#include <compiler_memory_manager.h>
35
#include <ir_virtual_machine.h>
36
#include <garbage_collector.h>
40
#include <cil_ir_translator.h>
41
#include <cil_stack.h>
43
#include <ildjit_assertions.h>
44
#include <iljit_dumper.h>
45
#include <general_tools.h>
46
#include <system_manager.h>
47
#include <internal_calls_manager.h>
48
#include <recompiler.h>
54
/* unaligned prefix values */
55
#define UNALIGNED_DONOTCHECK_ALIGNMENT 9
56
#define UNALIGNED_DEFAULT_ALIGNMENT 0
57
#define UNALIGNED_BYTE_ALIGNMENT 1
58
#define UNALIGNED_DOUBLEBYTE_ALIGNMENT 2
59
#define UNALIGNED_QUADBYTE_ALIGNMENT 4
61
static inline JITINT8 convertEnumIntoInt32(t_system *system, ir_item_t *item);
62
static inline void refresh_max_variables(t_system *system, t_stack *stack, Method method);
63
static inline void print_stack (t_stack *stack, JITUINT32 parameters, JITUINT32 locals);
64
static inline void print_stack_element(t_stack *stack, JITUINT32 elementID);
65
static inline JITINT16 create_call_IO(t_system *system, t_ir_instruction *inst, Method ilMethod, t_stack *stack, JITBOOLEAN created, Method creatorMethod, t_ir_signature *signature_of_the_jump_method, JITUINT32 bytes_read, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels);
66
static inline JITINT16 decode_locals_signature(t_system *system, JITUINT32 local_var_sig_tok, t_binary_information *binary, t_stack *stack, Method method);
67
static inline void print_labels (GList *labels);
68
static inline void labels_decrement_counter(GList *labels, JITUINT32 value);
69
static inline JITINT16 create_signature (t_system *system, t_binary_information **binary, Method method, JITUINT32 token, JITUINT32 *entry_point_address, JITBOOLEAN setJumper);
70
static inline GList * invalidate_blocks_starting_at_label(t_system *system, GList *labels, t_label *label);
71
static inline GList * invalidate_An_Handler(GList *labels, t_try_handler *current_handler);
72
static inline GList * invalidate_A_block(t_system *system, GList *labels, t_try_block *block);
73
static inline JITBOOLEAN coerce_operands_for_binary_operation(t_system *system, Method method , JITUINT32 bytes_read, t_stack *stack);
74
static inline JITBOOLEAN coerce_operands_for_binary_operation_to_unsigned_types (t_system *system, Method method , JITUINT32 bytes_read, t_stack *stack, JITBOOLEAN force_stackable_type);
75
static inline JITBOOLEAN _perform_conversion(t_system *system, Method method , JITUINT32 bytes_read, t_stack *stack, JITUINT32 toType , JITBOOLEAN with_overflow_check, t_ir_instruction *before);
76
static inline JITBOOLEAN _translate_binary_operation(t_system *system, Method method , JITUINT32 bytes_read, t_stack *stack, JITUINT32 IRop , JITUINT32 return_internal_type);
77
static inline JITBOOLEAN _translate_arithmetic_operation(t_system *system, Method method , JITUINT32 bytes_read, t_stack *stack, JITUINT32 IRop);
78
static inline JITBOOLEAN _translate_arithmetic_operation_un(t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack, JITUINT32 IRop);
79
static inline t_label * fetch_label (GList *labels, JITUINT32 ir_position);
80
static inline t_ir_instruction * find_insert_point(Method method, JITUINT32 insert_point);
81
static inline t_label * find_label_at_position(GList *labels, JITUINT32 bytes_offset);
82
IR_ITEM_VALUE get_field_number(t_binary_information *current_binary, JITUINT32 new_token);
83
static inline JITINT16 decode_exceptions (t_system *system, CILStack cilStack, t_binary_information *binary, JITUINT32 body_size, GList **labels, JITUINT32 *current_label_ID, Method method, t_stack *stack);
84
static inline t_try_block * find_inner_label(GList *blocks, JITUINT32 current_offset);
85
static inline t_try_block * find_next_inner_label(GList *blocks, t_try_block *inner_block);
86
static inline t_label * get_label_by_bytes_offset(GList *labels, JITUINT32 bytes_offset);
87
static inline JITINT16 cil_insert_label(t_system *system, CILStack cilStack, GList **labels, t_label *label, t_stack *stack, JITINT32 position);
88
static inline JITINT16 translate_cil_dup(t_system *system, t_binary_information *current_binary, Method method, JITUINT32 bytes_read, t_stack *stack);
89
static inline JITINT32 internal_check_ir (ir_method_t *method);
92
* @brief Store a value into a new variable
96
* --------- --------\ ---------
97
* | value | --------/ | varID |
98
* --------- / ---------
103
static inline JITINT16 translate_cil_store (t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack);
104
static inline JITINT16 translate_cil_arglist(t_system *system, CILStack cilStack, Method method, JITUINT32 bytes_read, t_stack *stack, JITUINT32 *current_label_ID, GList **labels);
105
static inline JITINT16 translate_cil_branch(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, JITUINT32 inst_size, t_stack *stack);
106
static inline JITINT8 translate_cil_sizeof (t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITUINT32 token);
107
static inline JITINT16 translate_cil_brfalse (t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, JITUINT32 inst_size, t_stack *stack);
108
static inline JITINT16 translate_cil_brtrue (t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, JITUINT32 inst_size, t_stack *stack);
109
static inline JITINT16 translate_cil_bge (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, JITUINT32 inst_size, t_stack *stack, JITBOOLEAN unordered);
110
static inline JITINT16 translate_cil_blt (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, JITUINT32 inst_size, t_stack *stack, JITBOOLEAN unordered);
111
static inline JITINT16 translate_cil_beq (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, JITUINT32 inst_size, t_stack *stack);
112
static inline JITINT16 translate_cil_bneq (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, JITUINT32 inst_size, t_stack *stack);
113
static inline JITINT16 translate_cil_conv(t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack, JITUINT32 type, JITBOOLEAN ovf, JITBOOLEAN force_unsigned_check, JITBOOLEAN force_stackable_type);
114
static inline JITINT16 translate_cil_ldlen(t_system *system, Method method, CILStack cilStack, JITUINT32 bytes_read, t_stack *stack, JITUINT32 *current_label_ID, GList **labels);
115
static inline JITINT16 translate_cil_ldelem(t_system *system, Method method, CILStack cilStack, JITUINT32 bytes_read, JITUINT32 type, t_stack *stack, JITUINT32 *current_label_ID, GList **labels, t_binary_information *binary);
116
static inline JITINT16 translate_cil_load_fconstant (t_system *system, Method method, JITUINT32 bytes_read, IR_ITEM_FVALUE value, JITUINT32 type, t_stack *stack);
117
static inline JITINT16 translate_cil_load_constant (t_system *system, Method method, JITUINT32 bytes_read, IR_ITEM_VALUE value, JITUINT32 type, t_stack *stack);
118
static inline JITINT16 translate_cil_stelem(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, ILType *classLocated, JITUINT32 type, t_stack *stack, t_binary_information *binary);
119
static inline JITINT16 translate_cil_checknull(t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack);
120
static inline JITINT16 translate_cil_ldcalloc (t_system *system, CILStack cilStack, t_binary_information *binary, Method method, JITUINT32 bytes_read, t_stack *stack, JITUINT32 *current_label_ID, GList **labels);
121
static inline JITINT16 translate_cil_call (t_system *system, CILStack cilStack, t_binary_information *binary, Method method, JITUINT32 token, JITUINT32 bytes_read, t_stack *stack, JITBOOLEAN isTail, JITUINT32 *current_label_ID, GList **labels, JITBOOLEAN created, XanList* methodsToCall);
122
static inline JITINT16 translate_cil_calli (t_system *system, CILStack cilStack, t_binary_information *binary, Method method, JITUINT32 token, JITUINT32 bytes_read, t_stack *stack, JITBOOLEAN isTail, JITUINT32 *current_label_ID, GList **labels);
123
static inline JITINT16 translate_cil_call_by_methodID(t_system *system, Method method, ILMethodID methodID, t_binary_information *binary_of_the_method, JITUINT32 bytes_read, t_stack *stack, JITBOOLEAN created, ILMethod_signature *signature_of_the_jump_method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels);
124
static inline JITINT16 translate_cil_castclass(t_system *system, Method method, CILStack cilStack, JITUINT32 token, t_binary_information *binary, GList **labels, JITUINT32 *current_label_ID, JITUINT32 bytes_read, t_stack *stack);
125
static inline JITINT16 translate_cil_ldstr(t_system *system, Method method, CILStack cilStack, JITUINT32 token, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITUINT32 *current_label_ID, GList **labels);
126
static inline JITINT16 translate_cil_leave(Method method, CILStack cilStack, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, t_system *system, JITUINT32 inst_size, t_stack *stack);
127
static inline JITINT16 translate_cil_newobj (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 bytes_read, JITUINT32 token, t_stack *stack, JITUINT32 *current_label_ID, GList **labels, XanList *methodsToCall);
128
static inline JITINT16 translate_cil_initobj (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 bytes_read, JITUINT32 token, t_stack *stack, JITUINT32 *current_label_ID, GList **labels);
129
static inline JITINT16 translate_cil_box (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 bytes_read, JITUINT32 token, t_stack *stack, JITUINT32 *current_label_ID, GList **labels);
130
static inline JITINT16 translate_cil_unbox (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 bytes_read, JITUINT32 token, t_stack *stack, JITUINT32 *current_label_ID, GList **labels);
131
static inline JITINT16 translate_cil_bgt (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, JITUINT32 inst_size, t_stack *stack, JITBOOLEAN unordered);
132
static inline JITINT16 translate_cil_throw(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary);
133
static inline JITINT16 translate_cil_rethrow(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary);
134
static inline JITINT16 translate_cil_refanyval(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITUINT32 token);
135
static inline JITINT16 translate_cil_newarr (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 bytes_read, JITUINT32 token, t_stack *stack, JITUINT32 *current_label_ID, GList **labels);
136
static inline JITINT16 translate_cil_ldelema (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 bytes_read, JITUINT32 token, t_stack *stack, JITUINT32 *current_label_ID, GList **labels);
137
static inline JITINT16 translate_cil_vcall(t_system *system, CILStack cilStack, t_binary_information *binary, Method method, JITUINT32 token, JITUINT32 bytes_read, t_stack *stack, JITBOOLEAN isTail, JITUINT32 *current_label_ID, GList **labels);
138
static inline JITINT16 translate_cil_ldind(t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack, JITUINT32 type, JITUINT32 target_type, t_binary_information *current_binary, JITUINT32 *current_label_ID, GList **labels);
139
static inline JITINT16 translate_cil_stind(t_system *system, Method method, CILStack cilStack, JITUINT32 bytes_read, t_stack *stack, t_binary_information *current_binary, JITUINT32 *current_label_ID, GList **labels, JITUINT32 type);
140
static inline JITINT16 translate_cil_stsfld(Method method, CILStack cilStack, JITUINT32 token, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, t_system *system, JITUINT32 *current_label_ID, GList **labels, XanList *methodsToCall);
141
static inline JITUINT32 translate_cil_ldftn(t_system *system, Method method, CILStack cilStack, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITUINT32 token);
142
static inline JITINT16 translate_cil_stobj (Method method, CILStack cilStack, JITUINT32 token, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, t_system *system, JITUINT32 *current_label_ID, GList **labels, JITUINT8 alignment);
143
static inline JITINT16 translate_cil_ldobj (Method method, CILStack cilStack, JITUINT32 token, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, t_system *system, JITUINT32 *current_label_ID, GList **labels);
144
static inline JITINT16 translate_cil_ble (t_system *system, CILStack cilStack, t_binary_information *current_binary, Method method, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, JITUINT32 inst_size, t_stack *stack, JITBOOLEAN unordered);
145
static inline JITINT16 translate_instruction_with_binary_logical_operator(t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack, JITUINT32 logical_operator);
146
static inline JITINT16 translate_cil_ldfld(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_binary_information *binary, JITUINT32 token, t_stack *stack);
147
static inline JITINT16 translate_cil_ldflda(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_binary_information *binary, JITUINT32 token, t_stack *stack, XanList *methodsToCall);
148
static inline JITINT16 translate_cil_ldsflda (t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_binary_information *binary, JITUINT32 token, t_stack *stack, XanList *methodsToCall);
149
static inline JITINT16 translate_cil_stfld (Method method, CILStack cilStack, JITUINT32 bytes_read, t_binary_information *binary, JITUINT32 token, t_stack *stack, JITUINT32 *current_label_ID, GList **labels, t_system *system);
150
static inline JITINT16 translate_cil_shl (t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack);
151
static inline JITINT16 translate_cil_shr (t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITBOOLEAN unsigned_check);
152
static inline JITINT16 translate_cil_ldsfld(Method method, CILStack cilStack, JITUINT32 token, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, t_system *system, JITUINT32 *current_label_ID, GList **labels, XanList *methodsToCall);
153
static inline JITINT16 translate_cil_ldarga(t_system *system, Method method, JITUINT32 bytes_read, JITUINT16 num, t_stack *stack);
154
static inline JITINT16 translate_cil_ldarg (t_system *system, Method method, JITUINT32 bytes_read, JITUINT32 arg_num, t_stack *stack);
155
static inline JITINT16 translate_cil_starg (t_system *system, Method method, JITUINT32 bytes_read, JITUINT32 arg_num, t_stack *stack);
156
static inline JITINT16 translate_cil_ldloc (t_system *system, Method method, JITUINT32 bytes_read, JITUINT32 loc_num, t_stack *stack);
157
static inline JITINT16 translate_cil_ldloca(t_system *system, Method method, JITUINT32 bytes_read, JITUINT16 num, t_stack *stack, JITBOOLEAN localsInit, JITUINT32 *current_label_ID, GList **labels, t_binary_information *binary);
158
static inline JITINT16 translate_cil_stloc (t_system *system, Method method, JITUINT32 bytes_read, JITUINT32 loc_num, t_stack *stack);
159
static inline JITINT16 translate_cil_ldnull (t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack);
160
static inline JITINT16 translate_cil_ldtoken(t_system *system, Method method, t_binary_information *binary, t_stack *stack, JITUINT32 bytes_read, JITUINT32 token, JITUINT32 *current_label_ID, GList **labels);
161
static inline JITINT16 translate_cil_eq(t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack);
162
static inline JITINT16 translate_cil_gt(t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack);
163
static inline JITINT16 translate_cil_lt(t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack);
164
static inline JITINT16 translate_cil_Ckfinite(Method method, CILStack cilStack, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, t_system *system, JITUINT32 inst_size, t_stack *stack, t_binary_information *binary);
165
static inline JITINT16 make_irnewobj(t_system *system, Method method, CILStack cilStack, JITUINT32 bytes_read, t_binary_information *binary, ILClassID classID, JITUINT32 overSize, t_stack *stack, JITUINT32 *current_label_ID, GList **labels, t_ir_instruction *before);
166
static inline JITINT16 make_irmemcpy(t_system *system, Method method, CILStack cilStack, JITUINT32 bytes_read ,t_binary_information *binary, t_stack *stack , JITUINT32 *current_label_ID, GList **labels, JITINT32 memsize, JITUINT8 alignment, t_ir_instruction *before);
167
static inline JITINT16 make_irnewValueType(t_system *system, Method method, JITUINT32 bytes_read , ILType *value_type, t_stack *stack, t_ir_instruction *before);
168
static inline JITINT16 translate_cil_uses_catcher(t_system *system, Method method, JITUINT32 bytes_read);
169
static inline JITINT16 translate_cil_compare(t_system *system, Method method, CILStack cilStack, JITUINT32 bytes_read, JITUINT32 type, t_stack *stack, JITUINT32 *current_label_ID, GList **labels, t_binary_information *binary, JITBOOLEAN unordered_check, JITBOOLEAN fix_all_labels, JITBOOLEAN force_stackable_type);
170
static inline JITINT16 translate_cil_cpblk(t_system *system, CILStack cilStack, t_binary_information *binary, Method method, JITUINT32 bytes_read, t_stack *stack, JITUINT32 *current_label_ID, GList **labels, JITUINT8 alignment);
171
static inline JITINT16 translate_cil_initblk(t_system *system, CILStack cilStack, t_binary_information *binary, Method method, JITUINT32 bytes_read, t_stack *stack, JITUINT32 *current_label_ID, GList **labels, JITUINT8 alignment);
175
* Insert a IRLABEL instruction (if it is needed) in the instructions list at position (bytes_read + bytes_offset) and set the parameter param to point to that label (where the IR instruction where the param is fill has size equal to inst_size); insert a label item into the labels list and increment by one the current_label_ID (if it is needed).
177
* @param method The current method
178
* @param labels Labels list of the current method
179
* @param bytes_offset Number of bytes to jump from the current position
180
* @param inst_size Size in bytes of the current branch instruction
181
* @param bytes_read Bytes read from the first instruction of the current method
182
* @param current_label_ID Current label ID free
183
* @param param Parameter of the current branch instruction
184
* @param stack Current stack of the method
186
static inline JITINT16 add_label_inst (t_system *system, Method method, CILStack cilStack, GList **labels, JITINT32 bytes_offset, JITUINT32 inst_size, JITUINT32 bytes_read, JITUINT32 *current_label_ID, ir_item_t *param, t_stack *stack);
187
static inline t_ir_instruction * insert_label_before (Method method, t_ir_instruction *inst, JITUINT32 current_label_ID, JITUINT32 bytes_offset, JITBOOLEAN *label_already_assigned);
189
static inline JITINT16 internal_translate_ldlen (t_system *system, Method method, JITUINT32 bytes_read, t_stack *stack, JITINT32 forceStackable);
190
static inline JITINT16 perform_leave(Method method, CILStack cilStack, JITUINT32 *current_label_ID, JITUINT32 bytes_read, JITINT32 jump_offset, GList **labels, t_system *system,JITUINT32 inst_size, t_stack *stack, t_try_block *source_block, t_try_block *target_block, t_try_handler *source_handler, t_try_handler *target_handler);
191
static inline JITINT16 make_catcher_instructions(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary);
192
static inline JITINT16 make_catcher_initialization_instructions(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary);
193
static inline void make_blocks_instructions(t_system *system, Method method, GList *blocks , JITUINT32 *current_label_ID, JITUINT32 exit_label, JITUINT32 bytes_read , t_stack *stack, t_binary_information *binary);
194
static inline JITINT16 translate_icall (t_system *system, Method method, char *function_name, void *internal_native_function, JITUINT32 result, XanList *params, JITUINT32 bytes_read, t_binary_information * binary, JITUINT32 result_variable_ID, t_ir_instruction *before);
196
/* functions used to test exception conditions */
197
static inline JITUINT32 translate_Test_Null_Reference(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary);
198
static inline JITUINT32 translate_Test_Array_Type_Mismatch (t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, ILType *classLocated);
199
static inline JITUINT32 translate_Test_Array_Index_Out_Of_Range(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary);
200
static inline JITUINT32 translate_Test_OutOfMemory(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, t_ir_instruction *before);
201
static inline JITUINT32 translate_Test_Overflow(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary);
202
static inline JITUINT32 translate_Test_Type_Load_with_ClassLocated(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, ILType *classLocated);
203
static inline JITUINT32 translate_Test_Type_Load_with_Type_Token(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITUINT32 token);
204
static inline JITUINT32 translate_Test_Missing_Method(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITUINT32 token);
205
static inline JITUINT32 translate_Test_Method_Access(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, t_method *metadata_callee);
206
static inline JITUINT32 translate_Test_Invalid_Operation(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, t_method *ctor_metadata);
207
static inline JITUINT32 _translate_throw_CIL_Exception(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, ILClassID classID);
208
static inline JITUINT32 translate_Test_Missing_Field(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITUINT32 token);
209
static inline JITUINT32 translate_Test_Null_Reference_With_Static_Field_Check(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, ILFieldID fieldID);
210
static inline JITUINT32 translate_Test_Field_Access(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, ILField *fieldLocated);
211
static inline JITUINT32 translate_Test_Cast_Class(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITUINT32 token, JITBOOLEAN can_throw_exception);
212
static inline JITUINT32 translate_Test_Valid_Value_Address(t_system *system, Method method, CILStack cilStack, JITUINT32 *current_label_ID, GList **labels, JITUINT32 bytes_read, t_stack *stack, t_binary_information *binary, JITUINT32 type);
214
static inline void decode_cil_signature_to_ir_signature(t_system *system, Method ilMethod, ILMethod_signature *cil_signature, ir_method_t *ir_method, JITBOOLEAN isFormalSignature);
216
static inline JITINT32 internal_isStackCorrect (Method method, t_stack *stack);
219
* @brief This function translates a CIL method in a method written the IR language
221
* @param system The t_system variable describing the running system
222
* @param method The CIL method to be translated. It usually comes from a pipeline
223
* @param methodsToCall A pointer to an empty XanList. At the end, it will contain a list of the static constructors that will be called by the current method.
225
* @return If the given method was a native call, it returns the constant value NATIVE_CALL.
227
JITINT16 translate_method_from_cil_to_ir (t_system *system, Method method, XanList *methodsToCall){
228
t_binary_information *current_binary; /**< Binary where the method is */
229
t_row_param_table *param;
231
t_method *methodMetadata;
234
JITBOOLEAN are_more_sections;
235
JITUINT32 entry_point_address;
239
JITUINT32 size_header; /**< Number of bytes of the header */
242
JITINT32 isCilImplemented;
243
JITINT8 buffer[DIM_BUF];
246
JITINT8 *body_stream;
247
JITUINT32 current_label_ID;
248
JITBOOLEAN is_invalid_basic_block;
249
JITBOOLEAN localsInit;
250
JITUINT8 unaligned_prefix_value;
251
ir_method_t *irMethod;
254
If the unaligned_prefix_value is 0, no unaligned prefix has been found;
255
the next instruction works considering the default alignment to IRNUINT
256
If the unaligned prefix is found, it must have one of the value in 1, 2 or 4
257
and the next instruction must check for addresses to be aligned to the indicated value
261
assert(method != NULL);
262
assert(method->getBinary(method) != NULL);
263
assert(method->getName(method) != NULL);
264
PDEBUG("CILIR: Method to translate in IR language\n");
265
PDEBUG("CILIR: Binary = %s\n", method->getBinary(method)->name);
266
PDEBUG("CILIR: Name = %s\n", method->getName(method));
268
/* Init the variables */
269
current_binary = NULL;
275
are_more_sections = 0;
276
entry_point_address = 0;
282
current_label_ID = 0;
283
is_invalid_basic_block = 0;
285
unaligned_prefix_value = 0;
287
/* Lock the method */
288
// method->lock(method); XAN
290
/* Create the stack */
291
PDEBUG("CILIR: Make the CIL stack\n");
292
cilStack = newCILStack();
293
assert(cilStack != NULL);
294
stack = cilStack->newStack(cilStack);
295
assert(stack != NULL);
297
/* Fetch the binary */
298
current_binary = method->getBinary(method);
299
assert(current_binary != NULL);
301
/* Fetch the IR method */
302
irMethod = method->getIRMethod(method);
303
assert(irMethod != NULL);
305
/* Fetch the metadata */
306
methodMetadata = method->getMetadata(method);
307
assert(methodMetadata != NULL);
309
/* Lock the mutex of the binary */
310
pthread_mutex_lock(&((current_binary->binary).mutex));
312
/* Create the signature */
313
PDEBUG("CILIR: Create the signature\n");
314
error = createSignature (system, method, &entry_point_address, 0);
316
/* Check if the method is CIL *
318
isCilImplemented = method->isCilImplemented(method);
320
if (!isCilImplemented){
321
PDEBUG("CILIR: This method has not a body in CIL bytecode\n");
322
PDEBUG("CILIR: Exit\n");
323
pthread_mutex_unlock(&((current_binary->binary).mutex));
324
//method->unlock(method); XAN
326
} else if (error != 0){
327
print_err("CILIR: ERROR = During creating the signature. ", 0);
328
pthread_mutex_unlock(&((current_binary->binary).mutex));
332
/* Check if the jit function exist */
333
PDEBUG("CILIR: Check the existance of the JIT function of the method\n");
334
if (method->getJITFunction(method) == NULL){
335
PDEBUG("CILIR: The JIT function of the method not exist\n");
336
assert((method->jit_function).jit_signature != NULL);
337
method->setJITFunction(method, (system->IRVM).newLibjitMethod(&(system->IRVM), method, (method->jit_function).jit_signature));
338
assert(method->getJITFunction(method) != NULL);
339
PDEBUG("CILIR: The JIT function of the method is made\n");
341
PDEBUG("CILIR: The JIT function of the method exist\n");
344
/* print the IL-SIGNATURE */
346
PDEBUG("CILIR: IL-signature : %s\n", method->getCILSignature(method)->toString(system, method->getCILSignature(method), method->getName(method), JITTRUE) );
348
/* Fetch the paramaters */
349
if ((t_param_table *) get_table (&(current_binary->metadata.streams_metadata.not_stream.tables), PARAM_TABLE) == NULL) {
352
max_count = ((t_param_table *)get_table (&(current_binary->metadata.streams_metadata.not_stream.tables), PARAM_TABLE))->cardinality;
356
if (methodMetadata->method->param_list > max_count) {
357
PDEBUG("CILIR: No parameters\n");
359
PDEBUG("CILIR: Parameters\n");
361
for (count = methodMetadata->method->param_list; count <= max_count; count++){
362
param = ((t_method_def_table *)get_table (& (current_binary->metadata.streams_metadata.not_stream.tables) , METHOD_DEF_TABLE)) ->get_next_param(&(current_binary->metadata.streams_metadata) , methodMetadata->method, param);
365
name = get_string(&(current_binary->metadata.streams_metadata.string_stream), param->name);
366
PDEBUG("CILIR: Name = %s\n", name);
367
PDEBUG("CILIR: Flags = 0x%X\n", param->flags);
368
if (((param->flags) & 0x1) != 0){
369
PDEBUG("CILIR: Input\n");
371
if (((param->flags) & 0x2) == 0x2){
372
PDEBUG("CILIR: Output\n");
374
if (((param->flags) & 0x10) == 0x10){
375
PDEBUG("CILIR: Optional\n");
377
if (((param->flags) & 0x1000) == 0x1000){
378
PDEBUG("CILIR: Has default value\n");
380
if (((param->flags) & 0x2000) == 0x2000){
381
PDEBUG("CILIR: Has field marshal\n");
389
/* Seek to the begin of the file */
390
PDEBUG("CILIR: Unroll the file\n");
391
if (unroll_file( &(current_binary->binary) )!=0){
392
pthread_mutex_unlock(&((current_binary->binary).mutex));
393
//method->unlock(method); XAN
394
return NO_SEEK_POSSIBLE;
397
/* Seek to the entry point address */
398
PDEBUG("CILIR: Seek to the entry point\n");
399
if(seek_within_file(&(current_binary->binary), buffer, (current_binary->binary).offset, entry_point_address ) !=0 ) {
400
pthread_mutex_unlock(&((current_binary->binary).mutex));
401
//method->unlock(method); XAN
402
return NO_SEEK_POSSIBLE;
404
assert((current_binary->binary).offset == entry_point_address);
405
PDEBUG("CILIR: File offset= 0x%llX\n", (current_binary->binary).offset);
407
/* Decode the entry point address */
408
PDEBUG("CILIR: Read the first byte of the method header\n");
409
if (il_read(&first_byte, 1, &(current_binary->binary))!=0) {
410
pthread_mutex_unlock(&((current_binary->binary).mutex));
411
//method->unlock(method); XAN
414
PDEBUG("CILIR: File offset= 0x%llX\n", (current_binary->binary).offset);
416
/* Decode the method header */
417
method_type = (first_byte & 0x03);
418
if (method_type == 0x03) {
423
JITUINT32 local_var_sig_tok;
424
PDEBUG("CILIR: Fat method\n");
426
/* Alignment check */
427
pad = (entry_point_address % 4);
428
assert(pad == 0); // The fat header shall start on a 4 byte boundary
430
/* Reading 12 bytes, the fat header */
431
buffer[0] = first_byte;
432
if (il_read(buffer+1, 11, &(current_binary->binary)) != 0) {
433
pthread_mutex_unlock(&((current_binary->binary).mutex));
434
//method->unlock(method); XAN
435
return NO_READ_POSSIBLE;
437
PDEBUG("CILIR: Flags\n");
438
if ((buffer[0] & 0x8) == 0x8) {
439
PDEBUG("CILIR: More sections\n");
440
are_more_sections = 1;
442
PDEBUG("CILIR: There aren't more sections\n");
444
if ((buffer[0] & 0x10) == 0x10) {
445
PDEBUG("CILIR: Call default contructor on all local variables\n");
448
size = (JITUINT32) ((buffer[1] >> 0x4) & 0xF);
449
size_header = size * 4;
450
PDEBUG("CILIR: Size header = %d Bytes\n", size_header);
451
max_stack = (*(JITUINT16 *)(buffer+2));
452
PDEBUG("CILIR: Max stack = %d items\n", max_stack);
453
body_size = (*(JITUINT32 *)(buffer+4));
454
PDEBUG("CILIR: Body size = %d Bytes\n", body_size);
455
local_var_sig_tok = (*(JITUINT32 *)(buffer+8));
456
PDEBUG("CILIR: LocalVarSigTok = 0x%X\n", local_var_sig_tok);
458
/* Decode the local signature */
459
if (local_var_sig_tok != 0x0) {
460
PDEBUG("CILIR: Decode the signature of the local variables\n");
461
decode_locals_signature(system, local_var_sig_tok, current_binary, stack, method);
464
/* Decode the method data section */
465
if (are_more_sections == 1) {
466
/* Note that the function `decode_exceptions` doesn't modify the (method->MaxVariables) variable
467
* and doesn't modify the `stack` element. */
468
PDEBUG("CILIR: Decode the exceptions header\n");
469
decode_exceptions(system, cilStack, current_binary, body_size, &labels, ¤t_label_ID, method, stack);
471
} else if (method_type == 0x02){
473
PDEBUG("CILIR: Tiny method\n");
475
body_size = ((first_byte >> 0x2) & 0x3F);
476
PDEBUG("CILIR: Body size = %d\n", body_size);
478
snprintf((char *)buffer, sizeof(buffer), "CILIR: ERROR = Method type %d is not known. ", method_type);
479
print_err((char *)buffer, 0);
480
pthread_mutex_unlock(&((current_binary->binary).mutex));
483
assert(body_size > 0);
485
/* Set the type of each parameters */
486
for (count=0, IRParam=NOPARAM; count < method->threadUnsafe_getParametersNumber(method); count++){
487
stack->adjustSize(stack);
488
IRParam = *(method->getParameterInternalType(method, count));
489
assert(IRParam != NOPARAM);
490
(stack->stack[count]).value = count;
491
(stack->stack[count]).type = IROFFSET;
492
(stack->stack[count]).internal_type = IRParam;
493
if (IRParam == IRVALUETYPE || IRParam == IRTYPEDREF) {
494
ILType *current_value_type;
495
t_decoded_param *currentParam;
496
ILMethod_signature *CIL_method_signature;
498
/* Initialize the local variables */
499
current_value_type = NULL;
502
/* Fetch the CIL signature */
503
CIL_method_signature = method->getCILSignature(method);
504
assert(CIL_method_signature != NULL);
506
/* retrieve the current IL parameter informations */
507
if (method->threadUnsafe_getParametersNumber(method) > CIL_method_signature->param_count) {
510
assert(method->threadUnsafe_getParametersNumber(method) == (CIL_method_signature->param_count + 1));
511
assert((count - 1) >= 0);
513
currentParam = CIL_method_signature->params + (count - 1);
515
currentParam = CIL_method_signature->params + count;;
518
/* test the postconditions */
519
assert(currentParam != NULL);
521
if (IRParam == IRTYPEDREF ) {
523
assert(currentParam->is_typedRef);
524
assert(!currentParam->is_byref);
525
assert(currentParam->type == NULL);
526
assert(system->valueType_manager != NULL);
527
assert((system->valueType_manager)->get_System_TypedReference != NULL);
529
/* retrieve the metadata infos for System.TypedReference */
530
current_value_type = (system->valueType_manager)->get_System_TypedReference(system->valueType_manager);
532
/* retireve the decoded_type IL associated with the value-type */
534
assert(!currentParam->is_typedRef);
535
assert(currentParam->type != NULL);
536
assert((currentParam->type)->type_infos != NULL);
538
/* retrieve the ILType of the current valuetype */
539
current_value_type = (ILType *) (currentParam->type)->type_infos;
543
assert(current_value_type != NULL);
544
assert(current_value_type->ID != NULL);
545
assert(current_value_type->binary != NULL);
546
(stack->stack[count]).value_type_infos.isByref = currentParam->is_byref;
547
(stack->stack[count]).value_type_infos.type_infos = current_value_type;
550
assert((stack->stack[count]).value_type_infos.type_infos != NULL);
551
assert((stack->stack[count]).value_type_infos.type_infos->ID != NULL);
552
assert((stack->stack[count]).value_type_infos.type_infos->binary != NULL);
554
assert((stack->stack[count]).type == IROFFSET);
557
/* Translate the body */
558
PDEBUG("CILIR: Body\n");
559
JITBOOLEAN exit_condition;
560
JITUINT32 opcode_counter;
561
JITUINT32 bytes_read; /* Bytes read of the body */
562
JITUINT32 old_bytes_read; /* Bytes read of the body */
570
method->setMaxVariables(method, method->getLocalsNumber(method) + method->threadUnsafe_getParametersNumber(method));
571
stack->top = method->getMaxVariables(method);
573
PDEBUG("CILIR: Parameters number = %u\n", method->threadUnsafe_getParametersNumber(method));
574
PDEBUG("CILIR: Locals number = %u\n", method->getLocalsNumber(method));
575
PDEBUG("CILIR: Var count = %u\n", method->getMaxVariables(method));
576
PDEBUG("CILIR: Top of the stack = %u\n", stack->top);
577
PDEBUG("CILIR: Body File offset = 0x%llX\n", (current_binary->binary).offset);
578
print_stack(stack, method->threadUnsafe_getParametersNumber(method), method->getLocalsNumber(method));
581
/* Refresh the max variables */
582
refresh_max_variables(system, stack, method);
584
/* Before starting with the analysis of each CIL instruction, we have to insert an IRUSESCATCHER
585
* instruction in order to manage all the exceptional beehaviours that can occurr during the execution
586
* of the code. Note: It's not necessary that the current method owns protected blocks. Each method
587
* shall implements a sort of exception handling mechanism to catch all the possibiles exception_thrown */
588
translate_cil_uses_catcher(system, method, bytes_read);
590
/* Compute the root set */
591
for (count=0; count < (method->getLocalsNumber(method) + method->threadUnsafe_getParametersNumber(method)); count++){
592
stack->adjustSize(stack);
593
assert((stack->stack[count]).type == IROFFSET);
594
if ( ((stack->stack[count]).internal_type == IROBJECT) ||
595
((stack->stack[count]).internal_type == IRTPOINTER) ||
596
((stack->stack[count]).internal_type == IRUPOINTER) ||
597
((stack->stack[count]).internal_type == IRMPOINTER) ||
598
((stack->stack[count]).internal_type == IRTYPEDREF) ){
599
method->addVariableToRootSet(method, count, system);
603
/* Initialize the local variables */
604
for (count=method->threadUnsafe_getParametersNumber(method); count < method->getLocalsNumber(method) + method->threadUnsafe_getParametersNumber(method); count++){
605
if ((stack->stack[count]).internal_type != IRVALUETYPE){
606
t_ir_instruction *instruction;
610
instruction = method->newIRInstr(method);
611
instruction->type = IRSTORE;
612
instruction->byte_offset = 0;
613
memcpy(&(instruction->param_1), &(stack->stack[count]), sizeof(ir_item_t));
614
memcpy(&(instruction->param_2), &(stack->stack[count]), sizeof(ir_item_t));
615
(instruction->param_2).value = 0;
616
(instruction->param_2).type = (stack->stack[count]).internal_type;
617
(instruction->param_2).internal_type = (stack->stack[count]).internal_type;
619
switch ((stack->stack[count]).internal_type){
640
snprintf(buf, sizeof(char)*DIM_BUF, "CIL IR: ERROR = Type %d of the variable %d of the method %s is not known. ", (stack->stack[count]).internal_type, count - method->threadUnsafe_getParametersNumber(method), method->getName(method));
642
pthread_mutex_unlock(&((current_binary->binary).mutex));
649
/* Read the body of the method */
650
body_stream = allocFunction(body_size + 1);
651
if (il_read(body_stream, body_size, &(current_binary->binary))!=0) {
652
pthread_mutex_unlock(&((current_binary->binary).mutex));
653
//method->unlock(method); XAN
657
/* Unlock the mutex of the binary */
658
pthread_mutex_unlock(&((current_binary->binary).mutex));
660
/* Now, we are ready to start with the code translation from CIL to IR. */
661
while (!exit_condition){
664
t_ir_instruction *instruction;
666
ILType *stelem_class_located;
668
/* Initialize the variables */
669
stelem_class_located = NULL;
674
/* Remember the bytes read till now */
675
old_bytes_read = bytes_read;
677
/* Check if I have to insert a label */
679
label = fetch_label(labels, method->threadUnsafe_getInstructionsNumber(method));
681
if ( is_invalid_basic_block
682
&& (label->type == EXCEPTION_HANDLING_LABEL_TYPE)
683
&& (label->ending_handler == NULL)
684
&& (label->ending_block == NULL) ) {
685
labels = invalidate_blocks_starting_at_label(system, labels, label);
687
t_ir_instruction *labelInstruction;
688
PDEBUG("CILIR: Insert the label \"L%d\"\n", label->ID);
689
instruction = method->newIRInstr(method);
690
instruction->type = IRLABEL;
691
(instruction->param_1).value = label->ID;
692
(instruction->param_1).type = IRLABELITEM;
693
(instruction->param_1).internal_type = IRLABELITEM;
694
instruction->byte_offset = bytes_read;
695
label->ir_position = method->threadUnsafe_getInstructionsNumber(method) -1;
696
labelInstruction = instruction;
698
if (label->type == EXCEPTION_HANDLING_LABEL_TYPE){
699
PDEBUG("CILIR: We found the EXCEPTION_HANDLING label"
700
"\"L%d\"\n", label->ID);
702
assert( label->ending_block != NULL
703
|| label->ending_handler != NULL
704
|| label->starting_handler != NULL
705
|| label->starting_blocks != NULL);
707
if (label->ending_handler != NULL){
709
PDEBUG("CILIR: case_ending_handler \n");
710
assert((label->ending_handler)->owner_block != NULL);
711
if (label->starting_handler != NULL) {
712
assert ((label->starting_handler)->owner_block != NULL);
713
assert ((label->starting_handler)->owner_block == (label->starting_handler)->owner_block );
715
assert( ( (label->ending_handler)
717
->stack_to_restore != NULL);
719
PDEBUG("CILIR RESTORING THE STACK ...\n");
720
PDEBUG("CILIR: New stack [FROM THE"
721
"BLOCK[\"L%d\",\"L%d\"]]\n",
722
((label->ending_handler)->owner_block)
723
->try_start_label_ID,
724
((label->ending_handler)->owner_block)
726
print_stack( ((label->ending_handler)->owner_block)
728
method->threadUnsafe_getParametersNumber(method),
729
method->getLocalsNumber(method));
731
stack = ((label->ending_handler)->owner_block)->stack_to_restore;
733
/* the block is no longer invalid ... */
734
is_invalid_basic_block = 0;
735
PDEBUG("CILIR: STACK RESTORED!\n");
737
if ((label->ending_handler)->type != EXCEPTION_TYPE)
739
PDEBUG("CILIR: ENCOUNTERED THE END OF A NOT"
740
"EXCEPTION_TYPE HANDLER. IT'S NECESSARY TO UPDATE"
741
"THE DATAFLOW INFORMATIONS...\n");
742
JITUINT32 endFinally_Or_Filter_Posn;
743
t_ir_instruction *endFinally_Or_Filter_Inst;
745
endFinally_Or_Filter_Posn = method->threadUnsafe_getInstructionsNumber(method) - 2;
746
PDEBUG("endFinally_Or_Filter_Posn = %d \n" , endFinally_Or_Filter_Posn);
747
irMethod->lock(irMethod);
748
endFinally_Or_Filter_Inst = irMethod->getInstructionAt(irMethod, endFinally_Or_Filter_Posn);
749
irMethod->unlock(irMethod);
751
PDEBUG("CILIR: LAST INSTRUCTION OF THE HANDLER WAS A %d \n"
752
, (endFinally_Or_Filter_Inst->type));
753
assert( endFinally_Or_Filter_Inst->type == IRENDFILTER
754
|| endFinally_Or_Filter_Inst
755
->type == IRENDFINALLY);
757
(label->ending_handler)->end_filter_or_finally_inst
758
= endFinally_Or_Filter_Inst;
761
/* WE HAVE TO VERIFY IF IT'S NECESSARY TO RESTORE AN OLD STACK
763
if (label->ending_block != NULL){
765
PDEBUG("CILIR: case_ending_block \n");
766
if (label->starting_handler != NULL){
767
assert ((label->starting_handler)->owner_block
770
, (label->starting_handler)->owner_block
771
, label->ending_block);
772
assert ((label->starting_handler)->owner_block
773
== label->ending_block );
775
assert((label->ending_block)->stack_to_restore != NULL);
776
PDEBUG("CILIR RESTORING THE STACK ...\n");
777
PDEBUG("CILIR: New stack [FROM THE"
778
"BLOCK[\"L%d\",\"L%d\"]]\n"
779
, (label->ending_block)->try_start_label_ID
780
, (label->ending_block)->try_end_label_ID);
781
print_stack((label->ending_block)->stack_to_restore
782
, method->threadUnsafe_getParametersNumber(method)
783
, method->getLocalsNumber(method));
785
stack = (label->ending_block)->stack_to_restore;
786
/* the block is no longer invalid ... */
787
is_invalid_basic_block = 0;
788
PDEBUG("CILIR STACK RESTORED!\n");
790
if (label->starting_handler != NULL){
792
PDEBUG("CILIR: case_starting_handler \n");
793
assert((label->starting_handler)->owner_block != NULL);
794
if (label->ending_block != NULL)
796
PDEBUG("%p %p \n", label->ending_block
797
, (label->starting_handler)
799
assert(label->ending_block
800
== (label->starting_handler)
803
PDEBUG("CILIR: New stack [FROM THE"
804
"BLOCK[\"L%d\",\"L%d\"]]\n"
805
, ((label->starting_handler)
806
->owner_block)->try_start_label_ID
807
, ((label->starting_handler)
808
->owner_block)->try_end_label_ID);
809
PDEBUG("CILIR: owner_block == %p \n"
810
, (label->starting_handler)
812
assert( ( (label->starting_handler)
814
->stack_to_restore != NULL);
816
PDEBUG("CILIR RESTORING THE STACK ...\n");
819
/* FETCH THE CORRECT STACK FROM THE PARENT PROTECTED BLOCK */
820
stack = ((label->starting_handler)->owner_block)
822
/* the block is no longer invalid ... */
823
is_invalid_basic_block = 0;
825
if ((label->starting_handler)->type != FINALLY_TYPE){
827
/* Clean the top of the stack */
828
stack->cleanTop(stack);
830
/* An exception object describing the
831
* specific exceptional behaviour detected
832
* is pushed onto the evaluation stack as the first
833
* item upon entry of a filter or catch clause */
834
PDEBUG("CILIR: Insert a IR instruction\n");
835
instruction = method->newIRInstr(method);
836
instruction->type = IRTHROWNEXCEPTIONOBJECT;
837
stack->stack[stack->top].value = method->getMaxVariables(method);
838
stack->stack[stack->top].type = IROFFSET;
839
stack->stack[stack->top].internal_type = IROBJECT;
840
(instruction->result).value = (stack->stack[stack->top]).value;
841
(instruction->result).type = (stack->stack[stack->top]).type;
842
(instruction->result).internal_type = (stack->stack[stack->top]).internal_type;
844
method->increaseMaxVariables(method);
845
instruction->byte_offset = bytes_read;
848
/* Print the stack */
850
PDEBUG("CILIR: New stack [FROM BLOCK[\"L%d\",\"L%d\"]]\n",
851
((label->starting_handler)->owner_block)
852
->try_start_label_ID,
853
((label->starting_handler)->owner_block)
856
print_stack(((label->starting_handler)
857
->owner_block)->stack_to_restore,
858
method->threadUnsafe_getParametersNumber(method),
859
method->getLocalsNumber(method));
860
PDEBUG("CILIR STACK RESTORED!\n");
863
if ((label->starting_handler)->type == FILTER_TYPE) {
865
/* Clean the top of the stack */
866
stack->cleanTop(stack);
868
/* ADD A START-FILTER INSTRUCTION */
869
PDEBUG("CILIR: ADD_LABEL_INS : START_FILTER_TYPE\n");
870
instruction = method->newIRInstr(method);
871
instruction->type = IRSTARTFILTER;
872
(instruction->param_1).value = label->ID;
873
(instruction->param_1).type = IRLABELITEM;
874
(instruction->param_1).internal_type = IRLABELITEM;
875
stack->stack[stack->top].value = method->getMaxVariables(method);
876
stack->stack[stack->top].type = IROFFSET;
877
stack->stack[stack->top].internal_type = IROBJECT;
878
(instruction->result).value = stack->stack[stack->top].value;
879
(instruction->result).type = (stack->stack[stack->top]).type;
880
(instruction->result).internal_type = stack->stack[stack->top].internal_type;
882
method->increaseMaxVariables(method);
883
instruction->byte_offset = bytes_read;
885
} else if ((label->starting_handler)->type == FINALLY_TYPE) {
887
/* ADD A START-FINALLY INSTRUCTION */
888
PDEBUG("CILIR: ADD_LABEL_INS : START_FINALLY_TYPE\n");
889
instruction = method->newIRInstr(method);
890
instruction->type = IRSTARTFINALLY;
891
(instruction->param_1).value = label->ID;
892
(instruction->param_1).type = IRLABELITEM;
893
(instruction->param_1).internal_type = IRLABELITEM;
894
instruction->byte_offset = bytes_read;
898
/* ONCE RESTORED THE CORRECT IMAGE, WE MUST VERIFY IF THERE ARE
899
* PROTECTED BLOCKS THAT START AT THIS CIL-ADDRESS */
900
if (label->starting_blocks != NULL)
902
PDEBUG("CILIR: case_starting_block \n");
903
GList *current_block;
904
t_try_block *current_try_block;
907
assert(g_list_length(label->starting_blocks) != 0);
909
/* initialize the current element */
910
current_block = g_list_first(label->starting_blocks);
912
while(current_block != NULL)
914
/* update the stack element for the current_block */
915
current_try_block = (t_try_block *) current_block->data;
916
assert(current_try_block->stack_to_restore == NULL);
918
/* Print the stack */
920
PDEBUG("CILIR: copying the current stack into the block structure\n");
922
method->threadUnsafe_getParametersNumber(method),
923
method->getLocalsNumber(method));
926
current_try_block->stack_to_restore = cilStack->cloneStack(cilStack, stack);
927
current_block = g_list_next(current_block);
931
PDEBUG("CILIR CASE : DEFAULT_LABEL_TYPE \n");
932
PDEBUG("CILIR UPDATING THE STACK... \n");
933
/* CASE : DEFAULT_LABEL_TYPE */
934
/* THIS LABEL IS NOT USED FOR THE EXCEPTION HANDLING MECHANISM.
935
* WE EXPECT THAT THE CORRECT VALUE OF stack IS STORED INTO
936
* THE label->stack FIELD. */
938
/* Print the stack */
940
PDEBUG("CILIR New stack: \n");
941
print_stack(label->stack, method->threadUnsafe_getParametersNumber(method), method->getLocalsNumber(method));
942
assert(label->stack);
945
/* Merge the stack */
946
stack = cilStack->mergeStackes(cilStack, stack, label->stack, method, labelInstruction);
947
assert(stack != NULL);
949
/* the block is no longer invalid ... */
950
is_invalid_basic_block = 0;
954
PDEBUG("NO LABEL FOUND AT offset-CIL %d\n", bytes_read);
958
/* Set the second byte of the opcode to zero */
961
/* Read OPCODE of the next instruction */
962
opcode[0] = body_stream[bytes_read];
966
/* Adjust the size of the stack */
967
stack->adjustSize(stack);
969
switch ((JITUINT16)opcode[0]){
971
PDEBUG("CILIR:<CIL Inst %d> nop\n", opcode_counter);
974
PDEBUG("CILIR:<CIL Inst %d> break\n", opcode_counter);
975
if (is_invalid_basic_block == 1) break;
976
print_err("CILIR: break instruction is not implemented. ", 0);
980
PDEBUG("CILIR:<CIL Inst %d> ldarg.0\n", opcode_counter);
981
if (is_invalid_basic_block == 1) break;
982
is_invalid_basic_block = translate_cil_ldarg (system, method, bytes_read, 0, stack);
985
PDEBUG("CILIR:<CIL Inst %d> ldarg.1\n", opcode_counter);
986
if (is_invalid_basic_block == 1) break;
987
is_invalid_basic_block = translate_cil_ldarg (system, method , bytes_read, 1, stack);
990
PDEBUG("CILIR:<CIL Inst %d> ldarg.2\n", opcode_counter);
991
if (is_invalid_basic_block == 1) break;
992
is_invalid_basic_block = translate_cil_ldarg (system, method, bytes_read, 2, stack);
995
PDEBUG("CILIR:<CIL Inst %d> ldarg.3\n", opcode_counter);
996
if (is_invalid_basic_block == 1) break;
997
is_invalid_basic_block = translate_cil_ldarg (system, method, bytes_read, 3, stack);
1000
PDEBUG("CILIR:<CIL Inst %d> ldloc.0\n", opcode_counter);
1001
if (is_invalid_basic_block == 1) break;
1002
is_invalid_basic_block = translate_cil_ldloc (system, method, bytes_read, 0, stack);
1004
case LDLOC_1_OPCODE:
1005
PDEBUG("CILIR:<CIL Inst %d> ldloc.1\n", opcode_counter);
1006
if (is_invalid_basic_block == 1) break;
1007
is_invalid_basic_block = translate_cil_ldloc (system, method, bytes_read, 1, stack);
1009
case LDLOC_2_OPCODE:
1010
PDEBUG("CILIR:<CIL Inst %d> ldloc.2\n", opcode_counter);
1011
if (is_invalid_basic_block == 1) break;
1012
is_invalid_basic_block = translate_cil_ldloc (system, method, bytes_read, 2, stack);
1014
case LDLOC_3_OPCODE:
1015
PDEBUG("CILIR:<CIL Inst %d> ldloc.3\n", opcode_counter);
1016
if (is_invalid_basic_block == 1) break;
1017
is_invalid_basic_block = translate_cil_ldloc (system, method, bytes_read, 3, stack);
1019
case STLOC_0_OPCODE:
1020
PDEBUG("CILIR:<CIL Inst %d> stloc.0\n", opcode_counter);
1021
if (is_invalid_basic_block == 1) break;
1022
is_invalid_basic_block = translate_cil_stloc(system, method, bytes_read, 0, stack);
1024
case STLOC_1_OPCODE:
1025
PDEBUG("CILIR:<CIL Inst %d> stloc.1\n", opcode_counter);
1026
if (is_invalid_basic_block == 1) break;
1027
is_invalid_basic_block = translate_cil_stloc (system, method, bytes_read, 1, stack);
1029
case STLOC_2_OPCODE:
1030
PDEBUG("CILIR:<CIL Inst %d> stloc.2\n", opcode_counter);
1031
if (is_invalid_basic_block == 1) break;
1032
is_invalid_basic_block = translate_cil_stloc (system, method, bytes_read, 2, stack);
1034
case STLOC_3_OPCODE:
1035
PDEBUG("CILIR:<CIL Inst %d> stloc.3\n", opcode_counter);
1036
if (is_invalid_basic_block == 1) break;
1037
is_invalid_basic_block = translate_cil_stloc (system, method, bytes_read, 3, stack);
1039
case LDARG_S_OPCODE:
1040
memcpy(buffer, body_stream + bytes_read, 1);
1042
PDEBUG("CILIR:<CIL Inst %d> ldarg.s %d\n", opcode_counter, buffer[0]);
1043
if (is_invalid_basic_block == 1) break;
1044
is_invalid_basic_block = translate_cil_ldarg(system, method, bytes_read, (JITUINT8) buffer[0], stack);
1046
case LDARGA_S_OPCODE:
1047
memcpy(buffer, body_stream + bytes_read, 1);
1049
PDEBUG("CILIR:<CIL Inst %d> ldarga.s 0x%X\n", opcode_counter, buffer[0]);
1050
if (is_invalid_basic_block == 1) break;
1051
is_invalid_basic_block = translate_cil_ldarga (system, method, bytes_read, (JITUINT8)buffer[0], stack);
1053
case STARG_S_OPCODE:
1054
memcpy(buffer, body_stream + bytes_read, 1);
1056
PDEBUG("CILIR:<CIL Inst %d> starg.s %d\n", opcode_counter, buffer[0]);
1057
if (is_invalid_basic_block == 1) break;
1058
is_invalid_basic_block = translate_cil_starg(system, method, bytes_read, (JITUINT8)buffer[0], stack);
1060
case LDLOC_S_OPCODE:
1061
memcpy(buffer, body_stream + bytes_read, 1);
1063
PDEBUG("CILIR:<CIL Inst %d> ldloc.s %d\n", opcode_counter, buffer[0]);
1064
if (is_invalid_basic_block == 1) break;
1065
is_invalid_basic_block = translate_cil_ldloc (system, method, bytes_read , (JITUINT8)buffer[0], stack);
1067
case LDLOCA_S_OPCODE:
1068
memcpy(buffer, body_stream + bytes_read, 1);
1070
PDEBUG("CILIR:<CIL Inst %d> ldloca.s 0x%X\n" , opcode_counter, buffer[0]);
1071
if (is_invalid_basic_block == 1) break;
1072
is_invalid_basic_block = translate_cil_ldloca (system, method, bytes_read , (JITUINT8)buffer[0], stack, localsInit, ¤t_label_ID , &labels, current_binary);
1074
case STLOC_S_OPCODE:
1075
memcpy(buffer, body_stream + bytes_read, 1);
1077
PDEBUG("CILIR:<CIL Inst %d> stloc.s %d\n", opcode_counter, buffer[0]);
1078
if (is_invalid_basic_block == 1) break;
1079
is_invalid_basic_block = translate_cil_stloc (system, method, bytes_read, (JITUINT8) buffer[0], stack);
1082
PDEBUG("CILIR:<CIL Inst %d> ldnull\n", opcode_counter);
1083
if (is_invalid_basic_block == 1) break;
1084
is_invalid_basic_block = translate_cil_ldnull(system, method, bytes_read, stack);
1086
case LDC_I4_M1_OPCODE:
1087
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.M1\n", opcode_counter);
1088
if (is_invalid_basic_block == 1) break;
1089
is_invalid_basic_block = translate_cil_load_constant(system, method, bytes_read, (JITINT32)-1, IRINT32, stack);
1091
case LDC_I4_0_OPCODE:
1092
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.0\n", opcode_counter);
1093
if (is_invalid_basic_block == 1) break;
1094
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)0, IRINT32, stack);
1096
case LDC_I4_1_OPCODE:
1097
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.1\n", opcode_counter);
1098
if (is_invalid_basic_block == 1) break;
1099
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)1, IRINT32, stack);
1101
case LDC_I4_2_OPCODE:
1102
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.2\n", opcode_counter);
1103
if (is_invalid_basic_block == 1) break;
1104
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)2, IRINT32, stack);
1106
case LDC_I4_3_OPCODE:
1107
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.3\n", opcode_counter);
1108
if (is_invalid_basic_block == 1) break;
1109
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)3, IRINT32, stack);
1111
case LDC_I4_4_OPCODE:
1112
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.4\n", opcode_counter);
1113
if (is_invalid_basic_block == 1) break;
1114
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)4, IRINT32, stack);
1116
case LDC_I4_5_OPCODE:
1117
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.5\n", opcode_counter);
1118
if (is_invalid_basic_block == 1) break;
1119
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)5, IRINT32, stack);
1121
case LDC_I4_6_OPCODE:
1122
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.6\n", opcode_counter);
1123
if (is_invalid_basic_block == 1) break;
1124
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)6, IRINT32, stack);
1126
case LDC_I4_7_OPCODE:
1127
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.7\n", opcode_counter);
1128
if (is_invalid_basic_block == 1) break;
1129
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)7, IRINT32, stack);
1131
case LDC_I4_8_OPCODE:
1132
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.8\n", opcode_counter);
1133
if (is_invalid_basic_block == 1) break;
1134
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)8, IRINT32, stack);
1136
case LDC_I4_S_OPCODE:
1137
memcpy(buffer, body_stream + bytes_read, 1);
1139
PDEBUG("CILIR:<CIL Inst %d> ldc.i4.s %d\n", opcode_counter, (JITINT8) buffer[0]);
1140
if (is_invalid_basic_block == 1) break;
1141
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32) ((JITINT8) buffer[0]), IRINT32, stack);
1144
memcpy(buffer, body_stream + bytes_read, 4);
1146
PDEBUG("CILIR:<CIL Inst %d> ldc.i4 %d\n", opcode_counter, *((JITINT32 *)buffer));
1147
if (is_invalid_basic_block == 1)
1149
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, (JITINT32)*((JITINT32 *) buffer), IRINT32, stack);
1152
memcpy(buffer, body_stream + bytes_read, 8);
1154
PDEBUG("CILIR:<CIL Inst %d> ldc.i8 %lld\n", opcode_counter, *((JITINT64 *)buffer));
1155
if (is_invalid_basic_block == 1) break;
1156
is_invalid_basic_block = translate_cil_load_constant (system, method, bytes_read, *((JITINT64*) buffer), IRINT64, stack);
1159
memcpy(buffer, body_stream + bytes_read, 4);
1161
PDEBUG("CILIR:<CIL Inst %d> ldc.r4 %f\n", opcode_counter, *((JITFLOAT32 *)buffer));
1162
if (is_invalid_basic_block == 1) break;
1163
is_invalid_basic_block = translate_cil_load_fconstant (system, method, bytes_read, *((JITFLOAT32 *) buffer), IRFLOAT32, stack);
1166
memcpy(buffer, body_stream + bytes_read, 8);
1168
PDEBUG("CILIR:<CIL Inst %d> ldc.r8 %.8f\n", opcode_counter, *((JITFLOAT64 *)buffer));
1169
if (is_invalid_basic_block == 1) break;
1170
is_invalid_basic_block = translate_cil_load_fconstant (system, method, bytes_read, *((JITFLOAT64 *) buffer), IRFLOAT64, stack);
1173
PDEBUG("CILIR:<CIL Inst %d> dup\n", opcode_counter);
1174
if (is_invalid_basic_block == 1) break;
1175
is_invalid_basic_block = translate_cil_dup (system, current_binary, method, bytes_read, stack);
1178
PDEBUG("CILIR:<CIL Inst %d> pop at %d\n", opcode_counter, bytes_read);
1181
case JMP_OPCODE: //FIXME todo
1182
memcpy(&new_token, body_stream + bytes_read, 4);
1184
PDEBUG("CILIR:<CIL Inst %d> jmp 0x%X\n", opcode_counter, new_token);
1185
if (is_invalid_basic_block == 1) break;
1186
print_err("CILIR: jmp instruction is not implemented. ", 0);
1190
memcpy(&new_token, body_stream + bytes_read, 4);
1192
PDEBUG("CILIR:<CIL Inst %d> call 0x%X\n", opcode_counter, new_token);
1193
if (is_invalid_basic_block == 1) break;
1194
is_invalid_basic_block = translate_cil_call(system, cilStack, current_binary, method, new_token, bytes_read, stack, 0, ¤t_label_ID, &labels, 0, methodsToCall);
1197
memcpy(&new_token, body_stream + bytes_read, 4);
1199
PDEBUG("CILIR:<CIL Inst %d> calli 0x%X\n", opcode_counter, new_token);
1200
if (is_invalid_basic_block == 1) break;
1201
is_invalid_basic_block = translate_cil_calli(system, cilStack, current_binary, method, new_token, bytes_read, stack, JITFALSE, ¤t_label_ID, &labels);
1204
PDEBUG("CILIR:<CIL Inst %d> Ret\n", opcode_counter);
1205
if (is_invalid_basic_block == 1) break;
1206
instruction = method->newIRInstr(method);
1207
instruction->type = IRRET;
1208
if (*(method->getResultType(method)) != IRVOID){
1209
(instruction->param_1).value = (stack->stack[(stack->top) - 1]).value;
1210
(instruction->param_1).fvalue = (stack->stack[(stack->top) - 1]).fvalue;
1211
(instruction->param_1).type = (stack->stack[(stack->top) - 1]).type;
1212
(instruction->param_1).internal_type = (stack->stack[(stack->top) - 1]).internal_type;
1213
make_ir_infos(&(instruction->param_1), &(stack->stack[(stack->top) -1]));
1216
instruction->byte_offset = bytes_read;
1217
PDEBUG("CILIR: Insert a IR instruction\n");
1220
memcpy(buffer, body_stream + bytes_read, 1);
1222
PDEBUG("CILIR:<CIL Inst %d> br.s %d\n", opcode_counter, buffer[0]);
1223
if (is_invalid_basic_block == 1) break;
1224
is_invalid_basic_block = translate_cil_branch(system, method, cilStack, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack);
1226
case BRFALSE_S_OPCODE:
1227
memcpy(buffer, body_stream + bytes_read, 1);
1229
PDEBUG("CILIR:<CIL Inst %d> brfalse.s %d\n", opcode_counter, buffer[0]);
1230
if (is_invalid_basic_block == 1) break;
1231
is_invalid_basic_block = translate_cil_brfalse(system, method, cilStack, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack);
1233
case BRTRUE_S_OPCODE:
1234
memcpy(buffer, body_stream + bytes_read, 1);
1236
PDEBUG("CILIR:<CIL Inst %d> brtrue.s %d\n", opcode_counter, buffer[0]);
1237
if (is_invalid_basic_block == 1) break;
1238
is_invalid_basic_block = translate_cil_brtrue(system, method, cilStack, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack);
1241
memcpy(buffer, body_stream + bytes_read, 1);
1243
PDEBUG("CILIR:<CIL Inst %d> beq.s %d\n", opcode_counter, buffer[0]);
1244
if (is_invalid_basic_block == 1) break;
1245
is_invalid_basic_block = translate_cil_beq(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack);
1248
memcpy(buffer, body_stream + bytes_read, 1);
1250
PDEBUG("CILIR:<CIL Inst %d> bge.s %d\n", opcode_counter, buffer[0]);
1251
if (is_invalid_basic_block == 1) break;
1252
is_invalid_basic_block = translate_cil_bge (system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack, 0);
1255
memcpy(buffer, body_stream + bytes_read, 1);
1257
PDEBUG("CILIR:<CIL Inst %d> bgt.s %d\n", opcode_counter, buffer[0]);
1258
if (is_invalid_basic_block == 1) break;
1259
is_invalid_basic_block = translate_cil_bgt(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack, 0);
1262
memcpy(buffer, body_stream + bytes_read, 1);
1264
PDEBUG("CILIR:<CIL Inst %d> ble.s %d\n", opcode_counter, buffer[0]);
1265
if (is_invalid_basic_block == 1) break;
1266
is_invalid_basic_block = translate_cil_ble(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack, 0);
1269
memcpy(buffer, body_stream + bytes_read, 1);
1271
PDEBUG("CILIR:<CIL Inst %d> blt.s %d\n", opcode_counter, buffer[0]);
1272
if (is_invalid_basic_block == 1) break;
1273
is_invalid_basic_block = translate_cil_blt(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack, 0);
1275
case BNE_UN_S_OPCODE:
1276
memcpy(buffer, body_stream + bytes_read, 1);
1278
address = buffer[0];
1279
PDEBUG("CILIR:<CIL Inst %d> bne.un.s %d\n", opcode_counter, address);
1280
if (is_invalid_basic_block == 1) break;
1281
is_invalid_basic_block = translate_cil_bneq(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, address, &labels, 2, stack);
1283
case BGE_UN_S_OPCODE:
1284
memcpy(buffer, body_stream + bytes_read, 1);
1286
PDEBUG("CILIR:<CIL Inst %d> bge.un.s %d\n", opcode_counter, buffer[0]);
1287
if (is_invalid_basic_block == 1) break;
1288
is_invalid_basic_block = translate_cil_bge (system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack, 1);
1290
case BGT_UN_S_OPCODE:
1291
PDEBUG("CILIR:<CIL Inst %d> bgt.un.s\n", opcode_counter);
1292
memcpy(buffer, body_stream + bytes_read, 1);
1294
if (is_invalid_basic_block == 1) break;
1295
is_invalid_basic_block = translate_cil_bgt(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack, 1);
1298
case BLE_UN_S_OPCODE:
1299
memcpy(buffer, body_stream + bytes_read, 1);
1301
PDEBUG("CILIR:<CIL Inst %d> ble.un.s %d\n", opcode_counter, buffer[0]);
1302
if (is_invalid_basic_block == 1) break;
1303
is_invalid_basic_block = translate_cil_ble(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack, 1);
1305
case BLT_UN_S_OPCODE:
1306
memcpy(buffer, body_stream + bytes_read, 1);
1308
PDEBUG("CILIR:<CIL Inst %d> blt.un.s %d\n", opcode_counter, buffer[0]);
1309
if (is_invalid_basic_block == 1) break;
1310
is_invalid_basic_block = translate_cil_blt(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, 2, stack, 1);
1313
memcpy(buffer, body_stream + bytes_read, 4);
1315
PDEBUG("CILIR:<CIL Inst %d> br %d\n", opcode_counter, *((JITINT32 *)buffer));
1316
if (is_invalid_basic_block == 1) break;
1317
is_invalid_basic_block = translate_cil_branch(system, method, cilStack, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack);
1319
case BRFALSE_OPCODE:
1320
memcpy(buffer, body_stream + bytes_read, 4);
1322
PDEBUG("CILIR:<CIL Inst %d> brfalse %d\n", opcode_counter, *((JITINT32 *)buffer));
1323
if (is_invalid_basic_block == 1) break;
1324
is_invalid_basic_block = translate_cil_brfalse(system, method, cilStack, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack);
1327
memcpy(buffer, body_stream + bytes_read, 4);
1329
PDEBUG("CILIR:<CIL Inst %d> brinst | brtrue %d\n", opcode_counter, *((JITINT32 *)buffer));
1330
if (is_invalid_basic_block == 1) break;
1331
is_invalid_basic_block = translate_cil_brtrue(system, method, cilStack, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack);
1334
memcpy(buffer, body_stream + bytes_read, 4);
1336
PDEBUG("CILIR:<CIL Inst %d> beq %d\n", opcode_counter, *((JITINT32 *)buffer));
1337
if (is_invalid_basic_block == 1) break;
1338
is_invalid_basic_block = translate_cil_beq(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack);
1341
memcpy(buffer, body_stream + bytes_read, 4);
1343
PDEBUG("CILIR:<CIL Inst %d> bge %d\n", opcode_counter, *((JITINT32 *)buffer));
1344
if (is_invalid_basic_block == 1) break;
1345
is_invalid_basic_block = translate_cil_bge (system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack, 0);
1348
memcpy(buffer, body_stream + bytes_read, 4);
1350
PDEBUG("CILIR:<CIL Inst %d> bgt %d\n", opcode_counter, *((JITINT32 *)buffer));
1351
if (is_invalid_basic_block == 1) break;
1352
is_invalid_basic_block = translate_cil_bgt(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack, 0);
1355
memcpy(buffer, body_stream + bytes_read, 4);
1357
PDEBUG("CILIR:<CIL Inst %d> ble %d\n", opcode_counter, *((JITINT32 *)buffer));
1358
if (is_invalid_basic_block == 1) break;
1359
is_invalid_basic_block = translate_cil_ble(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack, 0);
1362
memcpy(buffer, body_stream + bytes_read, 4);
1364
PDEBUG("CILIR:<CIL Inst %d> blt %d\n", opcode_counter, *((JITINT32 *)buffer));
1365
if (is_invalid_basic_block == 1) break;
1366
is_invalid_basic_block = translate_cil_blt(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack, 0);
1369
memcpy(buffer, body_stream + bytes_read, 4);
1371
address = *(JITUINT32 *)(buffer);
1372
PDEBUG("CILIR:<CIL Inst %d> bne.un %d\n", opcode_counter, address);
1373
if (is_invalid_basic_block == 1) break;
1374
is_invalid_basic_block = translate_cil_bneq (system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, address, &labels, 5, stack);
1377
memcpy(buffer, body_stream + bytes_read, 4);
1379
PDEBUG("CILIR:<CIL Inst %d> bge.un %d\n", opcode_counter, *((JITUINT32 *)buffer));
1380
if (is_invalid_basic_block == 1) break;
1381
is_invalid_basic_block = translate_cil_bge (system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack, 1);
1384
memcpy(buffer, body_stream + bytes_read, 4);
1386
PDEBUG("CILIR:<CIL Inst %d> bgt.un %d\n", opcode_counter, *((JITUINT32 *)buffer));
1387
if (is_invalid_basic_block == 1) break;
1388
is_invalid_basic_block = translate_cil_bgt(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack, 1);
1391
memcpy(buffer, body_stream + bytes_read, 4);
1393
PDEBUG("CILIR:<CIL Inst %d> ble.un %d\n", opcode_counter, *((JITUINT32 *)buffer));
1394
if (is_invalid_basic_block == 1) break;
1395
is_invalid_basic_block = translate_cil_ble(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack, 1);
1398
memcpy(buffer, body_stream + bytes_read, 4);
1400
PDEBUG("CILIR:<CIL Inst %d> blt.un %d\n", opcode_counter, *((JITUINT32 *)buffer));
1401
if (is_invalid_basic_block == 1) break;
1402
is_invalid_basic_block = translate_cil_blt(system, cilStack, current_binary, method, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, 5, stack, 1);
1406
Refer to page 424 of ECMA-335 4th edition, June 2006
1408
When we enter this clause, body_stream + bytes_read points to the number of targets the jump table contains;
1409
the element on the top of the stack is the value discriminating when we need to jump to the target.
1410
Once we retrieved the number of targers, we setup a for loop to execute the confront to each target within the jump table.
1411
if value is less than the current target iterator, the jump takes place.
1413
PDEBUG("CILIR:<CIL Inst %d> switch\n", opcode_counter);
1414
/* The element on top of the stack representing the value to confront */
1415
ir_item_t switch_value;
1416
/* The number of targets within the jump table */
1417
JITUINT32 switch_num_targets;
1418
/* The current target being considered */
1419
JITINT32 switch_current_tgt;
1420
JITUINT32 switch_instruction_size;
1421
JITUINT32 from_offset;
1424
/* Retrieving the number of targets within the jump table */
1425
switch_num_targets = *((JITUINT32 *) (body_stream + bytes_read) );
1427
PDEBUG("CILIR: The switch jump table contains %u targets\n", switch_num_targets);
1429
/* Retrieving the instruction size */
1430
switch_instruction_size = (5 + (switch_num_targets * 4));
1431
from_offset = bytes_read + (switch_num_targets * 4);
1433
/* Popping the value on top of the stack */
1434
PDEBUG("CILIR: %d elements on the stack so far\n", (stack->top) );
1435
switch_value.value = (stack->stack[(stack->top) - 1]).value;
1436
switch_value.fvalue = (stack->stack[(stack->top) - 1]).fvalue;
1437
switch_value.type = (stack->stack[(stack->top) - 1]).type;
1438
switch_value.internal_type = (stack->stack[(stack->top) - 1]).internal_type;
1440
PDEBUG("CILIR: The switch value value is %llu\n", switch_value.value);
1441
PDEBUG("CILIR: The switch value fvalue is %f\n", switch_value.fvalue);
1442
PDEBUG("CILIR: The switch value type is %u\n", switch_value.type);
1443
PDEBUG("CILIR: The switch value internal type is %u\n", switch_value.internal_type);
1444
PDEBUG("CILIR: one element popped from the stack, %d elements remaining\n", (stack->top) );
1445
/* Looping over the jump table */
1446
for(count=0; count<switch_num_targets; count=count+1) {
1447
/* Retrieving the current target from the jump table */
1448
switch_current_tgt = *((JITINT32 *) (body_stream + bytes_read) );
1450
PDEBUG("CILIR: Considering target %u, offset %d\n", count, switch_current_tgt);
1452
We have to push the two elements for the confront on the stack
1453
The check MUST be performed considering the parameters to be 32 bit UNSIGNED INTEGERs
1456
/* Clean the top of the stack */
1457
stack->cleanTop(stack);
1459
/* Pushing the value */
1460
(stack->stack[stack->top]).value = switch_value.value;
1461
(stack->stack[stack->top]).fvalue = switch_value.fvalue;
1462
(stack->stack[stack->top]).type = switch_value.type; //IRUINT32;
1463
(stack->stack[stack->top]).internal_type= switch_value.internal_type; //IRUINT32;
1466
/* Clean the top of the stack */
1467
stack->cleanTop(stack);
1469
/* Pushing the target iterator */
1470
(stack->stack[stack->top]).value = count;
1471
(stack->stack[stack->top]).fvalue = 0;
1472
(stack->stack[stack->top]).type = IRUINT32;
1473
(stack->stack[stack->top]).internal_type= IRUINT32;
1475
PDEBUG("CILIR: done with the stack, translating...\n");
1476
/* Translating the confront: we provide the target as the offset to jump to */
1477
is_invalid_basic_block = translate_cil_ble(system, cilStack, current_binary, method, ¤t_label_ID, from_offset, switch_current_tgt, &labels, switch_instruction_size, stack, 1);
1479
PDEBUG("CILIR: done with the switch\n");
1481
case LDIND_I1_OPCODE:
1482
PDEBUG("CILIR:<CIL Inst %d> ldind.i1\n", opcode_counter);
1483
if (is_invalid_basic_block == 1) break;
1484
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IRINT8, IRINT32, current_binary, ¤t_label_ID, &labels);
1486
case LDIND_U1_OPCODE:
1487
PDEBUG("CILIR:<CIL Inst %d> ldind.u1\n", opcode_counter);
1488
if (is_invalid_basic_block == 1) break;
1489
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IRUINT8, IRINT32, current_binary, ¤t_label_ID, &labels);
1491
case LDIND_I2_OPCODE:
1492
PDEBUG("CILIR:<CIL Inst %d> ldind.i2\n", opcode_counter);
1493
if (is_invalid_basic_block == 1) break;
1494
is_invalid_basic_block = translate_cil_ldind(system, method, bytes_read, stack, IRINT16, IRINT32, current_binary, ¤t_label_ID, &labels);
1496
case LDIND_U2_OPCODE:
1497
PDEBUG("CILIR:<CIL Inst %d> ldind.u2\n", opcode_counter);
1498
if (is_invalid_basic_block == 1) break;
1499
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IRUINT16, IRINT32, current_binary, ¤t_label_ID, &labels);
1501
case LDIND_I4_OPCODE:
1502
PDEBUG("CILIR:<CIL Inst %d> ldind.i4\n", opcode_counter);
1503
if (is_invalid_basic_block == 1) break;
1504
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IRINT32, IRINT32, current_binary, ¤t_label_ID, &labels);
1506
case LDIND_U4_OPCODE:
1507
PDEBUG("CILIR:<CIL Inst %d> ldind.u4\n", opcode_counter);
1508
if (is_invalid_basic_block == 1) break;
1509
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IRUINT32, IRINT32, current_binary, ¤t_label_ID, &labels);
1511
case LDIND_I8_OPCODE:
1512
PDEBUG("CILIR:<CIL Inst %d> ldind.i8\n", opcode_counter);
1513
if (is_invalid_basic_block == 1) break;
1514
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IRINT64, IRINT64, current_binary, ¤t_label_ID, &labels);
1516
case LDIND_I_OPCODE:
1517
PDEBUG("CILIR:<CIL Inst %d> ldind.i\n", opcode_counter);
1518
if (is_invalid_basic_block == 1) break;
1519
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IRNINT, IRNINT, current_binary, ¤t_label_ID, &labels);
1521
case LDIND_R4_OPCODE:
1522
PDEBUG("CILIR:<CIL Inst %d> ldind.r4\n", opcode_counter);
1523
if (is_invalid_basic_block == 1) break;
1524
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IRFLOAT32, IRFLOAT32, current_binary, ¤t_label_ID, &labels);
1526
case LDIND_R8_OPCODE:
1527
PDEBUG("CILIR:<CIL Inst %d> ldind.r8\n", opcode_counter);
1528
if (is_invalid_basic_block == 1) break;
1529
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IRFLOAT64, IRFLOAT64, current_binary, ¤t_label_ID, &labels);
1531
case LDIND_REF_OPCODE:
1532
PDEBUG("CILIR:<CIL Inst %d> ldind.ref\n", opcode_counter);
1533
if (is_invalid_basic_block == 1) break;
1534
is_invalid_basic_block = translate_cil_ldind (system, method, bytes_read, stack, IROBJECT, IROBJECT, current_binary, ¤t_label_ID, &labels);
1536
case STIND_REF_OPCODE:
1537
PDEBUG("CILIR:<CIL Inst %d> stind.ref\n", opcode_counter);
1538
if (is_invalid_basic_block == 1) break;
1539
is_invalid_basic_block = translate_cil_stind (system, method, cilStack, bytes_read, stack, current_binary, ¤t_label_ID, &labels, IROBJECT);
1541
case STIND_I1_OPCODE:
1542
PDEBUG("CILIR:<CIL Inst %d> stind.i1\n", opcode_counter);
1543
if (is_invalid_basic_block == 1) break;
1544
is_invalid_basic_block = translate_cil_stind (system, method, cilStack, bytes_read, stack, current_binary, ¤t_label_ID, &labels, IRINT8);
1546
case STIND_I2_OPCODE:
1547
PDEBUG("CILIR:<CIL Inst %d> stind.i2\n", opcode_counter);
1548
if (is_invalid_basic_block == 1) break;
1549
is_invalid_basic_block = translate_cil_stind (system, method, cilStack, bytes_read, stack, current_binary, ¤t_label_ID, &labels, IRINT16);
1551
case STIND_I4_OPCODE:
1552
PDEBUG("CILIR:<CIL Inst %d> stind.i4\n", opcode_counter);
1553
if (is_invalid_basic_block == 1) break;
1554
is_invalid_basic_block = translate_cil_stind (system, method, cilStack, bytes_read, stack, current_binary, ¤t_label_ID, &labels, IRINT32);
1556
case STIND_I8_OPCODE:
1557
PDEBUG("CILIR:<CIL Inst %d> stind.i8\n", opcode_counter);
1558
if (is_invalid_basic_block == 1) break;
1559
is_invalid_basic_block = translate_cil_stind (system, method, cilStack, bytes_read, stack, current_binary, ¤t_label_ID, &labels, IRINT64);
1561
case STIND_R4_OPCODE:
1562
PDEBUG("CILIR:<CIL Inst %d> stind.r4\n", opcode_counter);
1563
if (is_invalid_basic_block == 1) break;
1564
is_invalid_basic_block = translate_cil_stind (system, method, cilStack, bytes_read, stack, current_binary, ¤t_label_ID, &labels, IRFLOAT32);
1566
case STIND_R8_OPCODE:
1567
PDEBUG("CILIR:<CIL Inst %d> stind.r8\n", opcode_counter);
1568
if (is_invalid_basic_block == 1) break;
1569
is_invalid_basic_block = translate_cil_stind (system, method, cilStack, bytes_read, stack, current_binary, ¤t_label_ID, &labels, IRFLOAT64);
1572
PDEBUG("CILIR:<CIL Inst %d> add\n", opcode_counter);
1573
if (is_invalid_basic_block == 1) break;
1574
is_invalid_basic_block = _translate_arithmetic_operation(system, method, bytes_read, stack, IRADD);
1577
PDEBUG("CILIR:<CIL Inst %d> sub\n", opcode_counter);
1578
if (is_invalid_basic_block == 1) break;
1579
is_invalid_basic_block = _translate_arithmetic_operation(system, method , bytes_read, stack, IRSUB);
1582
PDEBUG("CILIR:<CIL Inst %d> mul\n", opcode_counter);
1583
if (is_invalid_basic_block == 1) break;
1584
is_invalid_basic_block = _translate_arithmetic_operation(system, method , bytes_read, stack, IRMUL);
1587
PDEBUG("CILIR:<CIL Inst %d> Div\n", opcode_counter);
1588
if (is_invalid_basic_block == 1) break;
1589
is_invalid_basic_block = _translate_arithmetic_operation(system, method , bytes_read, stack, IRDIV);
1592
PDEBUG("CILIR:<CIL Inst %d> div.un\n", opcode_counter);
1593
if (is_invalid_basic_block == 1) break;
1594
is_invalid_basic_block = _translate_arithmetic_operation_un(system, method, bytes_read, stack, IRDIV);
1597
PDEBUG("CILIR:<CIL Inst %d> rem\n", opcode_counter);
1598
if (is_invalid_basic_block == 1) break;
1599
is_invalid_basic_block = _translate_arithmetic_operation(system, method , bytes_read, stack, IRREM);
1602
PDEBUG("CILIR:<CIL Inst %d> rem.un\n", opcode_counter);
1603
if (is_invalid_basic_block == 1) break;
1604
is_invalid_basic_block = _translate_arithmetic_operation_un(system, method , bytes_read, stack, IRREM);
1607
PDEBUG("CILIR:<CIL Inst %d> and\n", opcode_counter);
1608
if (is_invalid_basic_block == 1) break;
1609
is_invalid_basic_block = translate_instruction_with_binary_logical_operator (system, method, bytes_read, stack, IRAND);
1612
PDEBUG("CILIR:<CIL Inst %d> or\n", opcode_counter);
1613
if (is_invalid_basic_block == 1) break;
1614
is_invalid_basic_block = translate_instruction_with_binary_logical_operator (system, method, bytes_read, stack, IROR);
1617
PDEBUG("CILIR:<CIL Inst %d> xor\n", opcode_counter);
1618
if (is_invalid_basic_block == 1) break;
1619
is_invalid_basic_block = translate_instruction_with_binary_logical_operator (system, method, bytes_read, stack, IRXOR);
1622
PDEBUG("CILIR:<CIL Inst %d> shl\n", opcode_counter);
1623
if (is_invalid_basic_block == 1) break;
1624
is_invalid_basic_block = translate_cil_shl (system, method, bytes_read, stack);
1627
PDEBUG("CILIR:<CIL Inst %d> shr\n", opcode_counter);
1628
if (is_invalid_basic_block == 1) break;
1629
is_invalid_basic_block = translate_cil_shr (system, method, bytes_read, stack, current_binary, 0);
1632
PDEBUG("CILIR:<CIL Inst %d> shr.un\n", opcode_counter);
1633
if (is_invalid_basic_block == 1) break;
1634
is_invalid_basic_block = translate_cil_shr (system, method, bytes_read, stack, current_binary, 1);
1637
PDEBUG("CILIR:<CIL Inst %d> neg\n", opcode_counter);
1638
if (is_invalid_basic_block == 1) break;
1639
instruction = method->newIRInstr(method);
1640
instruction->type = IRNEG;
1642
(instruction->param_1).value = stack->stack[stack->top].value;
1643
(instruction->param_1).fvalue = stack->stack[stack->top].fvalue;
1644
(instruction->param_1).type = (stack->stack[stack->top]).type;
1645
(instruction->param_1).internal_type = (stack->stack[stack->top]).internal_type;
1647
/* Clean the top of the stack */
1648
stack->cleanTop(stack);
1650
stack->stack[stack->top].value = method->getMaxVariables(method);
1651
stack->stack[stack->top].type = IROFFSET;
1652
stack->stack[stack->top].internal_type = (instruction->param_1).internal_type;
1654
(instruction->result).value = stack->stack[stack->top].value;
1655
(instruction->result).fvalue = stack->stack[stack->top].fvalue;
1656
(instruction->result).type = (stack->stack[stack->top]).type;
1657
(instruction->result).internal_type = stack->stack[stack->top].internal_type;
1659
method->increaseMaxVariables(method);
1660
instruction->byte_offset = bytes_read;
1663
PDEBUG("CILIR:<CIL Inst %d> not\n", opcode_counter);
1664
if (is_invalid_basic_block == 1)
1666
instruction = method->newIRInstr(method);
1667
instruction->type = IRNOT;
1669
(instruction->param_1).value = stack->stack[stack->top].value;
1670
(instruction->param_1).fvalue = stack->stack[stack->top].fvalue;
1671
(instruction->param_1).type = (stack->stack[stack->top]).type;
1672
(instruction->param_1).internal_type = (stack->stack[stack->top]).internal_type;
1674
/* Clean the top of the stack */
1675
stack->cleanTop(stack);
1677
stack->stack[stack->top].value = method->getMaxVariables(method);
1678
stack->stack[stack->top].type = IROFFSET;
1679
stack->stack[stack->top].internal_type = (instruction->param_1).internal_type;
1680
assert(stack->stack[stack->top].internal_type != NOPARAM);
1681
(instruction->result).value = stack->stack[stack->top].value;
1682
(instruction->result).fvalue = stack->stack[stack->top].fvalue;
1683
(instruction->result).type = (stack->stack[stack->top]).type;
1684
(instruction->result).internal_type = (stack->stack[stack->top]).internal_type;
1686
method->increaseMaxVariables(method);
1687
instruction->byte_offset = bytes_read;
1689
case CONV_I1_OPCODE:
1690
PDEBUG("CILIR:<CIL Inst %d> conv.i1\n", opcode_counter);
1691
if (is_invalid_basic_block == 1) break;
1692
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRINT8, 0, 0, 1);
1694
case CONV_I2_OPCODE:
1695
PDEBUG("CILIR:<CIL Inst %d> conv.i2\n", opcode_counter);
1696
if (is_invalid_basic_block == 1) break;
1697
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRINT16, 0, 0, 1);
1699
case CONV_I4_OPCODE:
1700
PDEBUG("CILIR:<CIL Inst %d> conv.i4\n", opcode_counter);
1701
if (is_invalid_basic_block == 1) break;
1702
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRINT32, 0, 0, 1);
1704
case CONV_I8_OPCODE:
1705
PDEBUG("CILIR:<CIL Inst %d> conv.i8\n", opcode_counter);
1706
if (is_invalid_basic_block == 1) break;
1707
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRINT64, 0, 0, 1);
1709
case CONV_R4_OPCODE:
1710
PDEBUG("CILIR:<CIL Inst %d> conv.r4\n", opcode_counter);
1711
if (is_invalid_basic_block == 1) break;
1712
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRFLOAT32, 0, 0, 1);
1714
case CONV_R8_OPCODE:
1715
PDEBUG("CILIR:<CIL Inst %d> conv.r8\n", opcode_counter);
1716
if (is_invalid_basic_block == 1) break;
1717
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRFLOAT64, 0, 0, 1);
1719
case CONV_U4_OPCODE:
1720
PDEBUG("CILIR:<CIL Inst %d> conv.u4\n", opcode_counter);
1721
if (is_invalid_basic_block == 1) break;
1722
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRUINT32, 0, 0, 1);
1724
case CONV_U8_OPCODE:
1725
PDEBUG("CILIR:<CIL Inst %d> conv.u8\n", opcode_counter);
1726
if (is_invalid_basic_block == 1) break;
1727
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRUINT64, 0, 0, 1);
1729
case CALLVIRT_OPCODE:
1730
memcpy(&new_token, body_stream + bytes_read, 4);
1732
PDEBUG("CILIR:<CIL Inst %d> callvirt 0x%X\n", opcode_counter, new_token);
1733
if (is_invalid_basic_block == 1) break;
1734
is_invalid_basic_block = translate_cil_vcall(system, cilStack, current_binary, method, new_token, bytes_read, stack, 0, ¤t_label_ID, &labels);
1736
case CPOBJ_OPCODE: //FIXME todo
1737
memcpy(&new_token, body_stream + bytes_read, 4);
1739
PDEBUG("CILIR:<CIL Inst %d> cpobj 0x%X\n", opcode_counter, new_token);
1740
if (is_invalid_basic_block == 1) break;
1741
print_err("CILIR: cpobj instruction is not implemented. ", 0);
1745
memcpy(&new_token, body_stream + bytes_read, 4);
1747
PDEBUG("CILIR:<CIL Inst %d> ldobj 0x%X\n", opcode_counter, new_token);
1748
if (is_invalid_basic_block == 1) break;
1749
is_invalid_basic_block = translate_cil_ldobj (method, cilStack, new_token, bytes_read, stack, current_binary, system, ¤t_label_ID, &labels);
1752
memcpy(&new_token, body_stream + bytes_read, 4);
1754
PDEBUG("CILIR:<CIL Inst %d> ldstr 0x%X\n", opcode_counter, new_token);
1755
if (is_invalid_basic_block == 1) break;
1756
is_invalid_basic_block = translate_cil_ldstr (system, method, cilStack, new_token, bytes_read, stack, current_binary, ¤t_label_ID, &labels);
1759
memcpy(&new_token, body_stream + bytes_read, 4);
1761
PDEBUG("CILIR:<CIL Inst %d> newobj 0x%X\n", opcode_counter, new_token);
1762
if (is_invalid_basic_block == 1) break;
1763
is_invalid_basic_block = translate_cil_newobj (system, cilStack, current_binary, method, bytes_read, new_token, stack, ¤t_label_ID, &labels, methodsToCall);
1765
case CASTCLASS_OPCODE:
1766
memcpy(&new_token, body_stream + bytes_read, 4);
1768
PDEBUG("CILIR:<CIL Inst %d> castclass 0x%X\n", opcode_counter, new_token);
1769
if (is_invalid_basic_block == 1) break;
1770
is_invalid_basic_block = translate_cil_castclass (system, method, cilStack, new_token, current_binary, &labels ,¤t_label_ID, bytes_read, stack);
1773
memcpy(&new_token, body_stream + bytes_read, 4);
1775
PDEBUG("CILIR:<CIL Inst %d> isinst 0x%X\n", opcode_counter, new_token);
1776
if (is_invalid_basic_block == 1) break;
1777
is_invalid_basic_block = translate_Test_Cast_Class (system, method, cilStack, ¤t_label_ID, &labels , bytes_read, stack, current_binary, new_token, 0);
1779
case CONV_R_UN_OPCODE:
1780
PDEBUG("CILIR:<CIL Inst %d> conv.r.un\n", opcode_counter);
1781
if (is_invalid_basic_block == 1) break;
1782
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRNFLOAT, 0, 1, 1);
1785
memcpy(&new_token, body_stream + bytes_read, 4);
1787
PDEBUG("CILIR:<CIL Inst %d> unbox 0x%X\n", opcode_counter, new_token);
1788
if (is_invalid_basic_block == 1) break;
1789
is_invalid_basic_block = translate_cil_unbox (system, cilStack, current_binary, method, bytes_read, new_token, stack, ¤t_label_ID, &labels);
1792
PDEBUG("CILIR:<CIL Inst %d> throw\n", opcode_counter);
1793
if (is_invalid_basic_block == 1) break;
1794
is_invalid_basic_block = translate_cil_throw (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, stack, current_binary);
1797
memcpy(&new_token, body_stream + bytes_read, 4);
1799
PDEBUG("CILIR:<CIL Inst %d> ldfld 0x%X\n", opcode_counter, new_token);
1800
if (is_invalid_basic_block == 1) break;
1801
is_invalid_basic_block = translate_cil_ldfld (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, current_binary, new_token, stack);
1804
memcpy(&new_token, body_stream + bytes_read, 4);
1806
PDEBUG("CILIR:<CIL Inst %d> ldflda 0x%X\n" , opcode_counter, new_token);
1807
if (is_invalid_basic_block == 1) break;
1808
is_invalid_basic_block = translate_cil_ldflda (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, current_binary, new_token, stack, methodsToCall);
1811
memcpy(&new_token, body_stream + bytes_read, 4);
1813
PDEBUG("CILIR:<CIL Inst %d> stfld 0x%X\n", opcode_counter, new_token);
1814
if (is_invalid_basic_block == 1) break;
1815
is_invalid_basic_block = translate_cil_stfld (method, cilStack, bytes_read, current_binary, new_token, stack, ¤t_label_ID, &labels, system);
1818
memcpy(&new_token, body_stream + bytes_read, 4);
1820
PDEBUG("CILIR:<CIL Inst %d> ldsfld 0x%X\n", opcode_counter, new_token);
1821
if (is_invalid_basic_block == 1) break;
1822
is_invalid_basic_block = translate_cil_ldsfld (method, cilStack, new_token, bytes_read, stack, current_binary, system, ¤t_label_ID, &labels, methodsToCall);
1824
case LDSFLDA_OPCODE:
1825
memcpy(&new_token, body_stream + bytes_read, 4);
1827
PDEBUG("CILIR:<CIL Inst %d> ldsflda 0x%X\n" , opcode_counter, new_token);
1828
if (is_invalid_basic_block == 1) break;
1829
is_invalid_basic_block = translate_cil_ldsflda (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, current_binary, new_token, stack, methodsToCall);
1832
memcpy(&new_token, body_stream + bytes_read, 4);
1834
PDEBUG("CILIR:<CIL Inst %d> stsfld 0x%X\n", opcode_counter, new_token);
1835
if (is_invalid_basic_block == 1) break;
1836
is_invalid_basic_block = translate_cil_stsfld (method, cilStack, new_token, bytes_read, stack, current_binary, system, ¤t_label_ID, &labels, methodsToCall);
1839
memcpy(&new_token, body_stream + bytes_read, 4);
1841
PDEBUG("CILIR:<CIL Inst %d> stobj 0x%X\n", opcode_counter, new_token);
1842
if (is_invalid_basic_block == 1) break;
1843
is_invalid_basic_block = translate_cil_stobj (method, cilStack, new_token, bytes_read, stack, current_binary, system, ¤t_label_ID, &labels, unaligned_prefix_value);
1844
/* Reset the unaligned prefix value */
1845
if (unaligned_prefix_value != 0) unaligned_prefix_value = 0;
1847
case CONV_OVF_I1_UN_OPCODE:
1848
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i1.un\n", opcode_counter);
1849
if (is_invalid_basic_block == 1) break;
1850
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRINT8, 1, 1, 1);
1852
case CONV_OVF_I2_UN_OPCODE:
1853
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i2.un\n", opcode_counter);
1854
if (is_invalid_basic_block == 1) break;
1855
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRINT16, 1, 1, 1);
1857
case CONV_OVF_I4_UN_OPCODE:
1858
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i4.un\n", opcode_counter);
1859
if (is_invalid_basic_block == 1) break;
1860
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRINT32, 1, 1, 1);
1862
case CONV_OVF_I8_UN_OPCODE:
1863
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i8.un\n", opcode_counter);
1864
if (is_invalid_basic_block == 1) break;
1865
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRINT64, 1, 1, 1);
1867
case CONV_OVF_U1_UN_OPCODE:
1868
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u1.un\n", opcode_counter);
1869
if (is_invalid_basic_block == 1) break;
1870
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT8, 1, 1, 1);
1872
case CONV_OVF_U2_UN_OPCODE:
1873
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u2.un\n", opcode_counter);
1874
if (is_invalid_basic_block == 1) break;
1875
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT16, 1, 1, 1);
1877
case CONV_OVF_U4_UN_OPCODE:
1878
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u4.un\n", opcode_counter);
1879
if (is_invalid_basic_block == 1) break;
1880
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT32, 1, 1, 1);
1882
case CONV_OVF_U8_UN_OPCODE:
1883
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u8.un\n", opcode_counter);
1884
if (is_invalid_basic_block == 1) break;
1885
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT64, 1, 1, 1);
1887
case CONV_OVF_I_UN_OPCODE:
1888
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i.un\n", opcode_counter);
1889
if (is_invalid_basic_block == 1) break;
1890
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRNINT, 1, 1, 1);
1892
case CONV_OVF_U_UN_OPCODE:
1893
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u.un\n", opcode_counter);
1894
if (is_invalid_basic_block == 1) break;
1895
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRNUINT, 1, 1, 1);
1898
memcpy(&new_token, body_stream + bytes_read, 4);
1900
PDEBUG("CILIR:<CIL Inst %d> box 0x%X\n", opcode_counter, new_token);
1901
if (is_invalid_basic_block == 1) break;
1902
is_invalid_basic_block = translate_cil_box (system, cilStack, current_binary, method, bytes_read, new_token, stack, ¤t_label_ID, &labels);
1905
memcpy(&new_token, body_stream + bytes_read, 4);
1907
PDEBUG("CILIR:<CIL Inst %d> newarr 0x%X\n", opcode_counter, new_token);
1908
if (is_invalid_basic_block == 1) break;
1909
is_invalid_basic_block = translate_cil_newarr (system, cilStack, current_binary, method, bytes_read, new_token, stack, ¤t_label_ID, &labels);
1912
PDEBUG("CILIR:<CIL Inst %d> ldlen\n", opcode_counter);
1913
if (is_invalid_basic_block == 1) break;
1914
is_invalid_basic_block = translate_cil_ldlen(system, method, cilStack, bytes_read, stack, ¤t_label_ID, &labels);
1916
case LDELEMA_OPCODE:
1917
memcpy(&new_token, body_stream + bytes_read, 4);
1919
PDEBUG("CILIR:<CIL Inst %d> ldelema 0x%X\n", opcode_counter, new_token);
1920
if (is_invalid_basic_block == 1) break;
1921
is_invalid_basic_block = translate_cil_ldelema (system, cilStack, current_binary, method, bytes_read , new_token, stack, ¤t_label_ID, &labels);
1923
case LDELEM_I1_OPCODE:
1924
PDEBUG("CILIR:<CIL Inst %d> ldelem.i1\n", opcode_counter);
1925
if (is_invalid_basic_block == 1) break;
1926
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRINT8, stack, ¤t_label_ID, &labels, current_binary);
1928
case LDELEM_U1_OPCODE:
1929
PDEBUG("CILIR:<CIL Inst %d> ldelem.u1\n", opcode_counter);
1930
if (is_invalid_basic_block == 1) break;
1931
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRUINT8, stack, ¤t_label_ID, &labels, current_binary);
1933
case LDELEM_I2_OPCODE:
1934
PDEBUG("CILIR:<CIL Inst %d> ldelem.i2\n", opcode_counter);
1935
if (is_invalid_basic_block == 1) break;
1936
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRINT16, stack, ¤t_label_ID, &labels, current_binary);
1938
case LDELEM_U2_OPCODE:
1939
PDEBUG("CILIR:<CIL Inst %d> ldelem.u2\n", opcode_counter);
1940
if (is_invalid_basic_block == 1) break;
1941
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRUINT16, stack, ¤t_label_ID, &labels, current_binary);
1943
case LDELEM_I4_OPCODE:
1944
PDEBUG("CILIR:<CIL Inst %d> ldelem.i4\n", opcode_counter);
1945
if (is_invalid_basic_block == 1) break;
1946
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRINT32, stack, ¤t_label_ID, &labels, current_binary);
1948
case LDELEM_U4_OPCODE:
1949
PDEBUG("CILIR:<CIL Inst %d> ldelem.u4\n", opcode_counter);
1950
if (is_invalid_basic_block == 1) break;
1951
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRUINT32, stack, ¤t_label_ID, &labels, current_binary);
1953
case LDELEM_I8_OPCODE:
1954
PDEBUG("CILIR:<CIL Inst %d> ldelem.i8\n", opcode_counter);
1955
if (is_invalid_basic_block == 1) break;
1956
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRINT64, stack, ¤t_label_ID, &labels, current_binary);
1958
case LDELEM_I_OPCODE:
1959
PDEBUG("CILIR:<CIL Inst %d> ldelem.i\n", opcode_counter);
1960
if (is_invalid_basic_block == 1) break;
1961
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRNINT, stack, ¤t_label_ID, &labels, current_binary);
1963
case LDELEM_R4_OPCODE:
1964
PDEBUG("CILIR:<CIL Inst %d> ldelem.r4\n", opcode_counter);
1965
if (is_invalid_basic_block == 1) break;
1966
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRFLOAT32, stack, ¤t_label_ID, &labels, current_binary);
1968
case LDELEM_R8_OPCODE:
1969
PDEBUG("CILIR:<CIL Inst %d> ldelem.r8\n", opcode_counter);
1970
if (is_invalid_basic_block == 1) break;
1971
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IRFLOAT64, stack, ¤t_label_ID, &labels, current_binary);
1973
case LDELEM_REF_OPCODE:
1974
PDEBUG("CILIR:<CIL Inst %d> ldelem.ref\n", opcode_counter);
1975
if (is_invalid_basic_block == 1) break;
1976
is_invalid_basic_block = translate_cil_ldelem (system, method, cilStack, bytes_read, IROBJECT, stack, ¤t_label_ID, &labels, current_binary);
1978
case STELEM_I_OPCODE:
1979
PDEBUG("CILIR:<CIL Inst %d> stelem.i\n", opcode_counter);
1980
if (is_invalid_basic_block == 1) break;
1981
assert(system->type_checker != NULL);
1982
assert((system->type_checker)->token_analyzer != NULL);
1983
stelem_class_located = ((system->type_checker)->token_analyzer) ->get_ILType_from_elementType ((system->type_checker)->token_analyzer , system->binary_info, ELEMENT_TYPE_I, system->binaries);
1984
assert(stelem_class_located != NULL);
1985
assert(stelem_class_located->ID != NULL);
1986
assert(stelem_class_located->binary != NULL);
1987
is_invalid_basic_block = translate_cil_stelem (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, stelem_class_located, IRNINT, stack, current_binary);
1989
case STELEM_I1_OPCODE:
1990
PDEBUG("CILIR:<CIL Inst %d> stelem.i1\n", opcode_counter);
1991
if (is_invalid_basic_block == 1) break;
1992
assert(system->type_checker != NULL);
1993
assert((system->type_checker)->token_analyzer != NULL);
1994
stelem_class_located = ((system->type_checker)->token_analyzer) ->get_ILType_from_elementType ((system->type_checker)->token_analyzer , system->binary_info, ELEMENT_TYPE_I1, system->binaries);
1995
assert(stelem_class_located != NULL);
1996
assert(stelem_class_located->ID != NULL);
1997
assert(stelem_class_located->binary != NULL);
1998
is_invalid_basic_block = translate_cil_stelem (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, stelem_class_located, IRINT8, stack, current_binary);
2000
case STELEM_I2_OPCODE:
2001
PDEBUG("CILIR:<CIL Inst %d> stelem.i2\n", opcode_counter);
2002
if (is_invalid_basic_block == 1) break;
2003
assert(system->type_checker != NULL);
2004
assert((system->type_checker)->token_analyzer != NULL);
2005
stelem_class_located = ((system->type_checker)->token_analyzer) ->get_ILType_from_elementType ((system->type_checker)->token_analyzer , system->binary_info, ELEMENT_TYPE_I2, system->binaries);
2006
assert(stelem_class_located != NULL);
2007
assert(stelem_class_located->ID != NULL);
2008
assert(stelem_class_located->binary != NULL);
2009
is_invalid_basic_block = translate_cil_stelem (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, stelem_class_located, IRINT16, stack, current_binary);
2011
case STELEM_I4_OPCODE:
2012
PDEBUG("CILIR:<CIL Inst %d> stelem.i4\n", opcode_counter);
2013
if (is_invalid_basic_block == 1) break;
2014
assert(system->type_checker != NULL);
2015
assert((system->type_checker)->token_analyzer != NULL);
2016
stelem_class_located = ((system->type_checker)->token_analyzer) ->get_ILType_from_elementType ((system->type_checker)->token_analyzer , system->binary_info, ELEMENT_TYPE_I4, system->binaries);
2017
assert(stelem_class_located != NULL);
2018
assert(stelem_class_located->ID != NULL);
2019
assert(stelem_class_located->binary != NULL);
2020
is_invalid_basic_block = translate_cil_stelem (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, stelem_class_located, IRINT32, stack, current_binary);
2022
case STELEM_I8_OPCODE:
2023
PDEBUG("CILIR:<CIL Inst %d> stelem.i8\n", opcode_counter);
2024
if (is_invalid_basic_block == 1) break;
2025
assert(system->type_checker != NULL);
2026
assert((system->type_checker)->token_analyzer != NULL);
2027
stelem_class_located = ((system->type_checker)->token_analyzer) ->get_ILType_from_elementType ((system->type_checker)->token_analyzer , system->binary_info, ELEMENT_TYPE_I8, system->binaries);
2028
assert(stelem_class_located != NULL);
2029
assert(stelem_class_located->ID != NULL);
2030
assert(stelem_class_located->binary != NULL);
2031
is_invalid_basic_block = translate_cil_stelem (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, stelem_class_located, IRINT64, stack, current_binary);
2033
case STELEM_R4_OPCODE:
2034
PDEBUG("CILIR:<CIL Inst %d> stelem.r4\n", opcode_counter);
2035
if (is_invalid_basic_block == 1) break;
2036
assert(system->type_checker != NULL);
2037
assert((system->type_checker)->token_analyzer != NULL);
2038
stelem_class_located = ((system->type_checker)->token_analyzer) ->get_ILType_from_elementType ((system->type_checker)->token_analyzer , system->binary_info, ELEMENT_TYPE_R4, system->binaries);
2039
assert(stelem_class_located != NULL);
2040
assert(stelem_class_located->ID != NULL);
2041
assert(stelem_class_located->binary != NULL);
2042
is_invalid_basic_block = translate_cil_stelem (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, stelem_class_located, IRFLOAT32, stack, current_binary);
2044
case STELEM_R8_OPCODE:
2045
PDEBUG("CILIR:<CIL Inst %d> stelem.r8\n", opcode_counter);
2046
if (is_invalid_basic_block == 1) break;
2047
assert(system->type_checker != NULL);
2048
assert((system->type_checker)->token_analyzer != NULL);
2049
stelem_class_located = ((system->type_checker)->token_analyzer) ->get_ILType_from_elementType ((system->type_checker)->token_analyzer , system->binary_info, ELEMENT_TYPE_R8, system->binaries);
2050
assert(stelem_class_located != NULL);
2051
assert(stelem_class_located->ID != NULL);
2052
assert(stelem_class_located->binary != NULL);
2053
is_invalid_basic_block = translate_cil_stelem (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, stelem_class_located, IRFLOAT64, stack, current_binary);
2055
case STELEM_REF_OPCODE:
2056
PDEBUG("CILIR:<CIL Inst %d> stelem.ref\n", opcode_counter);
2057
if (is_invalid_basic_block == 1) break;
2058
is_invalid_basic_block = translate_cil_stelem (system, method, cilStack, ¤t_label_ID, &labels, bytes_read, NULL, IRUPOINTER, stack, current_binary);
2060
case LDELEM_OPCODE: //FIXME todo
2061
memcpy(&new_token, body_stream + bytes_read, 4);
2063
PDEBUG("CILIR:<CIL Inst %d> ldelem 0x%X\n", opcode_counter, new_token);
2064
if (is_invalid_basic_block == 1)
2066
print_err("CILIR: ldelem instruction is not implemented. ", 0);
2069
case STELEM_OPCODE: //FIXME todo
2070
memcpy(&new_token, body_stream + bytes_read, 4);
2072
PDEBUG("CILIR:<CIL Inst %d> stelem 0x%X\n", opcode_counter, new_token);
2073
if (is_invalid_basic_block == 1)
2075
print_err("CILIR: stelem instruction is not implemented. ", 0);
2078
case UNBOX_ANY_OPCODE: //FIXME todo
2079
memcpy(&new_token, body_stream + bytes_read, 4);
2081
PDEBUG("CILIR:<CIL Inst %d> unbox.any 0x%X\n", opcode_counter, new_token);
2082
if (is_invalid_basic_block == 1)
2084
print_err("CILIR: unbox.any instruction is not implemented. ", 0);
2087
case CONV_OVF_I1_OPCODE:
2088
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i1\n", opcode_counter);
2089
if (is_invalid_basic_block == 1) break;
2090
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRINT8, 1, 0, 1);
2092
case CONV_OVF_U1_OPCODE:
2093
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u1\n", opcode_counter);
2094
if (is_invalid_basic_block == 1) break;
2095
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT8, 1, 0, 1);
2097
case CONV_OVF_I2_OPCODE:
2098
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i2\n", opcode_counter);
2099
if (is_invalid_basic_block == 1) break;
2100
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRINT16, 1, 0, 1);
2102
case CONV_OVF_U2_OPCODE:
2103
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u2\n", opcode_counter);
2104
if (is_invalid_basic_block == 1) break;
2105
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT16, 1, 0, 1);
2107
case CONV_OVF_I4_OPCODE:
2108
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i4\n", opcode_counter);
2109
if (is_invalid_basic_block == 1) break;
2110
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRINT32, 1, 0, 1);
2112
case CONV_OVF_U4_OPCODE:
2113
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u4\n", opcode_counter);
2114
if (is_invalid_basic_block == 1) break;
2115
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT32, 1, 0, 1);
2117
case CONV_OVF_I8_OPCODE:
2118
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i8\n", opcode_counter);
2119
if (is_invalid_basic_block == 1) break;
2120
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRINT64, 1, 0, 1);
2122
case CONV_OVF_U8_OPCODE:
2123
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u8\n", opcode_counter);
2124
if (is_invalid_basic_block == 1) break;
2125
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT64, 1, 0, 1);
2127
case REFANYVAL_OPCODE:
2128
memcpy(&new_token, body_stream + bytes_read, 4);
2130
PDEBUG("CILIR:<CIL Inst %d> refanyval 0x%X\n", opcode_counter, new_token);
2131
if (is_invalid_basic_block == 1) break;
2132
is_invalid_basic_block = translate_cil_refanyval(system, method, cilStack, ¤t_label_ID, &labels, bytes_read, stack, current_binary, new_token);
2134
case CKFINITE_OPCODE:
2135
PDEBUG("CILIR:<CIL Inst %d> ckfinite\n", opcode_counter);
2136
if (is_invalid_basic_block == 1) break;
2137
is_invalid_basic_block = translate_cil_Ckfinite (method, cilStack, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, system, 1, stack, current_binary);
2139
case MKREFANY_OPCODE: //FIXME todo
2140
memcpy(&new_token, body_stream + bytes_read, 4);
2142
PDEBUG("CILIR:<CIL Inst %d> mkrefany 0x%X\n", opcode_counter, new_token);
2143
if (is_invalid_basic_block == 1)
2145
print_err("CILIR: mkrefany instruction is not implemented. ", 0);
2148
case LDTOKEN_OPCODE:
2149
memcpy(&new_token, body_stream + bytes_read, 4);
2151
PDEBUG("CILIR:<CIL Inst %d> ldtoken 0x%X\n", opcode_counter, new_token);
2152
if (is_invalid_basic_block == 1) break;
2153
is_invalid_basic_block = translate_cil_ldtoken (system, method, current_binary, stack , bytes_read, new_token, ¤t_label_ID, &labels);
2155
case CONV_U2_OPCODE:
2156
PDEBUG("CILIR:<CIL Inst %d> conv.u2\n", opcode_counter);
2157
if (is_invalid_basic_block == 1) break;
2158
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT16, 0, 0, 1);
2160
case CONV_U1_OPCODE:
2161
PDEBUG("CILIR:<CIL Inst %d> conv.u1\n", opcode_counter);
2162
if (is_invalid_basic_block == 1) break;
2163
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRUINT8, 0, 0, 1);
2166
PDEBUG("CILIR:<CIL Inst %d> conv.i\n", opcode_counter);
2167
if (is_invalid_basic_block == 1) break;
2168
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRNINT, 0, 0, 1);
2170
case CONV_OVF_I_OPCODE:
2171
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.i\n", opcode_counter);
2172
if (is_invalid_basic_block == 1) break;
2173
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRNUINT, 1, 0, 1);
2175
case CONV_OVF_U_OPCODE:
2176
PDEBUG("CILIR:<CIL Inst %d> conv.ovf.u\n", opcode_counter);
2177
if (is_invalid_basic_block == 1) break;
2178
is_invalid_basic_block = translate_cil_conv (system, method, bytes_read, stack, IRNINT, 1, 0, 1);
2180
case ADD_OVF_OPCODE:
2181
PDEBUG("CILIR:<CIL Inst %d> add.ovf\n", opcode_counter);
2182
if (is_invalid_basic_block == 1) break;
2183
is_invalid_basic_block = _translate_arithmetic_operation(system, method , bytes_read, stack, IRADDOVF);
2185
case ADD_OVF_UN_OPCODE:
2186
PDEBUG("CILIR:<CIL Inst %d> add.ovf.un\n", opcode_counter);
2187
if (is_invalid_basic_block == 1) break;
2188
is_invalid_basic_block = _translate_arithmetic_operation_un(system, method , bytes_read, stack, IRADDOVF);
2190
case MUL_OVF_OPCODE:
2191
PDEBUG("CILIR:<CIL Inst %d> mul.ovf\n", opcode_counter);
2192
if (is_invalid_basic_block == 1) break;
2193
is_invalid_basic_block = _translate_arithmetic_operation(system, method , bytes_read, stack, IRMULOVF);
2195
case MUL_OVF_UN_OPCODE:
2196
PDEBUG("CILIR:<CIL Inst %d> mul.ovf.un\n", opcode_counter);
2197
if (is_invalid_basic_block == 1) break;
2198
is_invalid_basic_block = _translate_arithmetic_operation_un(system, method , bytes_read, stack, IRMULOVF);
2200
case SUB_OVF_OPCODE:
2201
PDEBUG("CILIR:<CIL Inst %d> sub.ovf\n", opcode_counter);
2202
if (is_invalid_basic_block == 1) break;
2203
is_invalid_basic_block = _translate_arithmetic_operation(system, method , bytes_read, stack, IRSUBOVF);
2205
case SUB_OVF_UN_OPCODE:
2206
PDEBUG("CILIR:<CIL Inst %d> sub.ovf.un\n", opcode_counter);
2207
if (is_invalid_basic_block == 1) break;
2208
is_invalid_basic_block = _translate_arithmetic_operation_un(system, method , bytes_read, stack, IRSUBOVF);
2210
case ENDFINALLY_OPCODE:
2211
PDEBUG("CILIR:<CIL Inst %d> endfault | endfinally\n", opcode_counter);
2212
if (is_invalid_basic_block == 1) break;
2213
instruction = method->newIRInstr(method);
2214
instruction->type = IRENDFINALLY;
2215
instruction->byte_offset = bytes_read;
2218
memcpy(buffer, body_stream + bytes_read, 4);
2220
PDEBUG("CILIR:<CIL Inst %d> leave %d\n", opcode_counter, *((JITUINT32 *)buffer));
2221
if (is_invalid_basic_block == 1) break;
2222
is_invalid_basic_block = translate_cil_leave (method, cilStack, ¤t_label_ID, bytes_read, *((JITINT32 *)buffer), &labels, system, 5, stack);
2224
case LEAVE_S_OPCODE:
2225
memcpy(buffer, body_stream + bytes_read, 1);
2227
PDEBUG("CILIR:<CIL Inst %d> leave.s %d\n", opcode_counter, buffer[0]);
2228
if (is_invalid_basic_block == 1) break;
2229
is_invalid_basic_block = translate_cil_leave(method, cilStack, ¤t_label_ID, bytes_read, (JITINT8)buffer[0], &labels, system, 2, stack);
2231
case STIND_I_OPCODE:
2232
PDEBUG("CILIR:<CIL Inst %d> stind.i\n", opcode_counter);
2233
if (is_invalid_basic_block == 1) break;
2234
is_invalid_basic_block = translate_cil_stind(system, method, cilStack, bytes_read, stack, current_binary, ¤t_label_ID, &labels, IRNINT);
2237
PDEBUG("CILIR:<CIL Inst %d> conv.u\n", opcode_counter);
2238
if (is_invalid_basic_block == 1) break;
2239
is_invalid_basic_block = translate_cil_conv(system, method, bytes_read, stack, IRNUINT, 0, 0, 1);
2242
memcpy(buffer, body_stream + bytes_read, 1);
2245
case ARGLIST_OPCODE:
2246
PDEBUG("CILIR:<CIL Inst %d> arglist\n", opcode_counter);
2247
if (is_invalid_basic_block == 1) break;
2248
is_invalid_basic_block = translate_cil_arglist(system, cilStack, method, bytes_read, stack, ¤t_label_ID, &labels);
2251
PDEBUG("CILIR:<CIL Inst %d> Ceq\n", opcode_counter);
2252
if (is_invalid_basic_block == 1) break;
2253
is_invalid_basic_block = translate_cil_compare (system, method, cilStack, bytes_read, IREQ, stack, ¤t_label_ID, &labels, current_binary, 0, 0, JITTRUE);
2256
PDEBUG("CILIR:<CIL Inst %d> Cgt\n", opcode_counter);
2257
if (is_invalid_basic_block == 1) break;
2258
is_invalid_basic_block = translate_cil_compare (system, method, cilStack, bytes_read, IRGT, stack, ¤t_label_ID, &labels, current_binary, 0, 0, JITTRUE);
2261
PDEBUG("CILIR:<CIL Inst %d> Cgt.un\n", opcode_counter);
2262
if (is_invalid_basic_block == 1) break;
2263
is_invalid_basic_block = translate_cil_compare (system, method, cilStack, bytes_read, IRGT, stack, ¤t_label_ID, &labels, current_binary, 1, 0, JITTRUE);
2266
PDEBUG("CILIR:<CIL Inst %d> Clt\n", opcode_counter);
2267
if (is_invalid_basic_block == 1) break;
2268
is_invalid_basic_block = translate_cil_compare (system, method, cilStack, bytes_read, IRLT, stack, ¤t_label_ID, &labels, current_binary, 0, 0, JITTRUE);
2271
PDEBUG("CILIR:<CIL Inst %d> clt.un\n", opcode_counter);
2272
if (is_invalid_basic_block == 1) break;
2273
is_invalid_basic_block = translate_cil_compare (system, method, cilStack, bytes_read, IRLT, stack, ¤t_label_ID, &labels, current_binary, 1, 0, JITTRUE);
2276
memcpy(&new_token, body_stream + bytes_read, 4);
2278
PDEBUG("CILIR:<CIL Inst %d> ldftn 0x%X\n",opcode_counter, new_token);
2279
is_invalid_basic_block = translate_cil_ldftn(system, method, cilStack, bytes_read, stack, current_binary, new_token);
2281
case LDVIRTFTN_OPCODE:
2283
print_err("CILIR: ldvirtftn instruction is not implemented. ", 0);
2287
memcpy(buffer, body_stream + bytes_read, 2);
2289
PDEBUG("CILIR:<CIL Inst %d> ldarg %d\n", opcode_counter, buffer[0]);
2290
if (is_invalid_basic_block == 1) break;
2291
is_invalid_basic_block = translate_cil_ldarg(system, method, bytes_read, *((JITUINT16 *) buffer), stack);
2294
memcpy(buffer, body_stream + bytes_read, 2);