diff --git a/assemble_aux.c b/assemble_aux.c index 1d92a0c..bc135cb 100644 --- a/assemble_aux.c +++ b/assemble_aux.c @@ -213,8 +213,9 @@ void implicit_gbl( /* Either make the undefined symbol into an implicit global */ add_sym(value->data.symbol->label, 0, SYMBOLFLAG_GLOBAL, &absolute_section, &implicit_st); } else { - /* or add it to the symbol table, purely for listing purposes. */ - add_sym(value->data.symbol->label, 0, SYMBOLFLAG_UNDEFINED, &absolute_section, &symbol_st); + /* or add it to the undefined symbol table, + purely for listing purposes. */ + add_sym(value->data.symbol->label, 0, SYMBOLFLAG_UNDEFINED, &absolute_section, &undefined_st); } } } @@ -265,6 +266,28 @@ void migrate_implicit( } } +/* Done between second pass and listing */ +/* Migrates the symbols from the "undefined" table into the main table. */ + +void migrate_undefined( + void) +{ + SYMBOL_ITER iter; + SYMBOL *isym, + *sym; + + for (isym = first_sym(&undefined_st, &iter); isym != NULL; isym = next_sym(&undefined_st, &iter)) { + sym = lookup_sym(isym->label, &symbol_st); + if (sym) { + continue; /* It's already in there. Great. */ + } + isym->flags |= SYMBOLFLAG_UNDEFINED; /* Just in case */ + sym = add_sym(isym->label, isym->value, isym->flags, isym->section, &symbol_st); + /* Just one other thing - migrate the stmtno */ + sym->stmtno = isym->stmtno; + } +} + int express_sym_offset( EX_TREE *value, SYMBOL **sym, diff --git a/assemble_aux.h b/assemble_aux.h index 98ab12a..f5727e6 100644 --- a/assemble_aux.h +++ b/assemble_aux.h @@ -85,7 +85,7 @@ void write_globals( FILE *obj); void migrate_implicit( void); - - +void migrate_undefined( + void); #endif diff --git a/macro11.c b/macro11.c index 3eba161..4debd12 100644 --- a/macro11.c +++ b/macro11.c @@ -417,6 +417,7 @@ int main( fprintf(stderr, "%d Errors\n", errcount); if (lstfile) { + migrate_undefined(); /* Migrate the undefined symbols */ list_symbol_table(); } diff --git a/symbols.c b/symbols.c index a00907b..64411db 100644 --- a/symbols.c +++ b/symbols.c @@ -30,6 +30,8 @@ SYMBOL_TABLE macro_st; /* Macros */ SYMBOL_TABLE implicit_st; /* The symbols which may be implicit globals */ +SYMBOL_TABLE undefined_st; /* The symbols which may be undefined */ + void list_section(SECTION *sec); diff --git a/symbols.h b/symbols.h index 94b4909..42e0a6c 100644 --- a/symbols.h +++ b/symbols.h @@ -370,6 +370,8 @@ extern SYMBOL_TABLE macro_st; /* Macros */ extern SYMBOL_TABLE implicit_st; /* The symbols which may be implicit globals */ +extern SYMBOL_TABLE undefined_st; /* The symbols which may be undefined */ + #endif int hash_name(