Various code cleanups, mainly to do with RISC assembly.
authorShamus Hammons <jlhamm@acm.org>
Mon, 4 Mar 2013 13:36:09 +0000 (07:36 -0600)
committerShamus Hammons <jlhamm@acm.org>
Mon, 4 Mar 2013 13:36:09 +0000 (07:36 -0600)
expr.c
procln.c
riscasm.c
rmac.c
rmac.h
sect.c
version.h

diff --git a/expr.c b/expr.c
index e552c39e9becf0d853436565d7bc4d731f5730b1..0335fbd12de4f46173e5efb254b85c5302126ad3 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -20,7 +20,7 @@
 #define DEF_KW                                                 // Declare keyword values 
 #include "kwtab.h"                                             // Incl generated keyword tables & defs
 
-static char tokcl[128];                                        // Generated table of token classes
+static char tokenClass[128];                                   // Generated table of token classes
 static VALUE evstk[EVSTACKSIZE];               // Evaluator value stack
 static WORD evattr[EVSTACKSIZE];               // Evaluator attribute stack
 
@@ -48,8 +48,9 @@ const char missym_error[] = "missing symbol";
 const char str_error[] = "missing symbol or string";
 
 // Convert expression to postfix
-static TOKEN * tk;                                             // Deposit tokens here (this is really a
+static TOKEN * evalTokenBuffer;                        // Deposit tokens here (this is really a
                                                                                // pointer to exprbuf from direct.c)
+                                                                               // (Can also be from others, like riscasm.c)
 static symbolNum;                                              // Pointer to the entry in symbolPtr[]
 
 
@@ -75,16 +76,16 @@ void init_expr(void)
        int i;                                                                  // Iterator
        char * p;                                                               // Token pointer
 
-       // Initialize token-class table
-       for(i=0; i<128; i++)                                    // Mark all entries END
-               tokcl[i] = END;
+       // Initialize token-class table (all set to END)
+       for(i=0; i<128; i++)
+               tokenClass[i] = END;
 
        for(i=0, p=itokcl; *p!=1; p++)
        {
                if (*p == 0)
                        i++;
                else 
-                       tokcl[(int)(*p)] = (char)i;
+                       tokenClass[(int)(*p)] = (char)i;
        }
 
        symbolNum = 0;
@@ -101,14 +102,14 @@ int expr0(void)
        if (expr1() != OK)
                return ERROR;
        
-       while (tokcl[*tok] >= MULT)
+       while (tokenClass[*tok] >= MULT)
        {
                t = *tok++;
 
                if (expr1() != OK)
                        return ERROR;
 
-               *tk++ = t;
+               *evalTokenBuffer++ = t;
        }
 
        return OK;
@@ -127,7 +128,7 @@ int expr1(void)
        WORD w;
        int j;
 
-       class = tokcl[*tok];
+       class = tokenClass[*tok];
 
        if (*tok == '-' || class == UNARY)
        {
@@ -139,32 +140,28 @@ int expr1(void)
                if (t == '-')
                        t = UNMINUS;
 
-               *tk++ = t;
+               *evalTokenBuffer++ = t;
        }
        else if (class == SUNARY)
        {
                switch ((int)*tok++)
                {
                case CR_TIME:
-                       *tk++ = CONST;
-                       *tk++ = dos_time();
+                       *evalTokenBuffer++ = CONST;
+                       *evalTokenBuffer++ = dos_time();
                        break;
                case CR_DATE:
-                       *tk++ = CONST;
-                       *tk++ = dos_date();
+                       *evalTokenBuffer++ = CONST;
+                       *evalTokenBuffer++ = dos_date();
                        break;
                case CR_MACDEF:                                    // ^^macdef <macro-name>
                        if (*tok++ != SYMBOL)
                                return error(missym_error);
 
-#if 0
-                       p = (char *)*tok++;
-#else
                        p = string[*tok++];
-#endif
                        w = (lookup(p, MACRO, 0) == NULL ? 0 : 1);
-                       *tk++ = CONST;
-                       *tk++ = (TOKEN)w;
+                       *evalTokenBuffer++ = CONST;
+                       *evalTokenBuffer++ = (TOKEN)w;
                        break;
                case CR_DEFINED:
                        w = DEFINED;
@@ -175,29 +172,17 @@ getsym:
                        if (*tok++ != SYMBOL)
                                return error(missym_error);
 
-#if 0
-                       p = (char *)*tok++;
-#else
                        p = string[*tok++];
-#endif
-                       j = 0;
-
-                       if (*p == '.')
-                               j = curenv;
-
+                       j = (*p == '.' ? curenv : 0);
                        w = ((sy = lookup(p, LABEL, j)) != NULL && (sy->sattr & w) ? 1 : 0);
-                       *tk++ = CONST;
-                       *tk++ = (TOKEN)w;
+                       *evalTokenBuffer++ = CONST;
+                       *evalTokenBuffer++ = (TOKEN)w;
                        break;
                case CR_STREQ:
                        if (*tok != SYMBOL && *tok != STRING)
                                return error(str_error);
 
-#if 0
-                       p = (char *)tok[1];
-#else
                        p = string[tok[1]];
-#endif
                        tok +=2;
 
                        if (*tok++ != ',')
@@ -206,16 +191,12 @@ getsym:
                        if (*tok != SYMBOL && *tok != STRING)
                                return error(str_error);
 
-#if 0
-                       p2 = (char *)tok[1];
-#else
                        p = string[tok[1]];
-#endif
                        tok += 2;
 
                        w = (WORD)(!strcmp(p, p2));
-                       *tk++ = CONST;
-                       *tk++ = (TOKEN)w;
+                       *evalTokenBuffer++ = CONST;
+                       *evalTokenBuffer++ = (TOKEN)w;
                        break;
                }
        }
