]> Shamusworld >> Repos - rmac/commitdiff
Fixed code to remove warnings. Inching closer towards zero. :-)
authorShamus Hammons <jlhamm@acm.org>
Tue, 25 Apr 2017 03:30:42 +0000 (22:30 -0500)
committerShamus Hammons <jlhamm@acm.org>
Tue, 25 Apr 2017 03:30:42 +0000 (22:30 -0500)
rmac.h
sect.c
sect.h
token.c
token.h
version.h

diff --git a/rmac.h b/rmac.h
index dcfbe5c1eebc2de576e499d8847a164523f06435..e2e677f63346d778518553b287818bbb27933483 100644 (file)
--- a/rmac.h
+++ b/rmac.h
 #define SPACE        ' '                       // ASCII space
 #define SLASHCHAR    '/'
 #define SLASHSTRING  "/"
 #define SPACE        ' '                       // ASCII space
 #define SLASHCHAR    '/'
 #define SLASHSTRING  "/"
-#define VALUE        LONG                      // Assembler value
-#define TOKEN        LONG                      // Assembler token
+#define VALUE        uint32_t          // Assembler value
+#define TOKEN        uint32_t          // Assembler token
 #define FNSIZ        128                       // Maximum size of a filename
 #define OK           0                         // OK return
 #define DEBUG        if (debug)                // Debug conditional
 #define FNSIZ        128                       // Maximum size of a filename
 #define OK           0                         // OK return
 #define DEBUG        if (debug)                // Debug conditional
diff --git a/sect.c b/sect.c
index 7a6f9e15cb0a64a4aefede0d782050b9008c7360..7bba11ce209de36016ea70274456c75321fe8b77 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -19,6 +19,9 @@
 #include "token.h"
 
 
 #include "token.h"
 
 
+// Minimum size of a fixup record
+#define MIN_FIXUP_MEM  (3 * sizeof(uint16_t) + 1 * sizeof(uint32_t))
+
 // Function prototypes
 void MakeSection(int, uint16_t);
 void SwitchSection(int);
 // Function prototypes
 void MakeSection(int, uint16_t);
 void SwitchSection(int);
