X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=symbol.c;fp=symbol.c;h=0a50eeb6c34c77ca39db4371e50fa171fcae7c24;hp=be9282634f6cace0f44082555dbee8ce142168b3;hb=2e6a046d5d7e2c1863179c4dce8ef7505ff6dd6c;hpb=7b931ff047bf0f55fbd5ac835987958e22af8d48 diff --git a/symbol.c b/symbol.c index be92826..0a50eeb 100644 --- a/symbol.c +++ b/symbol.c @@ -1,7 +1,7 @@ // // RMAC - Renamed Macro Assembler for all Atari computers // SYMBOL.C - Symbol Handling -// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2022 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // @@ -39,7 +39,6 @@ static uint8_t tdb_text[8] = { // Internal function prototypes static uint16_t WriteLODSection(int, uint16_t); - // // Initialize symbol table // @@ -56,7 +55,6 @@ void InitSymbolTable(void) currentUID = 0; } - // // Hash the ASCII name and enviroment number // @@ -75,7 +73,6 @@ int HashSymbol(uint8_t * name, int envno) return sum & (NBUCKETS - 1); } - // // Make a new symbol of type 'type' in enviroment 'envno' // @@ -121,7 +118,6 @@ SYM * NewSymbol(uint8_t * name, int type, int envno) return symbol; } - // // Look up the symbol name by its UID and return the pointer to the name. // If it's not found, return NULL. @@ -146,7 +142,6 @@ uint8_t * GetSymbolNameByUID(uint32_t uid) return NULL; } - // // Lookup the symbol 'name', of the specified type, with the specified // enviroment level @@ -171,7 +166,6 @@ SYM * lookup(uint8_t * name, int type, int envno) return symbol; } - // // Put symbol on "order-of-declaration" list of symbols // @@ -195,7 +189,6 @@ void AddToSymbolDeclarationList(SYM * symbol) sdecltail = symbol; } - // // Make all referenced, undefined symbols global // @@ -215,7 +208,6 @@ void ForceUndefinedSymbolsGlobal(void) } } - // // Assign numbers to symbols that are to be exported or imported. The symbol // number is put in 'senv'. Returns the number of symbols that will be in the @@ -226,7 +218,7 @@ void ForceUndefinedSymbolsGlobal(void) // count of the # of symbols in the symbol table, and the second is to // actually create it. // -uint32_t sy_assign(uint8_t * buf, uint8_t *(* construct)()) +uint32_t AssignSymbolNos(uint8_t * buf, uint8_t *(* construct)()) { uint16_t scount = 0; @@ -243,10 +235,19 @@ uint32_t sy_assign(uint8_t * buf, uint8_t *(* construct)()) // them. We also pick which symbols should be global or not here. for(SYM * sy=sdecl; sy!=NULL; sy=sy->sdecl) { + // Skip non-labels + if (sy->stype != LABEL) + continue; + + // Nuke equated register/CC symbols from orbit: + if (sy->sattre & (EQUATEDREG | UNDEF_EQUR | EQUATEDCC | UNDEF_CC)) + continue; + // Export or import external references, and export COMMON blocks. - if ((sy->stype == LABEL) - && ((sy->sattr & (GLOBAL | DEFINED)) == (GLOBAL | DEFINED) - || (sy->sattr & (GLOBAL | REFERENCED)) == (GLOBAL | REFERENCED)) + // N.B.: This says to mark the symbol as global if either 1) the symbol + // is global AND the symbol is defined OR referenced, or 2) this + // symbol is a common symbol. + if (((sy->sattr & GLOBAL) && (sy->sattr & (DEFINED | REFERENCED))) || (sy->sattr & COMMON)) { sy->senv = scount++; @@ -256,8 +257,11 @@ uint32_t sy_assign(uint8_t * buf, uint8_t *(* construct)()) } // Export vanilla labels (but don't make them global). An exception is // made for equates, which are not exported unless they are referenced. - else if (sy->stype == LABEL && lsym_flag - && (sy->sattr & (DEFINED | REFERENCED)) != 0) + // ^^^ The above just might be bullshit. ^^^ + // N.B.: This says if the symbol is either defined OR referenced (but + // because of the above we know it *won't* be GLOBAL). And + // lsym_flag is always set true in Process() in rmac.c. + else if (lsym_flag && (sy->sattr & (DEFINED | REFERENCED))) { sy->senv = scount++; @@ -269,16 +273,15 @@ uint32_t sy_assign(uint8_t * buf, uint8_t *(* construct)()) return scount; } - // -// Custom version of sy_assign for ELF .o files. +// Custom version of AssignSymbolNos for ELF .o files. // The order that the symbols should be dumped is different. // (globals must be explicitly at the end of the table) // -// N.B.: It should be possible to merge this with sy_assign, as there's nothing -// really ELF specific in here, other than the "globals go at the end of -// the queue" thing, which doesn't break the others. :-P -uint32_t sy_assign_ELF(uint8_t * buf, uint8_t *(* construct)()) +// N.B.: It should be possible to merge this with AssignSymbolNos, as there's +// nothing really ELF specific in here, other than the "globals go at the +// end of the queue" thing, which doesn't break the others. :-P +uint32_t AssignSymbolNosELF(uint8_t * buf, uint8_t *(* construct)()) { uint16_t scount = 0; @@ -327,7 +330,7 @@ uint32_t sy_assign_ELF(uint8_t * buf, uint8_t *(* construct)()) } else if ((sy->sattr == (GLOBAL | REFERENCED)) && (buf != NULL) && (sy->sattre & (EQUATEDREG | UNDEF_EQUR | EQUATEDCC | UNDEF_CC)) == 0) { - buf = construct(buf, sy, 0); + buf = construct(buf, sy, 0); // <-- this creates a NON-global symbol... scount++; } } @@ -335,7 +338,6 @@ uint32_t sy_assign_ELF(uint8_t * buf, uint8_t *(* construct)()) return scount; } - // // Helper function for dsp_lod_symbols // @@ -359,7 +361,6 @@ static uint16_t WriteLODSection(int section, uint16_t symbolCount) return symbolCount; } - // // Dump LOD style symbols into the passed in buffer // @@ -382,7 +383,6 @@ void DumpLODSymbols(void) //WriteLODSection(M56001?, count); } - // // Convert string to uppercase // @@ -395,7 +395,6 @@ void ToUppercase(uint8_t * s) } } - // // Generate symbol table for listing file // @@ -548,4 +547,3 @@ int symtable(void) return 0; } -