@@ -238,20 +219,12 @@ int expr2(void)
        switch ((int)*tok++)
        {
        case CONST:
-               *tk++ = CONST;
-               *tk++ = *tok++;
+               *evalTokenBuffer++ = CONST;
+               *evalTokenBuffer++ = *tok++;
                break;
        case SYMBOL:
-#if 0
-               p = (char *)*tok++;
-#else
                p = string[*tok++];
-#endif
-               j = 0;
-
-               if (*p == '.')
-                       j = curenv;
-
+               j = (*p == '.' ? curenv : 0);
                sy = lookup(p, LABEL, j);
 
                if (sy == NULL)
@@ -267,22 +240,18 @@ int expr2(void)
                                warns("equated symbol \'%s\' cannot be used in register bank 1", sy->sname);
                }
 
-               *tk++ = SYMBOL;
+               *evalTokenBuffer++ = SYMBOL;
 #if 0
-               *tk++ = (TOKEN)sy;
+               *evalTokenBuffer++ = (TOKEN)sy;
 #else
-               *tk++ = symbolNum;
+               *evalTokenBuffer++ = symbolNum;
                symbolPtr[symbolNum] = sy;
                symbolNum++;
 #endif
                break;
        case STRING:
-               *tk++ = CONST;
-#if 0
-               *tk++ = str_value((char *)*tok++);
-#else
-               *tk++ = str_value(string[*tok++]);
-#endif
+               *evalTokenBuffer++ = CONST;
+               *evalTokenBuffer++ = str_value(string[*tok++]);
                break;
        case '(':
                if (expr0() != OK)
@@ -301,19 +270,19 @@ int expr2(void)
 
                break;
        case '$':
-               *tk++ = ACONST;                                    // Attributed const
-               *tk++ = sloc;                                      // Current location
-               *tk++ = cursect | DEFINED;                         // Store attribs
+               *evalTokenBuffer++ = ACONST;                            // Attributed const
+               *evalTokenBuffer++ = sloc;                                      // Current location
+               *evalTokenBuffer++ = cursect | DEFINED;         // Store attribs
                break;
        case '*':
-               *tk++ = ACONST;                                    // Attributed const
+               *evalTokenBuffer++ = ACONST;                            // Attributed const
 
                if (orgactive)
-                       *tk++ = orgaddr;
+                       *evalTokenBuffer++ = orgaddr;
                else
-                       *tk++ = pcloc;                                  // Location at start of line
+                       *evalTokenBuffer++ = pcloc;                             // Location at start of line
 
-               *tk++ = ABS | DEFINED;                             // Store attribs
+               *evalTokenBuffer++ = ABS | DEFINED;                     // Store attribs
                break;
        default:
                return error("bad expression");
