Fixed a nasty bug that dropped symbols that shouldn't have been.
authorShamus Hammons <jlhamm@acm.org>
Sun, 1 Feb 2015 02:49:38 +0000 (20:49 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sun, 1 Feb 2015 02:49:38 +0000 (20:49 -0600)
This stemmed from the fact that EQUR symbols somehow made it on to the
symbol declaration list. If such symbol was later .equrundef'd, it would
find it's way back onto the the sdecl list *twice*, with the result
that any symbols that came after it would be summarily discarded into
the ether. Really, really bad mojo.

direct.c
expr.c
procln.c
riscasm.c
rmac.c
sect.c
symbol.c
symbol.h
version.h

index e7a23bd615bd6e45fb8e86309298e38a73f0ba15..5cdac4ca73b605c297caf6c0b870480677898fd4 100644 (file)
--- a/direct.c
+++ b/direct.c
@@ -136,7 +136,6 @@ int d_print(void)
                switch(*tok)
                {
                case STRING:
-//                     sprintf(prntstr, "%s", (char *)tok[1]);
                        sprintf(prntstr, "%s", string[tok[1]]);
                        printf("%s", prntstr);
 
@@ -203,7 +202,6 @@ int d_print(void)
        }
 
        printf("\n");
-//     println("\n");
 
        return 0;
 
@@ -229,12 +227,10 @@ int d_ccundef(void)
 
        if (*tok != SYMBOL)
        {
-//             error(syntax_error);
                error("syntax error; expected symbol");
                return ERROR;
        }
 
-//     ccname = lookup((char *)tok[1], LABEL, 0);
        ccname = lookup(string[tok[1]], LABEL, 0);
 
        // Make sure symbol is a valid ccdef
@@ -407,7 +403,6 @@ int d_even(void)
 {
        unsigned skip = (rgpu || rdsp ? orgaddr : sloc) & 0x01;
        
-//     if (sloc & 1)
        if (skip)
        {
                if ((scattr & SBSS) == 0)
@@ -581,23 +576,15 @@ int d_include(void)
        char buf[128];
        char buf1[128];
 
-       if (*tok == STRING)                                                     // Leave strings ALONE 
-#if 0
-               fn = (char *)*++tok;
-#else
+       if (*tok == STRING)                     // Leave strings ALONE 
                fn = string[*++tok];
-#endif
-       else if (*tok == SYMBOL)                                        // Try to append ".s" to symbols
+       else if (*tok == SYMBOL)        // Try to append ".s" to symbols
        {
-#if 0
-               strcpy(buf, (char *)*++tok);
-#else
                strcpy(buf, string[*++tok]);
-#endif
                fext(buf, ".s", 0);
                fn = &buf[0];
        }
-       else                                                                            // Punt if no STRING or SYMBOL 
+       else                                            // Punt if no STRING or SYMBOL 
                return error("missing filename");
 
        // Make sure the user didn't try anything like:
@@ -1114,7 +1101,6 @@ int d_comm(void)
        if (*tok != SYMBOL)
                return error("missing symbol");
 
-//     p = (char *)tok[1];
        p = string[tok[1]];
        tok += 2;
 
@@ -1273,18 +1259,10 @@ int d_cargs(void)
        {
                if (*tok == SYMBOL)
                {
-//                     p = (char *)tok[1];
                        p = string[tok[1]];
 
-#if 0
-                       if (*p == '.')
-                               env = curenv;                   // Label is local
-                       else
-                               env = 0;                                // Label is global
-#else
                        // Set env to either local (dot prefixed) or global scope
                        env = (*p == '.' ? curenv : 0);
-#endif
                        symbol = lookup(p, LABEL, env);
 
                        if (symbol == NULL)
@@ -1296,8 +1274,7 @@ int d_cargs(void)
                                return errors("multiply-defined label '%s'", p);
 
                        // Put symbol in "order of definition" list
-                       if (!(symbol->sattr & SDECLLIST))
-                               AddToSymbolOrderList(symbol);
+                       AddToSymbolDeclarationList(symbol);
 
                        symbol->sattr |= (ABS | DEFINED | EQUATED);
                        symbol->svalue = eval;
@@ -1322,7 +1299,6 @@ int d_cargs(void)
                        if (reglist(&rlist) < 0)
                                return 0;
 
-//                     for(i=0; i++<16; rlist>>=1)
                        for(i=0; i<16; i++, rlist>>=1)
                        {
                                if (rlist & 1)
@@ -1414,8 +1390,7 @@ int d_cstruct(void)
                                return errors("multiply-defined label '%s'", symbolName);
 
                        // Put symbol in "order of definition" list
-                       if (!(symbol->sattr & SDECLLIST))
-                               AddToSymbolOrderList(symbol);
+                       AddToSymbolDeclarationList(symbol);
 
                        tok += 2;
 
diff --git a/expr.c b/expr.c
index 5c7fc8760437375850a2b60ee4496ab8cee60def..deeea40a893300bba19bf3b587b18b78ad47a072 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -360,7 +360,7 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym)
                        j = (*p == '.' ? curenv : 0);
                        symbol = lookup(p, LABEL, j);
 #if 0
-printf("eval: Looking up symbol [=%08X]\n", symbol);
+printf("eval: Looking up symbol (%s) [=%08X]\n", p, symbol);
 if (symbol)
        printf("      attr=%04X, attre=%08X, val=%i, name=%s\n", symbol->sattr, symbol->sattre, symbol->svalue, symbol->sname);
 #endif
@@ -416,7 +416,6 @@ thrown away right here. What the hell is it for?
 */
                        if (symbol->sattre & EQUATEDREG) 
                                *a_value &= 0x1F;
-
                        *a_attr = (WORD)(symbol->sattr & ~GLOBAL);
 
                        if ((symbol->sattr & (GLOBAL | DEFINED)) == GLOBAL && a_esym != NULL)
index d849b000c4b416b82d08a24e5cf4a0448c9260f7..44b94d698332703eca6e06b0f5a784b7e086f9b5 100644 (file)
--- a/procln.c
+++ b/procln.c
@@ -371,7 +371,7 @@ normal:
                        {
 //REALLY?                              sy->sattre |= ~UNDEF_EQUR; 
                                sy->sattre &= ~UNDEF_EQUR; 
-                               sy->svalue  = 0;
+                               sy->svalue = 0;
                        }
                        else if ((equtyp == CCDEF) && (sy->sattre & UNDEF_CC))
                        {
@@ -386,9 +386,8 @@ normal:
                        }
                }
 
-               // Put symbol in "order of definition" list
-               if (!(sy->sattr & SDECLLIST))
-                       AddToSymbolOrderList(sy);
+               // Put symbol in "order of definition" list if it's not already there
+               AddToSymbolDeclarationList(sy);
 
                // Parse value to equate symbol to;
                // o  .equr
@@ -694,9 +693,8 @@ int HandleLabel(char * label, int labelType)
        else if (symbol->sattr & DEFINED)
                return errors("multiply-defined label '%s'", label);
 
-       // Put symbol in "order of definition" list
-       if (!(symbol->sattr & SDECLLIST))
-               AddToSymbolOrderList(symbol);
+       // Put symbol in "order of definition" list if it's not already in it
+       AddToSymbolDeclarationList(symbol);
 
        if (orgactive)
        {
index b4a06d7559d064f5bde2d3ac874a52d30a3fc610..d2d594b31c5a0d0ae59c94dff306321e98db271b 100644 (file)
--- a/riscasm.c
+++ b/riscasm.c
@@ -224,7 +224,8 @@ int GenerateRISCCode(int state)
                break;
 
        // Single operand instructions (Rd)
-       // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S, UNPACK
+       // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S,
+       // UNPACK
        case RI_ONE:
                reg2 = GetRegister(FU_REGTWO);
                at_eol();
@@ -232,8 +233,8 @@ int GenerateRISCCode(int state)
                break;   
 
        // Two operand instructions (Rs,Rd)
-       // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT, MMULT, 
-       // MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR
+       // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT,
+       // MMULT, MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR
        case RI_TWO:                      
                if (parm == 37)
                        altbankok = 1;                      // MOVEFA
@@ -258,7 +259,8 @@ int GenerateRISCCode(int state)
        case RI_NUM_31:
 
        // Numeric operand (n,Rd) where n = 1..32
-       // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ, RORQ
+       // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ,
+       // RORQ
        case RI_NUM_32:
                switch (type)
                {
@@ -348,7 +350,7 @@ int GenerateRISCCode(int state)
                {
                        if (eattr & TDB)
 //{
-//printf("risca: Doing rmark for RI_MOVEI (tdb=$%X)...\n", eattr & TDB);
+//printf("RISCASM: Doing rmark for RI_MOVEI (tdb=$%X)...\n", eattr & TDB);
                                rmark(cursect, sloc + 2, (eattr & TDB), (MLONG | MMOVEI), NULL);
 //}
                }
diff --git a/rmac.c b/rmac.c
index b2b2610d62c96bfaeef2da0feda1851b03329664..3f5a9b59758f551d53a0be14bb7d77001091f510 100644 (file)
--- a/rmac.c
+++ b/rmac.c
@@ -150,7 +150,7 @@ void DisplayHelp(void)
 void DisplayVersion(void)
 {
        printf("\nReboot's Macro Assembler for Atari Jaguar\n"
-               "Copyright (C) 199x Landon Dyer, 2011 Reboot\n"
+               "Copyright (C) 199x Landon Dyer, 2011-2015 Reboot\n"
                "V%01i.%01i.%01i %s (%s)\n\n", MAJOR, MINOR, PATCH, __DATE__, PLATFORM);
 }
 
diff --git a/sect.c b/sect.c
index 1ff54b4075e50a1d0274a355546fd089f4f00480..80acece60ac221107589a104713916b87119baef 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -80,10 +80,10 @@ void InitSection(void)
                MakeSection(i, 0);
 
        // Construct default sections, make TEXT the current section
-       MakeSection(ABS,   SUSED | SABS | SBSS);                // ABS
-       MakeSection(TEXT,  SUSED | TEXT       );                // TEXT
-       MakeSection(DATA,  SUSED | DATA       );                // DATA
-       MakeSection(BSS,   SUSED | BSS  | SBSS);                // BSS
+       MakeSection(ABS,  SUSED | SABS | SBSS);         // ABS
+       MakeSection(TEXT, SUSED | TEXT       );         // TEXT
+       MakeSection(DATA, SUSED | DATA       );         // DATA
+       MakeSection(BSS,  SUSED | BSS  | SBSS);         // BSS
 //     MakeSection(M6502, SUSED | TEXT       );                // 6502 code section
 
        // Switch to TEXT for starters
@@ -287,18 +287,21 @@ int AddFixup(WORD attr, LONG loc, TOKEN * fexpr)
                // NYAN !
                if ((attr & FUMASKRISC) == FU_JR)
                {
+//printf("AddFixup: ((attr & FUMASKRISC) == FU_JR)\n");
 //                     i = 18;
 //                     i = FIXUP_BASE_SIZE + (sizeof(LONG) * 2);
                        i = FIXUP_BASE_SIZE + sizeof(SYM *) + sizeof(LONG);
                }
                else
                {
+//printf("AddFixup: ((attr & FUMASKRISC) == FU_JR) ELSE\n");
 //                     i = 14;
                        i = FIXUP_BASE_SIZE + sizeof(SYM *);
                }
        }
        else
        {
+//printf("AddFixup: !SYMBOL\n");
                attr |= FU_EXPR;
 
                for(len=0; fexpr[len]!=ENDEXPR; len++)
@@ -312,7 +315,7 @@ int AddFixup(WORD attr, LONG loc, TOKEN * fexpr)
                i = FIXUP_BASE_SIZE + sizeof(WORD) + (len * sizeof(TOKEN));
        }
 
-       // Maybe alloc another fixup chunk for this one to fit in
+       // Alloc another fixup chunk for this one to fit in if necessary
        if ((fchalloc - fchsize) < i)
        {
                p = &sect[cursect];
@@ -360,6 +363,7 @@ int AddFixup(WORD attr, LONG loc, TOKEN * fexpr)
        {
 //             *fchptr.lp++ = (LONG)fexpr[1];
                *fchptr.sy++ = symbolPtr[fexpr[1]];
+//printf("AddFixup: adding symbol (%s) [%08X]\n", symbolPtr[fexpr[1]]->sname, symbolPtr[fexpr[1]]->sattr);
        }
 
        // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN !
@@ -402,17 +406,17 @@ int ResolveAllFixups(void)
 //
 int ResolveFixups(int sno)
 {
-       PTR fup;                                        // Current fixup
-       WORD * fuend;                           // End of last fixup (in this chunk)
-       WORD w;                                         // Fixup word (type+modes+flags)
-       char * locp;                            // Location to fix (in cached chunk) 
-       LONG loc;                                       // Location to fixup
-       VALUE eval;                                     // Expression value 
-       WORD eattr;                                     // Expression attrib
-       SYM * esym;                                     // External symbol involved in expr
-       SYM * sy;                                       // (Temp) pointer to a symbol
-       WORD i;                                         // (Temp) word
-       WORD tdb;                                       // eattr & TDB
+       PTR fup;                                // Current fixup
+       WORD * fuend;                   // End of last fixup (in this chunk)
+       WORD w;                                 // Fixup word (type+modes+flags)
+       char * locp;                    // Location to fix (in cached chunk) 
+       LONG loc;                               // Location to fixup
+       VALUE eval;                             // Expression value 
+       WORD eattr;                             // Expression attrib
+       SYM * esym;                             // External symbol involved in expr
+       SYM * sy;                               // (Temp) pointer to a symbol
+       WORD i;                                 // (Temp) word
+       WORD tdb;                               // eattr & TDB
        LONG oaddr;
        int reg2;
        WORD flags;
@@ -502,6 +506,7 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); }
 
                                if ((eattr & (GLOBAL | DEFINED)) == GLOBAL)
                                        esym = sy;
+printf("DoFixups: found symbol (%s) [%08X]\n", sy->sname, sy->sattr);
                        }
 
                        tdb = (WORD)(eattr & TDB);
@@ -895,7 +900,8 @@ DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); }
                                break;
 
                        default:
-                               interror(4);                                 // Bad fixup type
+                               // Bad fixup type--this should *never* happen!
+                               interror(4);
                                // NOTREACHED
                        }
                        continue;
index 2edf9fd2f564066ee0324a4fca2a6909aaae4475..71e7bf5948a95eb01417f5f62c9c2f87b384f7b9 100644 (file)
--- a/symbol.c
+++ b/symbol.c
@@ -170,20 +170,23 @@ SYM * lookup(char * name, int type, int envno)
 //
 // Put symbol on "order-of-declaration" list of symbols
 //
-//void sym_decl(SYM * symbol)
-void AddToSymbolOrderList(SYM * symbol)
+void AddToSymbolDeclarationList(SYM * symbol)
 {
-       if (symbol->sattr & SDECLLIST)
-               return;                                                         // Already on list
+       // Don't add if already on list, or it's an equated register/CC
+       if ((symbol->sattr & SDECLLIST)
+               || (symbol->sattre & (EQUATEDREG | UNDEF_EQUR | EQUATEDCC | UNDEF_CC)))
+               return;
 
-       symbol->sattr |= SDECLLIST;                             // Mark "already on list"
+       // Mark as "on .sdecl list"
+       symbol->sattr |= SDECLLIST;
 
        if (sdecl == NULL)
-               sdecl = symbol;                                         // First on decl-list
+               sdecl = symbol;                         // First on decl-list
        else 
-               sdecltail->sdecl = symbol;                      // Add to end of list
+               sdecltail->sdecl = symbol;      // Add to end of list
 
-       symbol->sdecl = NULL;                                   // Fix up list's tail
+       // Fix up list's tail
+       symbol->sdecl = NULL;
        sdecltail = symbol;
 }
 
@@ -238,33 +241,18 @@ int sy_assign(char * buf, char *(* constr)())
                // Append all symbols not appearing on the .sdecl list to the end of
                // the .sdecl list
                for(sy=sorder; sy!=NULL; sy=sy->sorder)
-               {
-                       // Essentially the same as 'sym_decl()' above:
-                       if (sy->sattr & SDECLLIST)
-                               continue;                               // Already on list 
-
-                       sy->sattr |= SDECLLIST;         // Mark "on the list"
-
-                       if (sdecl == NULL)
-                               sdecl = sy;                             // First on decl-list 
-                       else
-                               sdecltail->sdecl = sy;  // Add to end of list
-
-                       sy->sdecl = NULL;                       // Fix up list's tail
-                       sdecltail = sy;
-               }
+                       AddToSymbolDeclarationList(sy);
        }
 
        // Run through all symbols (now on the .sdecl list) and assign numbers to
        // them. We also pick which symbols should be global or not here.
        for(sy=sdecl; sy!=NULL; sy=sy->sdecl)
        {
-               if (sy->sattre & UNDEF_EQUR)
-                       continue;                 // Don't want undefined on our list
+               // Don't want register/CC or undefined on our list
+//these should already be rejected above...
+//             if (sy->sattre & (EQUATEDREG | UNDEF_EQUR | EQUATEDCC | UNDEF_CC)))
+//                     continue;
 
-               if (sy->sattre & UNDEF_CC)
-                       continue;                   
-               
                // Export or import external references, and export COMMON blocks.
                if ((sy->stype == LABEL)
                        && ((sy->sattr & (GLOBAL | DEFINED)) == (GLOBAL | DEFINED)
@@ -283,7 +271,9 @@ int sy_assign(char * buf, char *(* constr)())
                        && (!as68_flag || *sy->sname != 'L'))
                {
                        sy->senv = (WORD)scount++;
-                       if (buf != NULL) buf = (*constr)(buf, sy, 0);
+
+                       if (buf != NULL)
+                               buf = (*constr)(buf, sy, 0);
                }
        }
 
index 767799e15ae802a2fe3f2845b756f89187132b01..73a2dca9622b6913ceca4cf5ae9115b154753589 100644 (file)
--- a/symbol.h
+++ b/symbol.h
@@ -44,7 +44,7 @@ extern char subttl[];
 SYM * lookup(char *, int, int);
 void InitSymbolTable(void);
 SYM * NewSymbol(char *, int, int);
-void AddToSymbolOrderList(SYM *);
+void AddToSymbolDeclarationList(SYM *);
 void ForceUndefinedSymbolsGlobal(void);
 int symtable(void);
 int sy_assign(char *, char *(*)());
index 58f9dba6baddd80445b79209eb29d814600f965a..1e4e7aea901f8fe10c243b7dfb9a68b32b83bf33 100644 (file)
--- a/version.h
+++ b/version.h
@@ -13,6 +13,6 @@
 
 #define MAJOR   1              // Major version number
 #define MINOR   3              // Minor version number
-#define PATCH   2              // Patch release number
+#define PATCH   3              // Patch release number
 
 #endif // __VERSION_H__