Add a param flag to defs.

It is necessary to know if a def is a function parameter so it can be
treated as initialized by the flow analyzer. The support for the flag in
object files is, at this stage, purely for debugging purposes.
This commit is contained in:
Bill Currie 2012-11-20 17:50:59 +09:00
parent a734feacfd
commit d8a5d6745f
6 changed files with 26 additions and 4 deletions

View file

@ -53,6 +53,7 @@ typedef struct def_s {
unsigned global:1; ///< globally declared def
unsigned external:1; ///< externally declared def
unsigned local:1; ///< function local def
unsigned param:1; ///< function param def
unsigned system:1; ///< system def
unsigned nosave:1; ///< don't set DEF_SAVEGLOBAL
@ -69,6 +70,7 @@ typedef enum storage_class_e {
st_system,
st_extern,
st_static,
st_param,
st_local
} storage_class_t;

View file

@ -161,6 +161,13 @@ typedef struct qfo_def_s {
\hideinitializer
*/
#define QFOD_NOSAVE (1u<<7)
/** The def is a parameter to a function and is considered to be initialized.
QFOD_LOCAL will be set too.
\hideinitializer
*/
#define QFOD_PARAM (1u<<8)
//@}
/** \addtogroup qfcc_qfo

View file

@ -72,21 +72,31 @@ set_storage_bits (def_t *def, storage_class_t storage)
def->global = 1;
def->external = 0;
def->local = 0;
def->param = 0;
break;
case st_extern:
def->global = 1;
def->external = 1;
def->local = 0;
def->param = 0;
break;
case st_static:
def->external = 0;
def->global = 0;
def->local = 0;
def->param = 0;
break;
case st_local:
def->external = 0;
def->global = 0;
def->local = 1;
def->param = 0;
break;
case st_param:
def->external = 0;
def->global = 0;
def->local = 1;
def->param = 1;
break;
}
def->initialized = 0;
@ -487,7 +497,7 @@ initialize_def (symbol_t *sym, type_t *type, expr_t *init, defspace_t *space,
}
if (type == &type_vector && options.code.vector_components)
init_vector_components (sym, 0);
if (type->type == ev_field && storage != st_local)
if (type->type == ev_field && storage != st_local && storage != st_param)
init_field_def (sym->s.def, init, storage);
if (storage == st_extern) {
if (init)

View file

@ -249,6 +249,7 @@ flags_string (pr_uint_t flags)
dstring_appendstr (str, (flags & QFOD_LOCAL) ? "L" : "-");
dstring_appendstr (str, (flags & QFOD_SYSTEM) ? "S" : "-");
dstring_appendstr (str, (flags & QFOD_NOSAVE) ? "N" : "-");
dstring_appendstr (str, (flags & QFOD_PARAM) ? "P" : "-");
return str->str;
}

View file

@ -456,7 +456,7 @@ build_scope (symbol_t *fsym, symtab_t *parent)
if (fsym->type->t.func.num_params < 0) {
args = new_symbol_type (".args", &type_va_list);
initialize_def (args, args->type, 0, symtab->space, st_local);
initialize_def (args, args->type, 0, symtab->space, st_param);
}
for (p = fsym->params, i = 0; p; p = p->next) {
@ -465,14 +465,14 @@ build_scope (symbol_t *fsym, symtab_t *parent)
if (!p->type)
continue; // non-param selector
param = new_symbol_type (p->name, p->type);
initialize_def (param, param->type, 0, symtab->space, st_local);
initialize_def (param, param->type, 0, symtab->space, st_param);
i++;
}
if (args) {
while (i < MAX_PARMS) {
param = new_symbol_type (va (".par%d", i), &type_param);
initialize_def (param, &type_param, 0, symtab->space, st_local);
initialize_def (param, &type_param, 0, symtab->space, st_param);
i++;
}
}

View file

@ -90,6 +90,8 @@ qfo_def_flags (def_t *def)
flags |= QFOD_SYSTEM;
if (def->nosave)
flags |= QFOD_NOSAVE;
if (def->param)
flags |= QFOD_PARAM;
return flags;
}