@@ -75,18 +78,16 @@ static uint8_t fusizoffs[] = {
 //
 void InitSection(void)
 {
 //
 void InitSection(void)
 {
-       int i;
-
        // Cleanup all sections
        // Cleanup all sections
-       for(i=0; i<NSECTS; i++)
+       for(int i=0; i<NSECTS; i++)
                MakeSection(i, 0);
 
        // Construct default sections, make TEXT the current section
                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(M6502, SUSED | TEXT      );         // 6502 code section
+       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
        SwitchSection(TEXT);
 
        // Switch to TEXT for starters
        SwitchSection(TEXT);
@@ -116,7 +117,7 @@ void SwitchSection(int sno)
        cursect = sno;
        SECT * p = &sect[sno];
 
        cursect = sno;
        SECT * p = &sect[sno];
 
-    m6502 = (sno == M6502);    // Set 6502-mode flag
+       m6502 = (sno == M6502); // Set 6502-mode flag
 
        // Copy section vars
        scattr = p->scattr;
 
        // Copy section vars
        scattr = p->scattr;
@@ -264,66 +265,64 @@ int chcheck(uint32_t amt)
 }
 
 
 }
 
 
-// This is really wrong. We need to make some proper structures here so we
-// don't have to count sizes of objects, that's what the compiler's for! :-P
-#define FIXUP_BASE_SIZE (sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t))
+//
+// A fixup record is at least 4 pieces of data long, with some optional data at
+// the end. Is of the form:
+//
+// SYMBOL      EXPRESSION
+// ------      ----------
+// FU_EXPR.W   FU_EXPR.W        fixup type
+// loc.L       loc.L            location in section
+// fileno.W    fileno.W         file number fixup occurred in
+// lineno.W    lineno.W         line number fixup occurred in
+// symbol.*    size.W           &symbol (32 or 64 bits) / size of expression
+//             token.L          size (zero or more) TOKENS (32-bits each)
+//             ENDEXPR.L        End of expression (with size > zero)
+// JR.L                         Possible ORG address of RISC JR instruction
 //
 // Arrange for a fixup on a location
 //
 int AddFixup(uint16_t attr, uint32_t loc, TOKEN * fexpr)
 {
 //
 // Arrange for a fixup on a location
 //
 int AddFixup(uint16_t attr, uint32_t loc, TOKEN * fexpr)
 {
-       uint32_t i;
-       uint32_t len = 0;
-       CHUNK * cp;
-       SECT * p;
-       // Shamus: Expression lengths are voodoo ATM (variable "i"). Need to fix
-       //         this.
-WARNING(!!! AddFixup() is filled with VOODOO !!!)
+       uint32_t i = MIN_FIXUP_MEM;
+       uint16_t len = 0;
+
        DEBUG printf("FIXUP@$%X: $%X\n", loc, attr);
 
        // Compute length of expression (could be faster); determine if it's the
        DEBUG printf("FIXUP@$%X: $%X\n", loc, attr);
 
        // Compute length of expression (could be faster); determine if it's the
-       // single-symbol case; no expression if it's just a mark. This code assumes
-       // 16 bit WORDs and 32 bit LONGs
-       if (*fexpr == SYMBOL && fexpr[2] == ENDEXPR)
+       // single-symbol case; no expression if it's just a mark. (? is this true?)
+       if ((*fexpr == SYMBOL) && (fexpr[2] == ENDEXPR))
        {
        {
-               // Just a single symbol
-               // SCPCD : correct bit mask for attr (else other FU_xxx will match)
+               // Just a single symbol, possibly followed by a DWORD
+               i += sizeof(SYM *);
+
+               // SCPCD: Correct bit mask for attr (else other FU_xxx will match)
                // NYAN !
                if ((attr & FUMASKRISC) == FU_JR)
                // NYAN !
                if ((attr & FUMASKRISC) == FU_JR)
-               {
-//printf("AddFixup: ((attr & FUMASKRISC) == FU_JR)\n");
-//                     i = 18;
-//                     i = FIXUP_BASE_SIZE + (sizeof(uint32_t) * 2);
-                       i = FIXUP_BASE_SIZE + sizeof(SYM *) + sizeof(uint32_t);
-               }
-               else
-               {
-//printf("AddFixup: ((attr & FUMASKRISC) == FU_JR) ELSE\n");
-//                     i = 14;
-                       i = FIXUP_BASE_SIZE + sizeof(SYM *);
-               }
+                       i += sizeof(uint32_t);
        }
        else
        {
        }
        else
        {
-//printf("AddFixup: !SYMBOL\n");
                attr |= FU_EXPR;
 
                attr |= FU_EXPR;
 
+               // Count the # of tokens in the expression
                for(len=0; fexpr[len]!=ENDEXPR; len++)
                {
                for(len=0; fexpr[len]!=ENDEXPR; len++)
                {
+                       // Add one to len for 2X tokens
                        if (fexpr[len] == CONST || fexpr[len] == SYMBOL)
                                len++;
                }
 
                        if (fexpr[len] == CONST || fexpr[len] == SYMBOL)
                                len++;
                }
 
-               len++;                                                          // Add 1 for ENDEXPR
-//             i = (len << 2) + 12;
-               i = FIXUP_BASE_SIZE + sizeof(uint16_t) + (len * sizeof(TOKEN));
+               // Add 1 for ENDEXPR
+               len++;
+               i += sizeof(uint16_t) + (len * sizeof(TOKEN));
        }
 
        // Alloc another fixup chunk for this one to fit in if necessary
        if ((fchalloc - fchsize) < i)
        {
        }
 
        // Alloc another fixup chunk for this one to fit in if necessary
        if ((fchalloc - fchsize) < i)
        {
-               p = &sect[cursect];
-               cp = (CHUNK *)malloc(sizeof(CHUNK) + CH_FIXUP_SIZE);
+               SECT * p = &sect[cursect];
+               CHUNK * cp = (CHUNK *)malloc(sizeof(CHUNK) + CH_FIXUP_SIZE);
 
                // First fixup chunk in section
                if (sfix == NULL)
 
                // First fixup chunk in section
                if (sfix == NULL)
@@ -352,30 +351,30 @@ WARNING(!!! AddFixup() is filled with VOODOO !!!)
        *fchptr.wp++ = attr;
        *fchptr.lp++ = loc;
        *fchptr.wp++ = cfileno;
        *fchptr.wp++ = attr;
        *fchptr.lp++ = loc;
        *fchptr.wp++ = cfileno;
-       *fchptr.wp++ = (uint16_t)curlineno;
+       *fchptr.wp++ = curlineno;
 
        // Store postfix expression or pointer to a single symbol, or nothing for a
 
        // Store postfix expression or pointer to a single symbol, or nothing for a
-       // mark.
+       // mark (a zero word is stored in this case--[? is it?]).
        if (attr & FU_EXPR)
        {
        if (attr & FU_EXPR)
        {
-               *fchptr.wp++ = (uint16_t)len;
+               *fchptr.wp++ = len;
 
                while (len--)
 
                while (len--)
-                       *fchptr.lp++ = (uint32_t)*fexpr++;
+                       *fchptr.lp++ = *fexpr++;
        }
        else
        {
                *fchptr.sy++ = symbolPtr[fexpr[1]];
        }
        else
        {
                *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 !
-       if ((attr & FUMASKRISC) == FU_JR)
-       {
-               if (orgactive)
-                       *fchptr.lp++ = orgaddr;
-               else
-                       *fchptr.lp++ = 0x00000000;
+               // SCPCD: Correct bit mask for attr (else other FU_xxx will match)
+               // NYAN !
+               if ((attr & FUMASKRISC) == FU_JR)
+               {
+                       if (orgactive)
+                               *fchptr.lp++ = orgaddr;
+                       else
+                               *fchptr.lp++ = 0x00000000;
+               }
        }
 
        fchsize += i;
        }
 
        fchsize += i;
@@ -389,17 +388,9 @@ WARNING(!!! AddFixup() is filled with VOODOO !!!)
 int ResolveFixups(int sno)
 {
        PTR fup;                                // Current fixup
 int ResolveFixups(int sno)
 {
        PTR fup;                                // Current fixup
-       uint16_t * fuend;               // End of last fixup (in this chunk)
-       uint16_t w;                             // Fixup word (type+modes+flags)
-       uint8_t * locp;                 // Location to fix (in cached chunk)
-       uint32_t loc;                   // Location to fixup
        VALUE eval;                             // Expression value
        VALUE eval;                             // Expression value
-       uint16_t eattr;                 // Expression attrib
-       SYM * esym;                             // External symbol involved in expr
        SYM * sy;                               // (Temp) pointer to a symbol
        uint16_t i;                             // (Temp) word
        SYM * sy;                               // (Temp) pointer to a symbol
        uint16_t i;                             // (Temp) word
-       uint16_t tdb;                   // eattr & TDB
-       uint32_t oaddr;
        int reg2;
        uint16_t flags;
 
        int reg2;
        uint16_t flags;
 
@@ -416,23 +407,21 @@ int ResolveFixups(int sno)
        if (cch == NULL)
                return 0;
 
        if (cch == NULL)
                return 0;
 
-       /*
-        *  Wire the 6502 segment's size to its allocated size (64K)
-        */
+       // Wire the 6502 segment's size to its allocated size (64K)
        if (sno == M6502)
                cch->ch_size = cch->challoc;
 
        do
        {
                fup.cp = ch->chptr;                                     // fup -> start of chunk
        if (sno == M6502)
                cch->ch_size = cch->challoc;
 
        do
        {
                fup.cp = ch->chptr;                                     // fup -> start of chunk
-               fuend = (uint16_t *)(fup.cp + ch->ch_size);     // fuend -> end of chunk
+               uint16_t * fuend = (uint16_t *)(fup.cp + ch->ch_size);  // fuend -> end of chunk
 
                while (fup.wp < fuend)
                {
 
                while (fup.wp < fuend)
                {
-                       w = *fup.wp++;
-                       loc = *fup.lp++;
+                       uint16_t w = *fup.wp++;         // Fixup word (type+modes+flags)
+                       uint32_t loc = *fup.lp++;       // Location to fixup
                        cfileno = *fup.wp++;
                        cfileno = *fup.wp++;
-                       curlineno = (int)*fup.wp++;
+                       curlineno = *fup.wp++;
                        DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); }
 
                        // This is based on global vars cfileno, curfname :-P
                        DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); }
 
                        // This is based on global vars cfileno, curfname :-P
@@ -440,7 +429,7 @@ int ResolveFixups(int sno)
                        // than this.
                        SetFilenameForErrorReporting();
 
                        // than this.
                        SetFilenameForErrorReporting();
 
-                       esym = NULL;
+                       SYM * esym = NULL;                      // External symbol involved in expr
 
                        // Search for chunk containing location to fix up; compute a
                        // pointer to the location (in the chunk). Often we will find the
 
                        // Search for chunk containing location to fix up; compute a
                        // pointer to the location (in the chunk). Often we will find the
@@ -462,8 +451,9 @@ int ResolveFixups(int sno)
                                }
                        }
 
                                }
                        }
 
-                       locp = cch->chptr + (loc - cch->chloc);
-                       eattr = 0;
+                       // Location to fix (in cached chunk)
+                       uint8_t * locp = cch->chptr + (loc - cch->chloc);
+                       uint16_t eattr = 0;                     // Expression attrib
 
                        // Compute expression/symbol value and attribs
 
 
                        // Compute expression/symbol value and attribs
 
@@ -496,7 +486,7 @@ int ResolveFixups(int sno)
                                        esym = sy;
                        }
 
                                        esym = sy;
                        }
 
-                       tdb = (uint16_t)(eattr & TDB);
+                       uint16_t tdb = eattr & TDB;
 
                        // If the expression is undefined and no external symbol is
                        // involved, then that's an error.
 
                        // If the expression is undefined and no external symbol is
                        // involved, then that's an error.
@@ -542,7 +532,7 @@ int ResolveFixups(int sno)
                        }
 
                        // Do fixup classes
                        }
 
                        // Do fixup classes
