static void assert_convert_ldc_w_float(enum vm_type expected_type, double expected_value, uint8_t cp_type, unsigned long opcode) { unsigned char code[] = { opcode, 0x01, 0x00 }; uint32_t cp_infos[NR_CP_ENTRIES]; uint8_t cp_types[NR_CP_ENTRIES]; struct expression *expr; struct basic_block *bb; if (opcode == OPC_LDC_W) const_set_float(cp_infos, 0x100, (float) expected_value); else const_set_double(cp_infos, 0x100, expected_value); cp_types[0x100] = cp_type; bb = alloc_simple_bb(code, ARRAY_SIZE(code)); convert_ir_const(bb->b_parent, cp_infos, NR_CP_ENTRIES, cp_types); expr = stack_pop(bb->mimic_stack); assert_fvalue_expr(expected_type, expected_value, &expr->node); assert_true(stack_is_empty(bb->mimic_stack)); expr_put(expr); free_simple_bb(bb); }
static void __assert_convert_load(unsigned char *code, unsigned long code_size, enum vm_type expected_type, unsigned char expected_index) { struct expression *expr; struct statement *stmt; struct basic_block *bb; bb = alloc_simple_bb(code, code_size); convert_to_ir(bb->b_parent); expr = stack_pop(bb->mimic_stack); assert_temporary_expr(expected_type, &expr->node); stmt = stmt_entry(bb->stmt_list.next); assert_store_stmt(stmt); assert_local_expr(expected_type, expected_index, stmt->store_src); assert_ptr_equals(&expr->node, stmt->store_dest); assert_true(stack_is_empty(bb->mimic_stack)); expr_put(expr); free_simple_bb(bb); }
static void assert_dup_x2_stack(unsigned char opc, struct expression *value1, struct expression *value2, struct expression *value3) { struct basic_block *bb; struct statement *stmt; bb = alloc_simple_bb(&opc, 1); stack_push(bb->mimic_stack, expr_get(value3)); stack_push(bb->mimic_stack, expr_get(value2)); stack_push(bb->mimic_stack, expr_get(value1)); convert_to_ir(bb->b_parent); stmt = stmt_entry(bb->stmt_list.next); assert_store_stmt(stmt); assert_ptr_equals(value1, to_expr(stmt->store_src)); assert_temporary_expr(value1->vm_type, stmt->store_dest); assert_ptr_equals(to_expr(stmt->store_dest), pop_and_put_expr(bb->mimic_stack)); assert_ptr_equals(value2, pop_and_put_expr(bb->mimic_stack)); assert_ptr_equals(value3, pop_and_put_expr(bb->mimic_stack)); assert_ptr_equals(value1, pop_and_put_expr(bb->mimic_stack)); assert_true(stack_is_empty(bb->mimic_stack)); free_simple_bb(bb); }
static void assert_dup2_x2_stack(unsigned char opc, struct expression *value1, struct expression *value2, struct expression *value3, struct expression *value4) { struct statement *stmt, *stmt2; struct basic_block *bb; if (value1->vm_type == J_LONG || value1->vm_type == J_DOUBLE) { if (value2->vm_type == J_LONG || value2->vm_type == J_DOUBLE) { assert_dup_x1_stack(opc, value1, value2); return; } else { assert_dup_x2_stack(opc, value1, value2, value3); return; } } else { if (value3->vm_type == J_LONG || value3->vm_type == J_DOUBLE) { assert_dup2_x1_stack(opc, value1, value2, value3); return; } } bb = alloc_simple_bb(&opc, 1); stack_push(bb->mimic_stack, expr_get(value4)); stack_push(bb->mimic_stack, expr_get(value3)); stack_push(bb->mimic_stack, expr_get(value2)); stack_push(bb->mimic_stack, expr_get(value1)); convert_to_ir(bb->b_parent); stmt = stmt_entry(bb->stmt_list.next); stmt2 = stmt_entry(stmt->stmt_list_node.next); assert_store_stmt(stmt); assert_ptr_equals(value2, to_expr(stmt->store_src)); assert_temporary_expr(value2->vm_type, stmt->store_dest); assert_store_stmt(stmt2); assert_ptr_equals(value1, to_expr(stmt2->store_src)); assert_temporary_expr(value1->vm_type, stmt2->store_dest); assert_ptr_equals(to_expr(stmt2->store_dest), pop_and_put_expr(bb->mimic_stack)); assert_ptr_equals(to_expr(stmt->store_dest), pop_and_put_expr(bb->mimic_stack)); assert_ptr_equals(value3, pop_and_put_expr(bb->mimic_stack)); assert_ptr_equals(value4, pop_and_put_expr(bb->mimic_stack)); assert_ptr_equals(value1, pop_and_put_expr(bb->mimic_stack)); assert_ptr_equals(value2, pop_and_put_expr(bb->mimic_stack)); assert_true(stack_is_empty(bb->mimic_stack)); free_simple_bb(bb); }
static void assert_convert_fconst(enum vm_type expected_type, double expected_value, unsigned char opc) { struct expression *expr; struct basic_block *bb; bb = alloc_simple_bb(&opc, 1); convert_to_ir(bb->b_parent); expr = stack_pop(bb->mimic_stack); assert_fvalue_expr(expected_type, expected_value, &expr->node); assert_true(stack_is_empty(bb->mimic_stack)); expr_put(expr); free_simple_bb(bb); }
static void assert_swap_stack(unsigned char opc, void *value1, void *value2) { struct basic_block *bb; bb = alloc_simple_bb(&opc, 1); stack_push(bb->mimic_stack, expr_get(value1)); stack_push(bb->mimic_stack, expr_get(value2)); convert_to_ir(bb->b_parent); assert_ptr_equals(value1, pop_and_put_expr(bb->mimic_stack)); assert_ptr_equals(value2, pop_and_put_expr(bb->mimic_stack)); assert_true(stack_is_empty(bb->mimic_stack)); free_simple_bb(bb); }
static void __assert_convert_const(enum vm_type expected_type, long long expected_value, unsigned char *code, unsigned long code_size) { struct expression *expr; struct basic_block *bb; bb = alloc_simple_bb(code, code_size); convert_to_ir(bb->b_parent); expr = stack_pop(bb->mimic_stack); assert_value_expr(expected_type, expected_value, &expr->node); assert_true(stack_is_empty(bb->mimic_stack)); expr_put(expr); free_simple_bb(bb); }
static void assert_convert_ldc_w_string(enum vm_type expected_type, long long expected_value) { unsigned char code[] = { OPC_LDC_W, 0x01, 0x00 }; uint32_t cp_infos[NR_CP_ENTRIES]; uint8_t cp_types[NR_CP_ENTRIES]; struct basic_block *bb; struct expression *expr; const_set_int32_t(cp_infos, 0x100, 0x00); cp_types[0x100] = CAFEBABE_CONSTANT_TAG_STRING; bb = alloc_simple_bb(code, ARRAY_SIZE(code)); convert_ir_const(bb->b_parent, cp_infos, NR_CP_ENTRIES, cp_types); expr = stack_pop(bb->mimic_stack); assert_value_expr(expected_type, expected_value, &expr->node); assert_true(stack_is_empty(bb->mimic_stack)); expr_put(expr); free_simple_bb(bb); }
static void assert_convert_ldc_float(float expected_value) { unsigned char code[] = { OPC_LDC, 0xff }; uint32_t cp_infos[NR_CP_ENTRIES]; uint8_t cp_types[NR_CP_ENTRIES]; struct expression *expr; struct basic_block *bb; const_set_float(cp_infos, 0xff, expected_value); cp_types[0xff] = CAFEBABE_CONSTANT_TAG_FLOAT; bb = alloc_simple_bb(code, ARRAY_SIZE(code)); convert_ir_const(bb->b_parent, cp_infos, NR_CP_ENTRIES, cp_types); expr = stack_pop(bb->mimic_stack); assert_fvalue_expr(J_FLOAT, expected_value, &expr->node); assert_true(stack_is_empty(bb->mimic_stack)); expr_put(expr); free_simple_bb(bb); }
static void assert_convert_ldc(enum vm_type expected_type, long long expected_value, uint8_t cp_type) { uint32_t cp_infos[NR_CP_ENTRIES]; uint8_t cp_types[NR_CP_ENTRIES]; unsigned char code[] = { OPC_LDC, 0xff }; struct expression *expr; struct basic_block *bb; const_set_int32_t(cp_infos, 0xff, expected_value); cp_types[0xff] = cp_type; bb = alloc_simple_bb(code, ARRAY_SIZE(code)); convert_ir_const(bb->b_parent, cp_infos, NR_CP_ENTRIES, cp_types); expr = stack_pop(bb->mimic_stack); assert_value_expr(expected_type, expected_value, &expr->node); assert_true(stack_is_empty(bb->mimic_stack)); expr_put(expr); free_simple_bb(bb); }