mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 03:50: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) {
|
if (opts_printdefs) {
|
||||||
for (i = 0; i < prog->defs_count; ++i) {
|
for (i = 0; i < prog->defs_count; ++i) {
|
||||||
printf("Global: %8s %-16s at %u\n",
|
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),
|
prog_getstring(prog, prog->defs[i].name),
|
||||||
(unsigned int)prog->defs[i].offset);
|
(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_def;
|
||||||
typedef prog_section_both prog_section_field;
|
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 {
|
typedef struct {
|
||||||
int32_t entry; /* in statement table for instructions */
|
int32_t entry; /* in statement table for instructions */
|
||||||
uint32_t firstlocal; /* First local in local table */
|
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
|
/* 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...
|
* the system fields actually go? Though the engine knows this anyway...
|
||||||
* Maybe this could be an -foption
|
* 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 */
|
/* Add the def */
|
||||||
if (code_defs_add(def) < 0)
|
if (code_defs_add(def) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -2685,33 +2686,33 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global)
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case TYPE_FLOAT:
|
case TYPE_FLOAT:
|
||||||
{
|
{
|
||||||
if (code_defs_add(def) < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (global->isconst) {
|
if (global->isconst) {
|
||||||
iptr = (int32_t*)&global->constval.vfloat;
|
iptr = (int32_t*)&global->constval.vfloat;
|
||||||
ir_value_code_setaddr(global, code_globals_add(*iptr));
|
ir_value_code_setaddr(global, code_globals_add(*iptr));
|
||||||
} else
|
} else {
|
||||||
ir_value_code_setaddr(global, code_globals_add(0));
|
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;
|
return global->code.globaladdr >= 0;
|
||||||
}
|
}
|
||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
{
|
{
|
||||||
if (code_defs_add(def) < 0)
|
|
||||||
return false;
|
|
||||||
if (global->isconst)
|
if (global->isconst)
|
||||||
ir_value_code_setaddr(global, code_globals_add(code_cachedstring(global->constval.vstring)));
|
ir_value_code_setaddr(global, code_globals_add(code_cachedstring(global->constval.vstring)));
|
||||||
else
|
else {
|
||||||
ir_value_code_setaddr(global, code_globals_add(0));
|
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;
|
return global->code.globaladdr >= 0;
|
||||||
}
|
}
|
||||||
case TYPE_VECTOR:
|
case TYPE_VECTOR:
|
||||||
{
|
{
|
||||||
size_t d;
|
size_t d;
|
||||||
if (code_defs_add(def) < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (global->isconst) {
|
if (global->isconst) {
|
||||||
iptr = (int32_t*)&global->constval.vvec;
|
iptr = (int32_t*)&global->constval.vvec;
|
||||||
ir_value_code_setaddr(global, code_globals_add(iptr[0]));
|
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)
|
if (code_globals_add(0) < 0)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
def.type |= DEF_SAVEGLOBAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (code_defs_add(def) < 0)
|
||||||
|
return false;
|
||||||
return global->code.globaladdr >= 0;
|
return global->code.globaladdr >= 0;
|
||||||
}
|
}
|
||||||
case TYPE_FUNCTION:
|
case TYPE_FUNCTION:
|
||||||
if (code_defs_add(def) < 0)
|
|
||||||
return false;
|
|
||||||
if (!global->isconst) {
|
if (!global->isconst) {
|
||||||
ir_value_code_setaddr(global, code_globals_add(0));
|
ir_value_code_setaddr(global, code_globals_add(0));
|
||||||
return global->code.globaladdr >= 0;
|
if (global->code.globaladdr < 0)
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
ir_value_code_setaddr(global, code_globals_elements);
|
ir_value_code_setaddr(global, code_globals_elements);
|
||||||
code_globals_add(code_functions_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:
|
case TYPE_VARIANT:
|
||||||
/* assume biggest type */
|
/* assume biggest type */
|
||||||
ir_value_code_setaddr(global, code_globals_add(0));
|
ir_value_code_setaddr(global, code_globals_add(0));
|
||||||
|
|
Loading…
Reference in a new issue