-                       switch ((int)(w & FUMASK))
+                       switch (w & FUMASK)
                        {
                        // FU_BBRA fixes up a one-byte branch offset.
                        case FU_BBRA:
                        {
                        // FU_BBRA fixes up a one-byte branch offset.
                        case FU_BBRA:
@@ -621,12 +611,12 @@ int ResolveFixups(int sno)
                        case FU_WORD:
                                if ((w & FUMASKRISC) == FU_JR)
                                {
                        case FU_WORD:
                                if ((w & FUMASKRISC) == FU_JR)
                                {
-                                       oaddr = *fup.lp++;
+                                       uint32_t orgaddr = *fup.lp++;
 
 
-                                       if (oaddr)
-                                               reg2 = (signed)((eval - (oaddr + 2)) / 2);// & 0x1F;
+                                       if (orgaddr)
+                                               reg2 = (signed)((eval - (orgaddr + 2)) / 2);
                                        else
                                        else
-                                               reg2 = (signed)((eval - (loc + 2)) / 2);// & 0x1F;
+                                               reg2 = (signed)((eval - (loc + 2)) / 2);
 
                                        if ((reg2 < -16) || (reg2 > 15))
                                        {
 
                                        if ((reg2 < -16) || (reg2 > 15))
                                        {
diff --git a/sect.h b/sect.h
index 65264ae313e4113c7452ac8430f3c66794c6a380..ccb81b1c0ec7a785fe218eda3bfe83468c863341 100644 (file)
--- a/sect.h
+++ b/sect.h
@@ -59,7 +59,7 @@
 // token.L     expression list
 // (etc)
 // ENDEXPR.L   (end of expression)
 // token.L     expression list
 // (etc)
 // ENDEXPR.L   (end of expression)
-#define FUMASK       0x000F            // Mask for fixup cases:(shouldn't this be $7F?)
+#define FUMASK       0x000F            // Mask for fixup cases:
 #define FU_QUICK     0x0000            // Fixup 3-bit quick instruction field
 #define FU_BYTE      0x0001            // Fixup byte
 #define FU_WORD      0x0002            // Fixup word
 #define FU_QUICK     0x0000            // Fixup 3-bit quick instruction field
 #define FU_BYTE      0x0001            // Fixup byte
 #define FU_WORD      0x0002            // Fixup word
diff --git a/token.c b/token.c
index 0887d93b1b47bc29e0d24cf9064c6e5cf96c8c71..81a040a958aefc6971baf53ef30f8186cbc3e070 100644 (file)
--- a/token.c
+++ b/token.c
@@ -20,7 +20,7 @@
 
 
 int lnsave;                                    // 1; strcpy() text of current line
 
 
 int lnsave;                                    // 1; strcpy() text of current line
-int curlineno;                         // Current line number
+uint16_t curlineno;                    // Current line number (64K max currently)
 int totlines;                          // Total # of lines
 int mjump_align = 0;           // mjump alignment flag
 char lntag;                                    // Line tag
 int totlines;                          // Total # of lines
 int mjump_align = 0;           // mjump alignment flag
 char lntag;                                    // Line tag
@@ -517,9 +517,9 @@ DEBUG printf("ExM: SYMBOL=\"%s\"", d);
                                                                *dst++ = '"';
                                                                continue;
                                                                break;
                                                                *dst++ = '"';
                                                                continue;
                                                                break;
-// Shamus: Changing the format specifier from %lx to %ux caused
-//         the assembler to choke on legitimate code... Need to investigate
-//         this further before changing anything else here!
+// Shamus: Changing the format specifier from %lx to %ux caused the assembler
+//         to choke on legitimate code... Need to investigate this further
+//         before changing anything else here!
                                                        case CONST:
                                                                sprintf(numbuf, "$%lx", (LONG)*tk++);
                                                                d = numbuf;
                                                        case CONST:
                                                                sprintf(numbuf, "$%lx", (LONG)*tk++);
                                                                d = numbuf;
@@ -1567,17 +1567,12 @@ goteol:
 // expansion, and is NOT subject to macro expansion.  The whitespace may also
 // be EOL.
 //
 // expansion, and is NOT subject to macro expansion.  The whitespace may also
 // be EOL.
 //
-//int d_goto(WORD siz) {
-//int d_goto(void)
 int d_goto(WORD unused)
 {
 int d_goto(WORD unused)
 {
-       char * s1, * s2;
-
        // Setup for the search
        if (*tok != SYMBOL)
                return error("missing label");
 
        // Setup for the search
        if (*tok != SYMBOL)
                return error("missing label");
 
-//     sym = (char *)tok[1];
        char * sym = string[tok[1]];
        tok += 2;
 
        char * sym = string[tok[1]];
        tok += 2;
 
@@ -1585,39 +1580,35 @@ int d_goto(WORD unused)
                return error("goto not in macro");
 
        IMACRO * imacro = cur_inobj->inobj.imacro;
                return error("goto not in macro");
 
        IMACRO * imacro = cur_inobj->inobj.imacro;
-//     defln = (LONG *)imacro->im_macro->svalue;
        struct LineList * defln = imacro->im_macro->lineList;
 
        struct LineList * defln = imacro->im_macro->lineList;
 
-       // Find the label, starting with the first line.
+       // Attempt to find the label, starting with the first line.
        for(; defln!=NULL; defln=defln->next)
        {
        for(; defln!=NULL; defln=defln->next)
        {
-//             if (*(char *)(defln + 1) == ':')
+               // Must start with a colon
                if (defln->line[0] == ':')
                {
                        // Compare names (sleazo string compare)
                if (defln->line[0] == ':')
                {
                        // Compare names (sleazo string compare)
-                       // This string compare is not right. Doesn't check for lengths.
-                       // (actually it does, but in a crappy, unclear way.)
-WARNING(!!!! Bad string comparison !!!)
-                       s1 = sym;
-//                     s2 = (char *)(defln + 1) + 1;
-                       s2 = defln->line;
-
-                       while (*s1 == *s2)
+                       char * s1 = sym;
+                       char * s2 = defln->line;
+
+                       // Either we will match the strings to EOS on both, or we will
+                       // match EOS on string 1 to whitespace on string 2. Otherwise, we
+                       // have no match.
+                       while ((*s1 == *s2) || ((*s1 == EOS) && (chrtab[*s2] & WHITE)))
                        {
                        {
+                               // If we reached the end of string 1 (sym), we're done.
+                               // Note that we're also checking for the end of string 2 as
+                               // well, since we've established they're equal above.
                                if (*s1 == EOS)
                                if (*s1 == EOS)
-                                       break;
-                               else
                                {
                                {
-                                       s1++;
-                                       s2++;
+                                       // Found the label, set new macro next-line and return.
+                                       imacro->im_nextln = defln;
+                                       return 0;
                                }
                                }
-                       }
 
 
-                       // Found the label, set new macro next-line and return.
-                       if ((*s2 == EOS) || ((int)chrtab[*s2] & WHITE))
-                       {
-                               imacro->im_nextln = defln;
-                               return 0;
+                               s1++;
+                               s2++;
                        }
                }
        }
                        }
                }
        }
diff --git a/token.h b/token.h
index 91230e5f0182ff86ec789ac81de9ba3dccc83e3d..4ea67028f5c5ffada4e0092b7da0fc4db0fce822 100644 (file)
--- a/token.h
+++ b/token.h
@@ -138,7 +138,7 @@ IREPT {
 
 // Exported variables
 extern int lnsave;
 
 // Exported variables
 extern int lnsave;
-extern int curlineno;
+extern uint16_t curlineno;
 extern char * curfname;
 extern WORD cfileno;
 extern TOKEN * tok;
 extern char * curfname;
 extern WORD cfileno;
 extern TOKEN * tok;
index c87b6fe5649c944f46e0530c44daf3016d423954..0d9cda684b596440a5c5ae001ff7b4d22fea0963 100644 (file)
--- a/version.h
+++ b/version.h
@@ -15,7 +15,7 @@
 
 #define MAJOR   1              // Major version number
 #define MINOR   6              // Minor version number
 
 #define MAJOR   1              // Major version number
 #define MINOR   6              // Minor version number
-#define PATCH   4              // Patch release number
+#define PATCH   5              // Patch release number
 
 #endif // __VERSION_H__
 
 
 #endif // __VERSION_H__