mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-19 17:01:46 +00:00
add a global flag to def_t to make checking easier
rename pr.globals to pr.near_data and add pr.far_data
This commit is contained in:
parent
7a13e6b362
commit
1f67ea412d
9 changed files with 36 additions and 34 deletions
|
@ -47,6 +47,7 @@ typedef struct def_s {
|
|||
unsigned freed:1; // already freed from the scope
|
||||
unsigned removed:1; // already removed from the symbol table
|
||||
unsigned used:1; // unused local detection
|
||||
unsigned global:1; // globally declared def
|
||||
unsigned absolute:1; // don't relocate (for temps for shorts)
|
||||
unsigned managed:1; // managed temp
|
||||
|
||||
|
@ -73,7 +74,7 @@ typedef struct defspace_s {
|
|||
} defspace_t;
|
||||
|
||||
typedef enum {
|
||||
sc_static,
|
||||
sc_global,
|
||||
sc_params,
|
||||
sc_local,
|
||||
} scope_type;
|
||||
|
|
|
@ -61,7 +61,8 @@ typedef struct {
|
|||
dfunction_t *functions;
|
||||
int num_functions;
|
||||
|
||||
struct defspace_s *globals;
|
||||
struct defspace_s *near_data;
|
||||
struct defspace_s *far_data;
|
||||
struct scope_s *scope;
|
||||
|
||||
int size_fields;
|
||||
|
@ -77,13 +78,14 @@ extern int pr_source_line;
|
|||
extern struct scope_s *current_scope;
|
||||
extern int pr_error_count;
|
||||
|
||||
#define G_var(t, o) (pr.globals->data[o].t##_var)
|
||||
#define G_var(t, o) (pr.near_data->data[o].t##_var)
|
||||
#define G_FLOAT(o) G_var (float, o)
|
||||
#define G_INT(o) G_var (integer, o)
|
||||
#define G_VECTOR(o) G_var (vector, o)
|
||||
#define G_STRING(o) (pr.strings + G_var (string, o))
|
||||
#define G_FUNCTION(o) G_var (func, o)
|
||||
#define G_STRUCT(t,o) (*(t *)&pr.globals->data[o])
|
||||
#define G_POINTER(t,o) ((t *)(pr.near_data->data + o))
|
||||
#define G_STRUCT(t,o) (*G_POINTER (t, o))
|
||||
|
||||
extern string_t s_file; // filename for function definition
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ check_for_name (type_t *type, const char *name, scope_t *scope, int allocate)
|
|||
}
|
||||
if (!name)
|
||||
return 0;
|
||||
if (scope->type == sc_static && (find_struct (name) || get_enum (name))) {
|
||||
if (scope->type == sc_global && (find_struct (name) || get_enum (name))) {
|
||||
error (0, "%s redeclared", name);
|
||||
return 0;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ get_def (type_t *type, const char *name, scope_t *scope, int allocate)
|
|||
size = type_size (type->aux_type);
|
||||
scope->space->size += type->num_parms * size;
|
||||
|
||||
if (scope->type != sc_static) {
|
||||
if (scope->type >= sc_params) {
|
||||
expr_t *e1 = new_expr ();
|
||||
expr_t *e2 = new_expr ();
|
||||
|
||||
|
@ -247,6 +247,7 @@ new_def (type_t *type, const char *name, scope_t *scope)
|
|||
def->type = type;
|
||||
|
||||
def->scope = scope;
|
||||
def->global = scope->type == sc_global;
|
||||
|
||||
def->file = s_file;
|
||||
def->line = pr_source_line;
|
||||
|
|
|
@ -221,9 +221,9 @@ emit_assign_expr (int oper, expr_t *e)
|
|||
if (def_a->constant) {
|
||||
if (options.code.cow) {
|
||||
int size = type_size (def_a->type);
|
||||
int ofs = new_location (def_a->type, pr.globals);
|
||||
int ofs = new_location (def_a->type, pr.near_data);
|
||||
|
||||
memcpy (pr.globals->data + ofs, pr.globals->data + def_a->ofs,
|
||||
memcpy (G_POINTER (void, ofs), G_POINTER (void, def_a->ofs),
|
||||
size);
|
||||
def_a->ofs = ofs;
|
||||
def_a->constant = 0;
|
||||
|
|
|
@ -141,7 +141,7 @@ convert_name (expr_t *e)
|
|||
}
|
||||
d = get_def (NULL, name, current_scope, 0);
|
||||
if (d) {
|
||||
if (d->scope->type == sc_static) {
|
||||
if (d->global) {
|
||||
new = class_ivar_expr (current_class, name);
|
||||
if (new)
|
||||
goto convert;
|
||||
|
@ -327,7 +327,7 @@ check_initialized (expr_t *e)
|
|||
if (options.warnings.uninited_variable) {
|
||||
if (e->type == ex_def
|
||||
&& !(e->e.def->type->type == ev_func
|
||||
&& e->e.def->scope->type == sc_static)
|
||||
&& e->e.def->global)
|
||||
&& !e->e.def->initialized) {
|
||||
warning (e, "%s may be used uninitialized", e->e.def->name);
|
||||
e->e.def->initialized = 1; // only warn once
|
||||
|
@ -569,7 +569,7 @@ print_expr (expr_t *e)
|
|||
case ex_def:
|
||||
if (e->e.def->name)
|
||||
printf ("%s", e->e.def->name);
|
||||
if (e->e.def->scope->type != sc_static) {
|
||||
if (!e->e.def->global) {
|
||||
printf ("<%d>", e->e.def->ofs);
|
||||
} else {
|
||||
printf ("[%d]", e->e.def->ofs);
|
||||
|
@ -1790,7 +1790,7 @@ address_expr (expr_t *e1, expr_t *e2, type_t *t)
|
|||
case ex_def:
|
||||
type = e1->e.def->type;
|
||||
if (type->type == ev_struct) {
|
||||
int abs = e1->e.def->scope->type == sc_static;
|
||||
int abs = e1->e.def->global;
|
||||
def_t *def = e1->e.def;
|
||||
|
||||
e = e1;
|
||||
|
|
|
@ -276,7 +276,7 @@ ReuseConstant (expr_t *expr, def_t *def)
|
|||
}
|
||||
} else {
|
||||
cn = new_def (type, ".imm", pr.scope);
|
||||
cn->ofs = new_location (type, pr.globals);
|
||||
cn->ofs = new_location (type, pr.near_data);
|
||||
if (type == &type_vector || type == &type_quaternion) {
|
||||
int i;
|
||||
|
||||
|
@ -289,7 +289,7 @@ ReuseConstant (expr_t *expr, def_t *def)
|
|||
if (e.type == ex_string)
|
||||
e.e.integer_val = ReuseString (rep->str);
|
||||
|
||||
memcpy (pr.globals->data + cn->ofs, &e.e, 4 * type_size (type));
|
||||
memcpy (G_POINTER (void, cn->ofs), &e.e, 4 * type_size (type));
|
||||
|
||||
Hash_Add (tab, cn);
|
||||
|
||||
|
|
|
@ -263,7 +263,7 @@ selector_def (const char *_sel_id, const char *_sel_types)
|
|||
sel_def->sel_types = sel_types;
|
||||
sel_def->def = new_def (type_SEL.aux_type, ".imm", pr.scope);
|
||||
sel_def->def->initialized = sel_def->def->constant = 1;
|
||||
sel_def->def->ofs = new_location (type_SEL.aux_type, pr.globals);
|
||||
sel_def->def->ofs = new_location (type_SEL.aux_type, pr.near_data);
|
||||
G_INT (sel_def->def->ofs) = sel_id;
|
||||
G_INT (sel_def->def->ofs + 1) = sel_types;
|
||||
Hash_AddElement (sel_def_hash, sel_def);
|
||||
|
|
|
@ -340,7 +340,7 @@ def_item
|
|||
: def_name opt_initializer
|
||||
{
|
||||
$$ = $1;
|
||||
if ($$ && $$->scope->type == sc_static
|
||||
if ($$ && $$->global
|
||||
&& $$->type->type != ev_func)
|
||||
def_initialized ($$);
|
||||
}
|
||||
|
@ -351,11 +351,9 @@ def_name
|
|||
{
|
||||
if (current_scope->type == sc_local
|
||||
&& current_scope->parent->type == sc_params) {
|
||||
scope_t *scope;
|
||||
def_t *def = get_def (0, $1, current_scope, 0);
|
||||
if (def) {
|
||||
scope = def->scope;
|
||||
if (scope->type == sc_params)
|
||||
if (def->scope->type == sc_params)
|
||||
warning (0, "local %s shadows param %s", $1, def->name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,9 +108,9 @@ InitData (void)
|
|||
pr.strofs = 1;
|
||||
pr.num_functions = 1;
|
||||
|
||||
pr.globals = new_defspace ();
|
||||
pr.globals->data = calloc (65536, sizeof (pr_type_t));
|
||||
pr.scope = new_scope (sc_static, pr.globals, 0);
|
||||
pr.near_data = new_defspace ();
|
||||
pr.near_data->data = calloc (65536, sizeof (pr_type_t));
|
||||
pr.scope = new_scope (sc_global, pr.near_data, 0);
|
||||
current_scope = pr.scope;
|
||||
|
||||
numglobaldefs = 1;
|
||||
|
@ -136,7 +136,7 @@ WriteData (int crc)
|
|||
fields = calloc (pr.scope->num_defs, sizeof (ddef_t));
|
||||
|
||||
for (def = pr.scope->head; def; def = def->def_next) {
|
||||
if (def->scope->type != sc_static || !def->name)
|
||||
if (!def->global || !def->name)
|
||||
continue;
|
||||
if (def->type->type == ev_func) {
|
||||
} else if (def->type->type == ev_field) {
|
||||
|
@ -153,7 +153,7 @@ WriteData (int crc)
|
|||
|
||||
if (!def->constant
|
||||
&& def->type->type != ev_func
|
||||
&& def->type->type != ev_field && def->scope->type == sc_static)
|
||||
&& def->type->type != ev_field && def->global)
|
||||
dd->type |= DEF_SAVEGLOBAL;
|
||||
dd->s_name = ReuseString (def->name);
|
||||
dd->ofs = def->ofs;
|
||||
|
@ -168,7 +168,7 @@ WriteData (int crc)
|
|||
printf ("%6i global defs\n", numglobaldefs);
|
||||
printf ("%6i locals size (%s)\n", num_localdefs, big_function);
|
||||
printf ("%6i fielddefs\n", numfielddefs);
|
||||
printf ("%6i globals\n", pr.globals->size);
|
||||
printf ("%6i globals\n", pr.near_data->size);
|
||||
printf ("%6i entity fields\n", pr.size_fields);
|
||||
}
|
||||
|
||||
|
@ -227,10 +227,10 @@ WriteData (int crc)
|
|||
SafeWrite (h, fields, numfielddefs * sizeof (ddef_t));
|
||||
|
||||
progs.ofs_globals = ftell (h);
|
||||
progs.numglobals = pr.globals->size;
|
||||
for (i = 0; i < pr.globals->size; i++)
|
||||
progs.numglobals = pr.near_data->size;
|
||||
for (i = 0; i < pr.near_data->size; i++)
|
||||
G_INT (i) = LittleLong (G_INT (i));
|
||||
SafeWrite (h, pr.globals->data, pr.globals->size * 4);
|
||||
SafeWrite (h, pr.near_data->data, pr.near_data->size * 4);
|
||||
|
||||
if (options.verbosity >= -1)
|
||||
printf ("%6i TOTAL SIZE\n", (int) ftell (h));
|
||||
|
@ -302,7 +302,7 @@ WriteData (int crc)
|
|||
void
|
||||
begin_compilation (void)
|
||||
{
|
||||
pr.globals->size = RESERVED_OFS;
|
||||
pr.near_data->size = RESERVED_OFS;
|
||||
pr.func_tail = &pr.func_head;
|
||||
|
||||
pr_error_count = 0;
|
||||
|
@ -322,7 +322,7 @@ finish_compilation (void)
|
|||
// check to make sure all functions prototyped have code
|
||||
if (options.warnings.undefined_function)
|
||||
for (d = pr.scope->head; d; d = d->def_next) {
|
||||
if (d->type->type == ev_func && d->scope->type == sc_static) {
|
||||
if (d->type->type == ev_func && d->global) {
|
||||
// function args ok
|
||||
if (d->used) {
|
||||
if (!d->initialized) {
|
||||
|
@ -343,7 +343,7 @@ finish_compilation (void)
|
|||
}
|
||||
|
||||
for (def = pr.scope->head; def; def = def->def_next) {
|
||||
if (def->scope->type < sc_params || def->absolute)
|
||||
if (def->global || def->absolute)
|
||||
continue;
|
||||
relocate_refs (def->refs, def->ofs);
|
||||
}
|
||||
|
@ -355,15 +355,15 @@ finish_compilation (void)
|
|||
num_localdefs = f->scope->space->size;
|
||||
big_function = f->def->name;
|
||||
}
|
||||
f->dfunc->parm_start = pr.globals->size;
|
||||
f->dfunc->parm_start = pr.near_data->size;
|
||||
for (def = f->scope->head; def; def = def->def_next) {
|
||||
if (def->absolute)
|
||||
continue;
|
||||
def->ofs += pr.globals->size;
|
||||
def->ofs += pr.near_data->size;
|
||||
relocate_refs (def->refs, def->ofs);
|
||||
}
|
||||
}
|
||||
pr.globals->size += num_localdefs;
|
||||
pr.near_data->size += num_localdefs;
|
||||
|
||||
for (l = pr.labels; l; l = l->next)
|
||||
relocate_refs (l->refs, l->ofs);
|
||||
|
|
Loading…
Reference in a new issue