@@ -330,38 +299,37 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym)
 {
        // Passed in values (once derefenced, that is) can all be zero. They are
        // there so that the expression analyzer can fill them in as needed. The
-       // expression analyzer gets its input from "tok", and not from anything
-       // passed in by the user.
-       SYM * sy;
+       // expression analyzer gets its input from the global token pointer "tok",
+       // and not from anything passed in by the user.
+       SYM * symbol;
        char * p;
        int j;
 
-       tk = otk;                       // Set token pointer to 'exprbuf' (direct.c)
-                                               // Also set in various other places too (riscasm.c, e.g.)
-//     symbolNum = 0;          // Set symbol number in symbolPtr[] to 0
+       evalTokenBuffer = otk;  // Set token pointer to 'exprbuf' (direct.c)
+                                                       // Also set in various other places too (riscasm.c, e.g.)
 
        // Optimize for single constant or single symbol.
        if ((tok[1] == EOL)
                || (((*tok == CONST || *tok == SYMBOL) || (*tok >= KW_R0 && *tok <= KW_R31))
-               && (tokcl[tok[2]] < UNARY)))
+               && (tokenClass[tok[2]] < UNARY)))
        {
                if (*tok >= KW_R0 && *tok <= KW_R31)
                {
-                       *tk++ = CONST;
-                       *tk++ = *a_value = (*tok - KW_R0);
+                       *evalTokenBuffer++ = CONST;
+                       *evalTokenBuffer++ = *a_value = (*tok - KW_R0);
                        *a_attr = ABS | DEFINED;
 
                        if (a_esym != NULL)
                                *a_esym = NULL;
 
                        tok++;
-                       *tk++ = ENDEXPR;
+                       *evalTokenBuffer++ = ENDEXPR;
                        return OK;
                }
                else if (*tok == CONST)
                {
-                       *tk++ = CONST;
-                       *tk++ = *a_value = tok[1];
+                       *evalTokenBuffer++ = CONST;
+                       *evalTokenBuffer++ = *a_value = tok[1];
                        *a_attr = ABS | DEFINED;
 
                        if (a_esym != NULL)
@@ -369,15 +337,14 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym)
                }
                else if (*tok == '*')
                {
-                       *tk++ = CONST;
+                       *evalTokenBuffer++ = CONST;
 
                        if (orgactive)
-                               *tk++ = *a_value = orgaddr;
+                               *evalTokenBuffer++ = *a_value = orgaddr;
                        else
-                               *tk++ = *a_value = pcloc;
+                               *evalTokenBuffer++ = *a_value = pcloc;
 
                        *a_attr = ABS | DEFINED;
-                       //*tk++ = 
 
                        if (a_esym != NULL)
                                *a_esym = NULL;
@@ -387,73 +354,73 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym)
                else
                {
                        p = string[tok[1]];
-
-#if 0
-                       j = 0;
-
-                       if (*p == '.')
-                               j = curenv;
-#else
                        j = (*p == '.' ? curenv : 0);
-#endif
-
-                       sy = lookup(p, LABEL, j);
+                       symbol = lookup(p, LABEL, j);
 
-                       if (sy == NULL)
-                               sy = NewSymbol(p, LABEL, j);
+                       if (symbol == NULL)
+                               symbol = NewSymbol(p, LABEL, j);
 
-                       sy->sattr |= REFERENCED;
+                       symbol->sattr |= REFERENCED;
 
                        // Check for undefined register equates
-                       if (sy->sattre & UNDEF_EQUR)
+                       if (symbol->sattre & UNDEF_EQUR)
                        {
-                               errors("undefined register equate '%s'", sy->sname);
+                               errors("undefined register equate '%s'", symbol->sname);
 //if we return right away, it returns some spurious errors...
 //                             return ERROR;
                        }
 
                        // Check register bank usage
-                       if (sy->sattre & EQUATEDREG)
+                       if (symbol->sattre & EQUATEDREG)
                        {
-                               if ((regbank == BANK_0) && (sy->sattre & BANK_1) && !altbankok)   
-                                       warns("equated symbol '%s' cannot be used in register bank 0", sy->sname);
+                               if ((regbank == BANK_0) && (symbol->sattre & BANK_1) && !altbankok)   
+                                       warns("equated symbol '%s' cannot be used in register bank 0", symbol->sname);
 
-                               if ((regbank == BANK_1) && (sy->sattre & BANK_0) && !altbankok)
-                                       warns("equated symbol '%s' cannot be used in register bank 1", sy->sname);
+                               if ((regbank == BANK_1) && (symbol->sattre & BANK_0) && !altbankok)
+                                       warns("equated symbol '%s' cannot be used in register bank 1", symbol->sname);
                        }
 
-                       *tk++ = SYMBOL;
+                       *evalTokenBuffer++ = SYMBOL;
 #if 0
-                       *tk++ = (TOKEN)sy;
+                       *evalTokenBuffer++ = (TOKEN)symbol;
 #else
-                       *tk++ = symbolNum;
-                       symbolPtr[symbolNum] = sy;
+/*
+While this approach works, it's wasteful. It would be better to use something
+that's already available, like the symbol "order defined" table (which needs to
+be converted from a linked list into an array).
+*/
+                       *evalTokenBuffer++ = symbolNum;
+                       symbolPtr[symbolNum] = symbol;
                        symbolNum++;
 #endif
 
-                       if (sy->sattr & DEFINED)
-                               *a_value = sy->svalue;
+                       if (symbol->sattr & DEFINED)
+                               *a_value = symbol->svalue;
                        else
                                *a_value = 0;
 
-                       if (sy->sattre & EQUATEDREG) 
+/*
+All that extra crap that was put into the svalue when doing the equr stuff is
+thrown away right here. What the hell is it for?
+*/
+                       if (symbol->sattre & EQUATEDREG) 
                                *a_value &= 0x1F;
 
-                       *a_attr = (WORD)(sy->sattr & ~GLOBAL);
+                       *a_attr = (WORD)(symbol->sattr & ~GLOBAL);
 
-                       if ((sy->sattr & (GLOBAL | DEFINED)) == GLOBAL && a_esym != NULL)
-                               *a_esym = sy;
+                       if ((symbol->sattr & (GLOBAL | DEFINED)) == GLOBAL && a_esym != NULL)
+                               *a_esym = symbol;
                }
 
                tok += 2;
