Fix for bug #135 (RISC error reporting for immediate values).
authorShamus Hammons <jlhamm@acm.org>
Sat, 4 Jan 2020 16:24:57 +0000 (10:24 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sat, 4 Jan 2020 16:24:57 +0000 (10:24 -0600)
Thanks to Linkovitch for the report; now at v2.0.7.

expr.c
riscasm.c
rmac.h
version.h

diff --git a/expr.c b/expr.c
index 63d63ae2552e72f6fdf6dc77ee62fcc02decaa96..3e60d88ace2a8028c85b9cf9f027f7e78e86e2cf 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -417,7 +417,7 @@ int expr(TOKEN * otk, uint64_t * a_value, WORD * a_attr, SYM ** a_esym)
                {
                        *evalTokenBuffer.u32++ = CONST;
                        *evalTokenBuffer.u64++ = *a_value = (*tok - KW_R0);
-                       *a_attr = ABS | DEFINED;
+                       *a_attr = ABS | DEFINED | RISCREG;
 
                        if (a_esym != NULL)
                                *a_esym = NULL;
@@ -522,19 +522,19 @@ be converted from a linked list into an array).
                        symbolNum++;
 #endif
 
-                       if (symbol->sattr & DEFINED)
-                               *a_value = symbol->svalue;
-                       else
-                               *a_value = 0;
+                       *a_value = (symbol->sattr & DEFINED ? symbol->svalue : 0);
+                       *a_attr = (WORD)(symbol->sattr & ~GLOBAL);
 
 /*
 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)(symbol->sattr & ~GLOBAL);
+                               *a_attr |= RISCREG; // Mark it as a register, 'cause it is
+                               *a_esym = symbol;
+                       }
 
                        if ((symbol->sattr & (GLOBAL | DEFINED)) == GLOBAL
                                && a_esym != NULL)
index 82caf808d463e07d6b4cbbce9ce7076c2b6d7ae7..9ecc61da0b547fa7509b2718d707b26785cac778 100644 (file)
--- a/riscasm.c
+++ b/riscasm.c
@@ -229,7 +229,7 @@ int GenerateRISCCode(int state)
        int indexed;                            // Indexed register flag
 
        uint64_t eval;                          // Expression value
-       uint16_t eattr;                                 // Expression attributes
+       uint16_t eattr;                         // Expression attributes
        SYM * esym;                                     // External symbol involved in expr.
        TOKEN r_expr[EXPRSIZE];         // Expression token list
 
@@ -325,8 +325,14 @@ int GenerateRISCCode(int state)
                }
                else
                {
+                       if (esym && (esym->sattre & EQUATEDREG))
+                               return error("equated register seen for immediate value");
+
+                       if (eattr & RISCREG)
+                               return error("register seen for immediate value");
+
                        if (((int)eval < reg1) || ((int)eval > reg2))
-                               return error("constant out of range (%d to %d", reg1, reg2);
+                               return error("constant out of range (%d to %d)", reg1, reg2);
 
                        if (parm & SUB32)
                                reg1 = 32 - (int)eval;
diff --git a/rmac.h b/rmac.h
index a2cc1c8a270d38677e6d98ccc05daecd18b1414b..52fb92ddd355621645fe812b9f60a6839d74baa2 100644 (file)
--- a/rmac.h
+++ b/rmac.h
@@ -218,6 +218,7 @@ PTR
 #define EQUATED      0x0800            // Symbol was equated
 #define SDECLLIST    0x0400            // Symbol is on 'sdecl'-order list
 #define FLOAT        0x0200            // Symbol is a floating point value
+#define RISCREG      0x0100            // Symbol is a RISC register
 
 // Expression spaces, ORed with symbol and expression attributes above
 #define ABS          0x0000            // In absolute space
index e4164d4418c29e0ee6d1007e9a3adc0292a5be14..c9d53878ef70279ae4ab33767c099c9b2ad73edd 100644 (file)
--- a/version.h
+++ b/version.h
@@ -15,7 +15,7 @@
 
 #define MAJOR   2              // Major version number
 #define MINOR   0              // Minor version number
-#define PATCH   6              // Patch release number
+#define PATCH   7              // Patch release number
 
 #endif // __VERSION_H__