204 def Expr2C(ir_arch, l, exprs, gen_exception_code=False):
206 out = [
"// %s" % (l)]
212 prefect_index = {8: 0, 16: 0, 32: 0, 64: 0}
215 e =
set_pc(ir_arch, l.offset & mask_int)
220 set_exception_flags =
False
222 assert isinstance(e, m2_expr.ExprAff)
223 assert not isinstance(e.dst, m2_expr.ExprOp)
224 if isinstance(e.dst, m2_expr.ExprId):
225 if not e.dst
in dst_dict:
227 dst_dict[e.dst].append(e)
231 ops = m2_expr.get_expr_ops(e)
232 if set([
'umod',
'udiv']).intersection(ops):
233 set_exception_flags =
True
234 if e.dst == exception_flags:
235 set_exception_flags =
True
239 rs = e.src.get_r(mem_read=
True)
241 if (
not isinstance(r, m2_expr.ExprMem))
or r
in src_mem:
244 index = prefect_index[r.size]
245 prefect_index[r.size] += 1
246 pfmem = prefetch_id_size[r.size][index]
249 for dst, exs
in dst_dict.items():
254 log_to_c_h.debug(
'warning: detected multi dst to same id')
255 log_to_c_h.debug(
'\t'.join([str(x)
for x
in exs]))
260 mem_k = src_mem.keys()
263 str_src = translator.from_expr(
patch_c_id(ir_arch.arch, k))
264 str_dst = translator.from_expr(
patch_c_id(ir_arch.arch, src_mem[k]))
265 out.append(
'%s = %s;' % (str_dst, str_src))
267 for k, v
in src_mem.items():
271 src, dst = e.src, e.dst
273 src = src.replace_expr(src_w_len)
274 if dst
is ir_arch.IRDst:
279 str_src = translator.from_expr(
patch_c_id(ir_arch.arch, src))
280 str_dst = translator.from_expr(
patch_c_id(ir_arch.arch, dst))
284 if isinstance(dst, m2_expr.ExprId):
285 id_to_update.append(dst)
287 if dst
in ir_arch.arch.regs.regs_flt_expr:
289 out.append(
'%s = (%s);' % (str_dst, str_src))
291 out.append(
'%s = (%s)&0x%X;' % (str_dst, str_src,
292 my_size_mask[src.size]))
293 elif isinstance(dst, m2_expr.ExprMem):
295 str_dst = str_dst.replace(
'MEM_LOOKUP',
'MEM_WRITE')
296 out_mem.append(
'%s, %s);' % (str_dst[:-1], str_src))
298 if e.dst == ir_arch.arch.pc[ir_arch.attrib]:
300 out_pc += [
"return JIT_RET_NO_EXCEPTION;"]
307 if gen_exception_code:
309 e =
set_pc(ir_arch, l.offset & mask_int)
310 s1 =
"%s" % translator.from_expr(
patch_c_id(ir_arch.arch, e))
311 s1 +=
';\n Resolve_dst(BlockDst, 0x%X, 0)'%(l.offset & mask_int)
312 out.append(code_exception_fetch_mem_at_instr_noautomod % s1)
313 if set_exception_flags:
314 e =
set_pc(ir_arch, l.offset & mask_int)
315 s1 =
"%s" % translator.from_expr(
patch_c_id(ir_arch.arch, e))
316 s1 +=
';\n Resolve_dst(BlockDst, 0x%X, 0)'%(l.offset & mask_int)
317 out.append(code_exception_at_instr_noautomod % s1)
319 for i
in id_to_update:
320 if i
is ir_arch.IRDst:
322 out.append(
'%s = %s;' %
327 if gen_exception_code:
328 if set_exception_flags:
330 post_instr.append(
"if (VM_exception_flag) { " +
331 "/*pc = 0x%X; */return JIT_RET_EXCEPTION; }" % (l.offset))
333 e =
set_pc(ir_arch, l.offset & mask_int)
334 s1 =
"%s" % translator.from_expr(
patch_c_id(ir_arch.arch, e))
335 s1 +=
';\n Resolve_dst(BlockDst, 0x%X, 0)'%(l.offset & mask_int)
336 e =
set_pc(ir_arch, (l.offset + l.l) & mask_int)
337 s2 =
"%s" % translator.from_expr(
patch_c_id(ir_arch.arch, e))
338 s2 +=
';\n Resolve_dst(BlockDst, 0x%X, 0)'%((l.offset + l.l) & mask_int)
340 code_exception_post_instr_noautomod % (s1, s2))
343 if l.additional_info.except_on_instr:
346 offset = l.offset + l.l
348 e =
set_pc(ir_arch, offset & mask_int)
349 s1 =
"%s" % translator.from_expr(
patch_c_id(ir_arch.arch, e))
350 s1 +=
';\n Resolve_dst(BlockDst, 0x%X, 0)'%(offset & mask_int)
352 code_exception_fetch_mem_post_instr_noautomod % (s1))
355 return out, post_instr, post_instr + out_pc