Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- test/jit/bc-test-utils.c | 13 +++++++++++++ test/jit/bc-test-utils.h | 1 + test/jit/typeconv-bc-test.c | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/test/jit/bc-test-utils.c b/test/jit/bc-test-utils.c index fde03c8..9cddfac 100644 --- a/test/jit/bc-test-utils.c +++ b/test/jit/bc-test-utils.c @@ -182,6 +182,19 @@ void assert_conv_expr(enum vm_type expected_type, assert_ptr_equals(expected_expression, to_expr(expr->from_expression)); } +void assert_trunc_expr(enum vm_type expected_to_type, + enum expression_type expected_expr_type, + struct expression *expected_expression, + struct tree_node *node) +{ + struct expression *expr = to_expr(node); + + assert_int_equals(expected_expr_type, expr_type(expr)); + assert_int_equals(expected_to_type, expr->to_type); + assert_int_equals(J_INT, expr->vm_type); + assert_ptr_equals(expected_expression, to_expr(expr->from_expression)); +} + static void __assert_field_expr(enum expression_type expected_expr_type, enum vm_type expected_type, struct expression *expr) diff --git a/test/jit/bc-test-utils.h b/test/jit/bc-test-utils.h index c202f6c..aa945bc 100644 --- a/test/jit/bc-test-utils.h +++ b/test/jit/bc-test-utils.h @@ -32,6 +32,7 @@ void assert_binop_expr(enum vm_type, enum binary_operator, struct expression *, struct expression *, struct tree_node *); void assert_conv_expr(enum vm_type, enum expression_type, struct expression *, struct tree_node *); +void assert_trunc_expr(enum vm_type, enum expression_type, struct expression *, struct tree_node *); void assert_class_field_expr(enum vm_type, struct vm_field *, struct tree_node *); void assert_instance_field_expr(enum vm_type, struct vm_field *, struct expression *, struct tree_node *); void assert_invoke_expr(enum vm_type, struct vm_method *, diff --git a/test/jit/typeconv-bc-test.c b/test/jit/typeconv-bc-test.c index 2e8cb37..6c9dc0d 100644 --- a/test/jit/typeconv-bc-test.c +++ b/test/jit/typeconv-bc-test.c @@ -36,6 +36,33 @@ static void assert_conversion_mimic_stack(unsigned char opc, __free_simple_bb(bb); } +static void assert_truncation_mimic_stack(unsigned char opc, + enum expression_type expr_type, + enum vm_type from_type, + enum vm_type to_type) +{ + unsigned char code[] = { opc }; + struct vm_method method = { + .code_attribute.code = code, + .code_attribute.code_length = ARRAY_SIZE(code), + }; + struct expression *truncation_expression; + struct expression *expression; + struct basic_block *bb; + + bb = __alloc_simple_bb(&method); + expression = temporary_expr(from_type, bb->b_parent); + stack_push(bb->mimic_stack, expression); + convert_to_ir(bb->b_parent); + + truncation_expression = stack_pop(bb->mimic_stack); + assert_trunc_expr(to_type, expr_type, expression, &truncation_expression->node); + assert_true(stack_is_empty(bb->mimic_stack)); + + expr_put(truncation_expression); + __free_simple_bb(bb); +} + void test_convert_int_widening(void) { assert_conversion_mimic_stack(OPC_I2L, EXPR_CONVERSION, J_INT, J_LONG); @@ -66,7 +93,7 @@ void test_convert_double_conversion(void) void test_convert_int_narrowing(void) { - assert_conversion_mimic_stack(OPC_I2B, EXPR_CONVERSION, J_INT, J_BYTE); - assert_conversion_mimic_stack(OPC_I2C, EXPR_CONVERSION, J_INT, J_CHAR); - assert_conversion_mimic_stack(OPC_I2S, EXPR_CONVERSION, J_INT, J_SHORT); + assert_truncation_mimic_stack(OPC_I2B, EXPR_TRUNCATION, J_INT, J_BYTE); + assert_truncation_mimic_stack(OPC_I2C, EXPR_TRUNCATION, J_INT, J_CHAR); + assert_truncation_mimic_stack(OPC_I2S, EXPR_TRUNCATION, J_INT, J_SHORT); } -- 1.6.0.6 ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel