From: Dale Weiler Date: Wed, 2 May 2012 19:48:00 +0000 (-0400) Subject: argsize parsing for assembler X-Git-Tag: 0.1-rc1~514^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fbe86450dcee3fd4c3c10add22aa71fa89c02d3d;p=xonotic%2Fgmqcc.git argsize parsing for assembler --- diff --git a/asm.c b/asm.c index 4f7e396..adb7678 100644 --- a/asm.c +++ b/asm.c @@ -284,6 +284,7 @@ static GMQCC_INLINE bool asm_parse_func(const char *skip, size_t line, asm_state * the `#` (pound sign). */ int args = 0; + int size = 0; char *find = strchr(name, '#'); char *peek = find; @@ -305,7 +306,7 @@ static GMQCC_INLINE bool asm_parse_func(const char *skip, size_t line, asm_state * invalid and shouldn't be allowed. The QuakeC VM only * allows a maximum of eight arguments. */ - if (strlen(find) > 1 || *find == '9') { + if (*find == '9') { printf("invalid number of arguments, must be a valid number from 0-8\n"); mem_d(copy); mem_d(name); @@ -325,8 +326,37 @@ static GMQCC_INLINE bool asm_parse_func(const char *skip, size_t line, asm_state case '2': args++; case '1': args++; } } + /* + * We need to parse the argument size now by determining + * the argument identifer list used after the amount of + * arguments. + */ + memset(function.argsize, 0, sizeof(function.argsize)); + find ++; /* skip the number */ + while (*find == ' ' || *find == '\t') find++; + while (size < args) { + switch (*find) { + case 'V': case 'v': function.argsize[size]=3; break; + case 'S': case 's': + case 'F': case 'f': + case 'E': case 'e': function.argsize[size]=1; break; + case '\0': + printf("missing argument identifer, expected %d\n", args); + return false; + default: + printf("error invalid function argument identifier\n"); + return false; + } + size++,find++; + } + while (*find == ' ' || *find == '\t') find++; + if (*find != '\0') { + printf("too many function argument identifers expected %d\n", args); + return false; + } } else { printf("missing number of argument count in function %s\n", name); + return false; } /* @@ -360,7 +390,6 @@ static GMQCC_INLINE bool asm_parse_func(const char *skip, size_t line, asm_state def.type = TYPE_FUNCTION; def.offset = code_globals_elements; def.name = code_chars_elements; - memset(function.argsize, 0, sizeof(function.argsize)); code_functions_add(function); code_globals_add(code_statements_elements); code_chars_put (name, strlen(name)); diff --git a/code.c b/code.c index fe0833e..4c35b32 100644 --- a/code.c +++ b/code.c @@ -208,7 +208,7 @@ void code_write() { util_debug("GEN", "FUNCTIONS:\n"); for (; it < code_functions_elements; it++) { size_t j = code_functions_data[it].entry; - util_debug("GEN", " {.entry =% 5d, .firstlocal =% 5d, .locals =% 5d, .profile =% 5d, .name =% 5d, .file =% 5d, .nargs =% 5d, .argsize =%0X }\n", + util_debug("GEN", " {.entry =% 5d, .firstlocal =% 5d, .locals =% 5d, .profile =% 5d, .name =% 5d, .file =% 5d, .nargs =% 5d, .argsize ={%d,%d,%d,%d,%d,%d,%d,%d} }\n", code_functions_data[it].entry, code_functions_data[it].firstlocal, code_functions_data[it].locals, @@ -216,7 +216,15 @@ void code_write() { code_functions_data[it].name, code_functions_data[it].file, code_functions_data[it].nargs, - *((int32_t*)&code_functions_data[it].argsize) + code_functions_data[it].argsize[0], + code_functions_data[it].argsize[1], + code_functions_data[it].argsize[2], + code_functions_data[it].argsize[3], + code_functions_data[it].argsize[4], + code_functions_data[it].argsize[5], + code_functions_data[it].argsize[6], + code_functions_data[it].argsize[7] + ); util_debug("GEN", " NAME: %s\n", &code_chars_data[code_functions_data[it].name]); /* Internal functions have no code */ diff --git a/data/test.qs b/data/test.qs index b714ba1..0852b50 100644 --- a/data/test.qs +++ b/data/test.qs @@ -89,14 +89,13 @@ FUNCTION: checkextension, $99 ;code_chars_put("m_toggle", 0x8); ;code_chars_put("m_shutdown", 0xA); -FUNCTION: m_init #1 +FUNCTION: m_init #3VVV DONE -FUNCTION: m_keydown #1 +FUNCTION: m_keydown #1S DONE -FUNCTION: m_draw #1 +FUNCTION: m_draw #1S DONE -FUNCTION: m_toggle #1 - DONE -FUNCTION: m_shutdown #1 +FUNCTION: m_toggle #1S DONE +FUNCTION: m_shutdown #1S