From c8c1bd3b363a4d796397fd4920a19fbcd98bab3a Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sat, 4 Jan 2020 10:24:57 -0600 Subject: [PATCH] Fix for bug #135 (RISC error reporting for immediate values). Thanks to Linkovitch for the report; now at v2.0.7. --- expr.c | 14 +++++++------- riscasm.c | 10 ++++++++-- rmac.h | 1 + version.h | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/expr.c b/expr.c index 63d63ae..3e60d88 100644 --- 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) diff --git a/riscasm.c b/riscasm.c index 82caf80..9ecc61d 100644 --- 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 a2cc1c8..52fb92d 100644 --- 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 diff --git a/version.h b/version.h index e4164d4..c9d5387 100644 --- 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__ -- 2.37.2