make data handling a little easier

This commit is contained in:
Bill Currie 2002-07-11 15:42:20 +00:00
parent 1db26eea86
commit 2df43ef941
3 changed files with 31 additions and 7 deletions

View file

@ -108,6 +108,7 @@ extern def_t def_function;
scope_t *new_scope (scope_type type, defspace_t *space, scope_t *parent); scope_t *new_scope (scope_type type, defspace_t *space, scope_t *parent);
defspace_t *new_defspace (void); defspace_t *new_defspace (void);
void defspace_adddata (defspace_t *space, pr_type_t *data, int size);
def_t *get_def (struct type_s *type, const char *name, scope_t *scope, def_t *get_def (struct type_s *type, const char *name, scope_t *scope,
storage_class_t storage); storage_class_t storage);

View file

@ -117,6 +117,18 @@ new_defspace (void)
return space; return space;
} }
void
defspace_adddata (defspace_t *space, pr_type_t *data, int size)
{
if (space->size + size > space->max_size) {
space->max_size = (space->size + size + 1023) & ~1023;
space->data = realloc (space->data,
space->max_size * sizeof (pr_type_t));
}
if (data)
memcpy (space->data, data, space->max_size * sizeof (pr_type_t));
}
scope_t * scope_t *
new_scope (scope_type type, defspace_t *space, scope_t *parent) new_scope (scope_type type, defspace_t *space, scope_t *parent)
{ {

View file

@ -53,8 +53,15 @@ static const char rcsid[] =
static hashtab_t *extern_defs; static hashtab_t *extern_defs;
static hashtab_t *defined_defs; static hashtab_t *defined_defs;
static codespace_t *code;
static defspace_t *data;
static defspace_t *far_data;
static strpool_t *strings; static strpool_t *strings;
static strpool_t *type_strings; static strpool_t *type_strings;
static int code_base;
static int data_base;
static int far_data_base;
static const char * static const char *
defs_get_key (void *_def, void *unused) defs_get_key (void *_def, void *unused)
@ -64,11 +71,6 @@ defs_get_key (void *_def, void *unused)
return G_GETSTR (def->name); return G_GETSTR (def->name);
} }
void
add_code (qfo_t *qfo)
{
}
void void
add_defs (qfo_t *qfo) add_defs (qfo_t *qfo)
{ {
@ -97,7 +99,7 @@ add_defs (qfo_t *qfo)
QFO_var (qfo, string, def->ofs) = s; QFO_var (qfo, string, def->ofs) = s;
} }
if (def->ofs) if (def->ofs)
def->ofs += pr.near_data->size; def->ofs += data_base;
if (def->flags & QFOD_GLOBAL) { if (def->flags & QFOD_GLOBAL) {
while ((d = Hash_Find (extern_defs, G_GETSTR (def->name)))) { while ((d = Hash_Find (extern_defs, G_GETSTR (def->name)))) {
Hash_Del (extern_defs, G_GETSTR (d->name)); Hash_Del (extern_defs, G_GETSTR (d->name));
@ -134,6 +136,9 @@ linker_begin (void)
{ {
extern_defs = Hash_NewTable (16381, defs_get_key, 0, 0); extern_defs = Hash_NewTable (16381, defs_get_key, 0, 0);
defined_defs = Hash_NewTable (16381, defs_get_key, 0, 0); defined_defs = Hash_NewTable (16381, defs_get_key, 0, 0);
code = codespace_new ();
data = new_defspace ();
far_data = new_defspace ();
strings = strpool_new (); strings = strpool_new ();
type_strings = strpool_new (); type_strings = strpool_new ();
} }
@ -146,10 +151,16 @@ linker_add_object_file (const char *filename)
qfo = read_obj_file (filename); qfo = read_obj_file (filename);
if (!qfo) if (!qfo)
return; return;
puts(filename); puts(filename);
code_base = code->size;
data_base = data->size;
far_data_base = far_data->size;
add_defs (qfo); add_defs (qfo);
add_functions (qfo); add_functions (qfo);
add_code (qfo); codespace_addcode (code, qfo->code, qfo->code_size);
//add_data (qfo); //add_data (qfo);
//add_far_data (qfo); //add_far_data (qfo);
//add_strings (qfo); //add_strings (qfo);