mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
Adding DEF_SAVEGLOBAL, marking globals as to-be-saved now, for real support of quicksaving
This commit is contained in:
parent
f9746a59ae
commit
b2cb612c70
3 changed files with 29 additions and 16 deletions
2
exec.c
2
exec.c
|
@ -903,7 +903,7 @@ int main(int argc, char **argv)
|
|||
if (opts_printdefs) {
|
||||
for (i = 0; i < prog->defs_count; ++i) {
|
||||
printf("Global: %8s %-16s at %u\n",
|
||||
type_name[prog->defs[i].type],
|
||||
type_name[prog->defs[i].type & DEF_TYPEMASK],
|
||||
prog_getstring(prog, prog->defs[i].name),
|
||||
(unsigned int)prog->defs[i].offset);
|
||||
}
|
||||
|
|
4
gmqcc.h
4
gmqcc.h
|
@ -390,6 +390,10 @@ typedef struct {
|
|||
typedef prog_section_both prog_section_def;
|
||||
typedef prog_section_both prog_section_field;
|
||||
|
||||
/* this is ORed to the type */
|
||||
#define DEF_SAVEGLOBAL (1<<15)
|
||||
#define DEF_TYPEMASK ((1<<15)-1)
|
||||
|
||||
typedef struct {
|
||||
int32_t entry; /* in statement table for instructions */
|
||||
uint32_t firstlocal; /* First local in local table */
|
||||
|
|
39
ir.c
39
ir.c
|
@ -2667,8 +2667,9 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
|
|||
/* I'd argue setting it to 0 is sufficient, but maybe some depend on knowing how far
|
||||
* the system fields actually go? Though the engine knows this anyway...
|
||||
* Maybe this could be an -foption
|
||||
* fteqcc creates data for end_sys_* - of size 1, so let's do the same
|
||||
*/
|
||||
ir_value_code_setaddr(global, def.offset);
|
||||
ir_value_code_setaddr(global, code_globals_add(0));
|
||||
/* Add the def */
|
||||
if (code_defs_add(def) < 0)
|
||||
return false;
|
||||
|
@ -2685,33 +2686,33 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
|
|||
/* fall through */
|
||||
case TYPE_FLOAT:
|
||||
{
|
||||
if (code_defs_add(def) < 0)
|
||||
return false;
|
||||
|
||||
if (global->isconst) {
|
||||
iptr = (int32_t*)&global->constval.vfloat;
|
||||
ir_value_code_setaddr(global, code_globals_add(*iptr));
|
||||
} else
|
||||
} else {
|
||||
ir_value_code_setaddr(global, code_globals_add(0));
|
||||
def.type |= DEF_SAVEGLOBAL;
|
||||
}
|
||||
if (code_defs_add(def) < 0)
|
||||
return false;
|
||||
|
||||
return global->code.globaladdr >= 0;
|
||||
}
|
||||
case TYPE_STRING:
|
||||
{
|
||||
if (code_defs_add(def) < 0)
|
||||
return false;
|
||||
if (global->isconst)
|
||||
ir_value_code_setaddr(global, code_globals_add(code_cachedstring(global->constval.vstring)));
|
||||
else
|
||||
else {
|
||||
ir_value_code_setaddr(global, code_globals_add(0));
|
||||
def.type |= DEF_SAVEGLOBAL;
|
||||
}
|
||||
if (code_defs_add(def) < 0)
|
||||
return false;
|
||||
return global->code.globaladdr >= 0;
|
||||
}
|
||||
case TYPE_VECTOR:
|
||||
{
|
||||
size_t d;
|
||||
if (code_defs_add(def) < 0)
|
||||
return false;
|
||||
|
||||
if (global->isconst) {
|
||||
iptr = (int32_t*)&global->constval.vvec;
|
||||
ir_value_code_setaddr(global, code_globals_add(iptr[0]));
|
||||
|
@ -2731,20 +2732,28 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
|
|||
if (code_globals_add(0) < 0)
|
||||
return false;
|
||||
}
|
||||
def.type |= DEF_SAVEGLOBAL;
|
||||
}
|
||||
|
||||
if (code_defs_add(def) < 0)
|
||||
return false;
|
||||
return global->code.globaladdr >= 0;
|
||||
}
|
||||
case TYPE_FUNCTION:
|
||||
if (code_defs_add(def) < 0)
|
||||
return false;
|
||||
if (!global->isconst) {
|
||||
ir_value_code_setaddr(global, code_globals_add(0));
|
||||
return global->code.globaladdr >= 0;
|
||||
if (global->code.globaladdr < 0)
|
||||
return false;
|
||||
} else {
|
||||
ir_value_code_setaddr(global, code_globals_elements);
|
||||
code_globals_add(code_functions_elements);
|
||||
return gen_global_function(self, global);
|
||||
if (!gen_global_function(self, global))
|
||||
return false;
|
||||
def.type |= DEF_SAVEGLOBAL;
|
||||
}
|
||||
if (code_defs_add(def) < 0)
|
||||
return false;
|
||||
return true;
|
||||
case TYPE_VARIANT:
|
||||
/* assume biggest type */
|
||||
ir_value_code_setaddr(global, code_globals_add(0));
|
||||
|
|
Loading…
Reference in a new issue