mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-03-21 10:21:03 +00:00
argsize parsing for assembler
This commit is contained in:
parent
bc318bb68e
commit
fbe86450dc
3 changed files with 46 additions and 10 deletions
33
asm.c
33
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));
|
||||
|
|
12
code.c
12
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 */
|
||||
|
|
11
data/test.qs
11
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue