X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=parmode.h;h=c003523f322f9aa49c6e0f3858b1c37b833ffe55;hp=543701ace549f4bb9e9ee4c879888a1f6cab2c70;hb=02523045dcb28c8f6ad794a84e32beff214be424;hpb=d0c28c349ddfb8393568037f68bddbe8979ce0df diff --git a/parmode.h b/parmode.h index 543701a..c003523 100644 --- a/parmode.h +++ b/parmode.h @@ -31,6 +31,11 @@ AMn = IMMED; } + + // Small problem with this is that the opening parentheses might be an + // expression that's part of a displacement; this code will falsely flag + // that as an error. + // (An) // (An)+ // (An,Xn[.siz][*scale]) @@ -67,21 +72,22 @@ } AMn = AINDEXED; - goto AMn_IX0; // Handle ",Xn[.siz][*scale])" + goto AMn_IX0; // Handle ",Xn[.siz][*scale])" } else if (*tok == KW_PC) { // (PC,Xn[.siz][*scale]) tok++; AMn = PCINDEXED; - // Common index handler; enter here with `tok' pointing at the comma. + // Common index handler; enter here with 'tok' pointing at the + // comma. - AMn_IX0: // Handle indexed with missing expr + AMn_IX0: // Handle indexed with missing expr AnEXVAL = 0; AnEXATTR = ABS | DEFINED; - AMn_IXN: // Handle any indexed (tok -> a comma) + AMn_IXN: // Handle any indexed (tok -> a comma) if (*tok++ != ',') goto badmode; @@ -92,7 +98,7 @@ AnIXREG = *tok++ & 15; switch ((int)*tok) - { // Index reg size: | .W | .L + { // Index reg size: | .W | .L case DOTW: tok++; default: @@ -102,12 +108,12 @@ AnIXSIZ = 0x0800; tok++; break; - case DOTB: // .B not allowed here... + case DOTB: // .B not allowed here... goto badmode; } if (*tok == '*') - { // scale: *1, *2, *4, *8 + { // scale: *1, *2, *4, *8 tok++; if (*tok++ != CONST || *tok > 8) @@ -131,7 +137,7 @@ } } - if (*tok++ != ')') // final ")" + if (*tok++ != ')') // final ")" goto badmode; goto AnOK; @@ -141,10 +147,19 @@ goto unmode; } else - { // (expr... + { // (expr... if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK) return ERROR; + // It could be that this is really just an expression prefixing a + // register as a displacement... + if (*tok == ')') + { + tok++; + goto CHK_FOR_DISPn; + } + + // Otherwise, check for PC & etc displacements... if (*tok++ != ',') goto badmode; @@ -176,7 +191,7 @@ } else if (*tok == ')') { - AMn = PCDISP; // expr(PC) + AMn = PCDISP; // expr(PC) tok++; goto AnOK; } @@ -187,7 +202,7 @@ goto badmode; } } - else if (*tok=='-' && tok[1]=='(' && ((tok[2]>=KW_A0) && (tok[2]<=KW_A7)) && tok[3]==')') + else if (*tok == '-' && tok[1] == '(' && ((tok[2] >= KW_A0) && (tok[2] <= KW_A7)) && tok[3] == ')') { AMn = APREDEC; AnREG = tok[2] & 7; @@ -223,11 +238,16 @@ if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK) return ERROR; +CHK_FOR_DISPn: if (*tok == DOTW) { // expr.W tok++; AMn = ABSW; + + if ((AnEXATTR & (TDB|DEFINED)) == DEFINED && (AnEXVAL < 0x10000)) + AnEXVAL = (int32_t)(int16_t)AnEXVAL; // Sign extend value + goto AnOK; } else if (*tok != '(') @@ -237,9 +257,14 @@ // Defined, absolute values from $FFFF8000..$00007FFF get optimized // to absolute short - if ((AnEXATTR & (TDB|DEFINED)) == DEFINED && (AnEXVAL + 0x8000) < 0x10000) + if (optim_flags[OPT_ABS_SHORT] && (AnEXATTR & (TDB|DEFINED)) == DEFINED && (AnEXVAL + 0x8000) < 0x10000) + { AMn = ABSW; + if (sbra_flag) + warn("absolute value from $FFFF8000..$00007FFF optimised to absolute short"); + } + // Is .L forced here? if (*tok == DOTL) { @@ -287,7 +312,7 @@ ; } -// Cleanup dirty little macros +// Clean up dirty little macros #undef AnOK #undef AMn #undef AnREG @@ -302,3 +327,4 @@ #undef AnESYM #undef AMn_IX0 #undef AMn_IXN +#undef CHK_FOR_DISPn