This increases maintainability. After this, method arguments are parsed only by parse_method_args().
Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- test/jit/invoke-bc-test.c | 20 +++++++-- vm/types.c | 102 +++++--------------------------------------- 2 files changed, 27 insertions(+), 95 deletions(-) diff --git a/test/jit/invoke-bc-test.c b/test/jit/invoke-bc-test.c index 1d71670..c6d0634 100644 --- a/test/jit/invoke-bc-test.c +++ b/test/jit/invoke-bc-test.c @@ -8,6 +8,7 @@ #include "jit/compiler.h" #include "jit/statement.h" #include "vm/stack.h" +#include "lib/string.h" #include <args-test-utils.h> #include <libharness.h> @@ -172,9 +173,18 @@ static void assert_invoke_args(unsigned char invoke_opc, unsigned long nr_args) struct expression *second_arg; struct basic_block *bb; struct statement *stmt; + struct string *str; + + str = alloc_str(); + + str_append(str, "("); + for (int i = 0; i < nr_args; i++) + str_append(str, "I"); + str_append(str, ")V"); create_args(args, ARRAY_SIZE(args)); - bb = build_invoke_bb(invoke_opc, "()V", nr_args+1, 0, 0, 0, args); + bb = build_invoke_bb(invoke_opc, str->value, nr_args+1, 0, 0, 0, args); + free_str(str); stmt = first_stmt(bb->b_parent); invoke_expr = to_expr(stmt->expression); @@ -361,10 +371,10 @@ void test_convert_invokestatic(void) { assert_converts_to_invoke_expr(J_BYTE, OPC_INVOKESTATIC, "()B", 0); assert_converts_to_invoke_expr(J_INT, OPC_INVOKESTATIC, "()I", 0); - assert_converts_to_invoke_expr(J_INT, OPC_INVOKESTATIC, "()I", 1); - assert_converts_to_invoke_expr(J_INT, OPC_INVOKESTATIC, "()I", 2); - assert_converts_to_invoke_expr(J_INT, OPC_INVOKESTATIC, "()I", 3); - assert_converts_to_invoke_expr(J_INT, OPC_INVOKESTATIC, "()I", 5); + assert_converts_to_invoke_expr(J_INT, OPC_INVOKESTATIC, "(I)I", 1); + assert_converts_to_invoke_expr(J_INT, OPC_INVOKESTATIC, "(II)I", 2); + assert_converts_to_invoke_expr(J_INT, OPC_INVOKESTATIC, "(III)I", 3); + assert_converts_to_invoke_expr(J_INT, OPC_INVOKESTATIC, "(IIIII)I", 5); } void test_convert_invokestatic_for_void_return_type(void) diff --git a/vm/types.c b/vm/types.c index 8b64bb3..27f5c3c 100644 --- a/vm/types.c +++ b/vm/types.c @@ -5,6 +5,8 @@ #include "vm/die.h" #include "vm/vm.h" +#include "jit/args.h" + /* See Table 4.2 in Section 4.3.2 ("Field Descriptors") of the JVM specification. */ enum vm_type str_to_type(const char *type) @@ -61,101 +63,21 @@ unsigned int vm_type_size(enum vm_type type) return size[type]; } -#include <stdio.h> - -static int count_skip_arguments(const char **type); - -int skip_type(const char **type) -{ - const char *ptr = *type; - int ret = 1; - - switch (*ptr) { - /* BaseType */ - case 'B': - case 'C': - case 'F': - case 'I': - case 'S': - case 'Z': - ++ptr; - break; - - case 'D': - case 'J': - ++ptr; - ret = 2; - break; - - /* ObjectType */ - case 'L': - while (1) { - if (!*ptr) - return -1; - if (*ptr == ';') - break; - - ++ptr; - } - - ++ptr; - break; - - /* ArrayType */ - case '[': - ++ptr; - skip_type(&ptr); - ret = 1; - break; - - default: - NOT_IMPLEMENTED; - return -1; - } - - *type = ptr; - return ret; -} - -static int count_skip_arguments(const char **type) -{ - unsigned int args = 0; - const char *ptr = *type; - - while (1) { - int ret; - - if (!*ptr) - break; - - if (*ptr == ')') - break; - - ret = skip_type(&ptr); - if (ret < 0) - return -1; - - args += ret; - } - - *type = ptr; - return args; -} - int count_arguments(const char *type) { - unsigned int args = 0; + enum vm_type vmtype; + int count; - if (*type != '(') - return -1; - ++type; + count = 0; - args = count_skip_arguments(&type); - - if (*type != ')') - return -1; + while ((type = parse_method_args(type, &vmtype, NULL))) { + if (vmtype == J_LONG || vmtype == J_DOUBLE) + count += 2; + else + count++; + } - return args; + return count; } static enum vm_type bytecode_type_to_vmtype_map[] = { -- 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