From b2cb612c703a8135b50fbcbfcab4f9ce7df0c4ce Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Thu, 23 Aug 2012 18:28:05 +0200 Subject: [PATCH] Adding DEF_SAVEGLOBAL, marking globals as to-be-saved now, for real support of quicksaving --- exec.c | 2 +- gmqcc.h | 4 ++++ ir.c | 39 ++++++++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/exec.c b/exec.c index 666468a..bb35ee9 100644 --- a/exec.c +++ b/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); } diff --git a/gmqcc.h b/gmqcc.h index f150cf1..1584633 100644 --- a/gmqcc.h +++ b/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 */ diff --git a/ir.c b/ir.c index 4dc7914..0313fd9 100644 --- a/ir.c +++ b/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)); -- 2.39.2