-               *tk++ = ENDEXPR;
+               *evalTokenBuffer++ = ENDEXPR;
                return OK;
        }
 
        if (expr0() != OK)
                return ERROR;
 
-       *tk++ = ENDEXPR;
+       *evalTokenBuffer++ = ENDEXPR;
        return evexpr(otk, a_value, a_attr, a_esym);
 }
 
index 4ab0f7d44fb720b9d13541f3f7b0676a61939e60..61c9029ab095e186e0af0cc0bda75680bef7e66c 100644 (file)
--- a/procln.c
+++ b/procln.c
@@ -180,7 +180,6 @@ loop1:                                                                              // Internal line processing loop
 
        if (j == '=' || j == DEQUALS || j == SET || j == REG || j == EQUREG || j == CCDEF)
        {
-//             equate = (char *)tok[1];
                equate = string[tok[1]];
                equtyp = j;
                tok += 3;
@@ -347,11 +346,15 @@ normal:
        // Do equates
        if (equate != NULL)
        {
-               j = 0;                                                          // Pick global or local sym enviroment
+               // Pick global or local symbol enviroment
+#if 0
+               j = 0;
 
                if (*equate == '.')
                        j = curenv;
-
+#else
+               j = (*equate == '.' ? curenv : 0);
+#endif
                sy = lookup(equate, LABEL, j);
 
                if (sy == NULL)
@@ -402,6 +405,14 @@ normal:
                // o  everything else
                if (equtyp == EQUREG)
                {
+//Linko's request to issue a warning on labels that equated to the same register
+//would go here. Not sure how to implement it though. :-/
+/*
+Maybe like this way:
+have an array of bools with 64 entries. Whenever a register is equated, set the
+corresponding register bool to true. Whenever it's undef'ed, set it to false. When
+checking to see if it's already been equated, issue a warning.
+*/
                        // Check that we are in a RISC section
                        if (!rgpu && !rdsp)
                        {
@@ -414,33 +425,42 @@ normal:
                        {
                                sy->sattre  = EQUATEDREG | RISCSYM;     // Mark as equated register
                                riscreg = (*tok - KW_R0);
+//is there any reason to do this, since we're putting this in svalue?
                                sy->sattre |= (riscreg << 8);           // Store register number
 
+                               // Default is no register bank specified
+                               registerbank = BANK_N;
+
+                               // Check for ",<bank #>" notation
                                if ((tok[1] == ',') && (tok[2] == CONST))
                                {
+                                       // Advance token pointer to the constant
                                        tok += 3;
 
+                                       // Anything other than a 0 or a 1 will result in "No Bank"
                                        if (*tok == 0)
                                                registerbank = BANK_0;
                                        else if (*tok == 1)
                                                registerbank = BANK_1;
-                                       else
-                                               registerbank = BANK_N;
-                               }
-                               else
-                               {
-                                       registerbank = BANK_N;
                                }
 
+// What needs to happen here is to prime registerbank with regbank, then use
+// registerbank down below for the bank marking.
+#warning "!!! regbank <-> registerbank confusion here !!!"
+// The question here is why, if we're allowed to override the ".regbankN" rules above,
+// then why is it using the one set by the directive in the extended attributes and
+// not in what ends up in symbol->svalue?
+// ".regbankN" is not an original Madmac directive, so it's suspect
                                sy->sattre |= regbank;          // Store register bank
                                eattr = ABS | DEFINED | GLOBAL;
-                               eval = 0x80000080 + (riscreg) + (registerbank << 8);
+// & what does this $80000080 constant mean???
+//                             eval = 0x80000080 + (riscreg) + (registerbank << 8);
+                               eval = riscreg;
                                tok++;
                        }
                        // Checking for a register symbol
                        else if (tok[0] == SYMBOL)
                        {
-//                             sy2 = lookup((char *)tok[1], LABEL, j);
                                sy2 = lookup(string[tok[1]], LABEL, j);
 
                                // Make sure symbol is a valid equreg
@@ -478,7 +498,6 @@ normal:
 
                        if (tok[0] == SYMBOL)
                        {
-//                             sy2 = lookup((char *)tok[1], LABEL, j);
                                sy2 = lookup(string[tok[1]], LABEL, j);
 
                                if (!sy2 || !(sy2->sattre & EQUATEDCC))
@@ -500,7 +519,6 @@ normal:
                //equ a equr
                else if (*tok == SYMBOL)
                {
-//                     sy2 = lookup((char *)tok[1], LABEL, j);
                        sy2 = lookup(string[tok[1]], LABEL, j);
 
                        if (sy2 && (sy2->sattre & EQUATEDREG))
index fbc8f81cf605ff2a14178c7754b9c64bac94718b..f2ffa4d34563edc781ffffcef605bd0e19b3a92d 100644 (file)
--- a/riscasm.c
+++ b/riscasm.c
@@ -171,15 +171,6 @@ int GetRegister(WORD rattr)
        if ((challoc - ch_size) < 4)
                chcheck(4L);
 
-       // See if this symbol has been defined, then undefined:
-//does nothing
-//segfaults now (esym == NULL?)
-/*     if (esym->sattre & UNDEF_EQUR)
-       {
-               error("undefined register");
-               return ERROR;
-       }*/
-
        if (!(eattr & DEFINED))
        {
                fixup((WORD)(FU_WORD | rattr), sloc, r_expr);      
diff --git a/rmac.c b/rmac.c
index 02bdcfd6e90c9ef6b52b73dd45073e611759ec44..6dd9475d7db3b7a7aa848820977d45f2e78bdf75 100644 (file)
--- a/rmac.c
+++ b/rmac.c
@@ -65,7 +65,8 @@ static int qsz;                                             // Size of each reco
 static int thresh;                                          // THRESHold in chars 
 static int mthresh;                                         // MTHRESHold in chars
 
-
+// This is unused BOLLOCKS
+#if 0
 //
 // qst: Do a quicksort. First, find the median element, and put that one in the
 // first place as the discriminator. (This "median" is just the median of the
@@ -298,7 +299,7 @@ int rmac_qsort(char * base, int n, int size, int (*compar)())
 
        return 0;
 }
-
+#endif
 
 #if 0
 //
diff --git a/rmac.h b/rmac.h
index 7d8b526970a3136085f046e0e31974f47ad7ab66..1c777747731a78ffa878ef36ddde98e5d9d9502a 100644 (file)
--- a/rmac.h
+++ b/rmac.h
@@ -194,6 +194,6 @@ void autoeven(int);
 int nthpath(char *, int, char *);
 void clear(char *, LONG);
 char * copy(char *, char *, LONG);
-int rmac_qsort(char *, int, int, int (*)());
+//int rmac_qsort(char *, int, int, int (*)());
 
 #endif // __RMAC_H__
diff --git a/sect.c b/sect.c
index b8d62407e12987f1acfab80e0abc8a43880126cb..f9c8a588531a4d655b2981189b845ad859294b51 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -269,7 +269,7 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr)
        LONG len = 0;
        CHUNK * cp;
        SECT * p;
-       // Shamus: Expression lengths are voodoo ATM (varibale "i"). Need to fix this.
+       // Shamus: Expression lengths are voodoo ATM (variable "i"). Need to fix this.
 #warning "!!! fixup() is filled with VOODOO !!!"
        DEBUG printf("FIXUP@$%X: $%X\n", loc, attr);
 
index 3017afc7b60a7dff90f936e1cb82c15c01c22fbd..dd47ccdbdc639de3f3923741c35af4a00684c2a7 100644 (file)
--- a/version.h
+++ b/version.h
@@ -13,6 +13,6 @@
 
 #define MAJOR   1                      // Major version number
 #define MINOR   2                      // Minor version number
-#define PATCH   3                      // Patch release number
+#define PATCH   4                      // Patch release number
 
 #endif // __VERSION_H__