From: Shamus Hammons Date: Thu, 20 Jul 2017 19:15:53 +0000 (-0500) Subject: Fix for bug #102. Thanks (blame!) go to ggn & dml for the idea. :-) X-Git-Tag: v2.1.0~113 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=commitdiff_plain;h=49eac9eff9d177e717de7bc8799a632c46b79237;ds=sidebyside Fix for bug #102. Thanks (blame!) go to ggn & dml for the idea. :-) --- diff --git a/eagen.c b/eagen.c index de1ecb4..1f18b85 100644 --- a/eagen.c +++ b/eagen.c @@ -14,6 +14,7 @@ #include "mach.h" #include "riscasm.h" #include "sect.h" +#include "token.h" #define eaNgen ea0gen #define amN am0 diff --git a/eagen0.c b/eagen0.c index f01b989..1bb00ba 100644 --- a/eagen0.c +++ b/eagen0.c @@ -38,7 +38,7 @@ int eaNgen(WORD siz) if (tdb) MarkRelocatable(cursect, sloc, tdb, MWORD, NULL); - if ((v == 0) && optim_flags[OPT_INDIRECT_DISP] && !movep) + if ((v == 0) && CHECK_OPTS(OPT_INDIRECT_DISP) && !movep) { // If expr is 0, size optimise the opcode. Generally the lower // 6 bits of the opcode for expr(ax) are 101rrr where rrr=the diff --git a/mach.c b/mach.c index ac800eb..22a2727 100644 --- a/mach.c +++ b/mach.c @@ -13,7 +13,6 @@ #include "error.h" #include "procln.h" #include "riscasm.h" -//#include "rmac.h" #include "sect.h" #include "token.h" @@ -469,7 +468,7 @@ int m_ea(WORD inst, WORD siz) // int m_lea(WORD inst, WORD siz) { - if (optim_flags[OPT_LEA_ADDQ] + if (CHECK_OPTS(OPT_LEA_ADDQ) && ((am0 == ADISP) && (a0reg == a1reg) && (a0exattr & DEFINED)) && ((a0exval > 0) && (a0exval <= 8))) { @@ -820,7 +819,7 @@ int m_move(WORD inst, WORD size) int siz = (int)size; // Try to optimize to MOVEQ - if (optim_flags[OPT_MOVEL_MOVEQ] + if (CHECK_OPTS(OPT_MOVEL_MOVEQ) && (siz == SIZL) && (am0 == IMMED) && (am1 == DREG) && ((a0exattr & (TDB | DEFINED)) == DEFINED) && (a0exval + 0x80 < 0x100)) @@ -981,7 +980,7 @@ int m_br(WORD inst, WORD siz) // Optimize branch instr. size if (siz == SIZN) { - if (optim_flags[OPT_BSR_BCC_S] && (v != 0) && ((v + 0x80) < 0x100)) + if (CHECK_OPTS(OPT_BSR_BCC_S) && (v != 0) && ((v + 0x80) < 0x100)) { // Fits in .B inst |= v & 0xFF; diff --git a/parmode.h b/parmode.h index 5f475db..54b584e 100644 --- a/parmode.h +++ b/parmode.h @@ -303,7 +303,7 @@ else { expr(AnBEXPR, &AnBEXVAL, &AnBEXATTR, &AnESYM); - if (optim_flags[OPT_BASE_DISP] && AnBEXVAL==0 && AnEXATTR!=0) + if (CHECK_OPTS(OPT_BASE_DISP) && AnBEXVAL==0 && AnEXATTR!=0) { // bd=0 so let's optimise it out AnEXTEN|=EXT_BDSIZE0; @@ -325,7 +325,7 @@ { // Defined, absolute values from $FFFF8000..$00007FFF get optimized // to absolute short - if (optim_flags[OPT_ABS_SHORT] + if (CHECK_OPTS(OPT_ABS_SHORT) && ((AnBEXATTR & (TDB | DEFINED)) == DEFINED) && ((AnBEXVAL + 0x8000) < 0x10000)) { @@ -583,7 +583,7 @@ if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK) goto badmode; - if (optim_flags[OPT_BASE_DISP] && (AnEXVAL == 0)) + if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXVAL == 0)) { // od=0 so optimise it out AMn = MEMPOST; // let's say it's ([bd,An],Xn,od) with od=0 then @@ -601,7 +601,7 @@ // Defined, absolute values from $FFFF8000..$00007FFF get // optimized to absolute short - if (optim_flags[OPT_ABS_SHORT] + if (CHECK_OPTS(OPT_ABS_SHORT) && ((AnEXATTR & (TDB | DEFINED)) == DEFINED) && ((AnEXVAL + 0x8000) < 0x10000)) { @@ -654,7 +654,7 @@ expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM); - if (optim_flags[OPT_BASE_DISP] && (AnEXVAL == 0)) + if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXVAL == 0)) { // od=0 so optimise it out AMn = MEMPOST; // let's say it's ([bd,An],Xn,od) with od=0 then @@ -685,7 +685,7 @@ // Defined, absolute values from $FFFF8000..$00007FFF get // optimized to absolute short - else if (optim_flags[OPT_BASE_DISP] + else if (CHECK_OPTS(OPT_BASE_DISP) && ((AnEXATTR & (TDB | DEFINED)) == DEFINED) && ((AnEXVAL + 0x8000) < 0x10000)) { @@ -814,7 +814,7 @@ if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK) goto badmode; - if (optim_flags[OPT_BASE_DISP] && (AnEXVAL == 0)) + if (CHECK_OPTS(OPT_BASE_DISP) && (AnEXVAL == 0)) { // od=0 so optimise it out AMn = MEMPRE; // let's say it's ([bd,An],Xn,od) with od=0 then @@ -847,7 +847,7 @@ // Defined, absolute values from $FFFF8000..$00007FFF get optimized // to absolute short - else if (optim_flags[OPT_BASE_DISP] + else if (CHECK_OPTS(OPT_BASE_DISP) && ((AnEXATTR & (TDB | DEFINED)) == DEFINED) && ((AnEXVAL + 0x8000) < 0x10000)) { @@ -1007,7 +1007,7 @@ CHK_FOR_DISPn: // Defined, absolute values from $FFFF8000..$00007FFF get optimized // to absolute short - if (optim_flags[OPT_ABS_SHORT] + if (CHECK_OPTS(OPT_ABS_SHORT) && ((AnEXATTR & (TDB | DEFINED)) == DEFINED) && ((AnEXVAL + 0x8000) < 0x10000)) { diff --git a/token.c b/token.c index 2a8513d..1722f63 100644 --- a/token.c +++ b/token.c @@ -36,6 +36,7 @@ TOKEN * tok; // Ptr to current token TOKEN * etok; // Ptr past last token in tokbuf[] TOKEN tokeol[1] = {EOL}; // Bailout end-of-line token char * string[TOKBUFSIZE*2]; // Token buffer string pointer storage +int optimizeOff; // Optimization override flag // File record, used to maintain a list of every include file ever visited #define FILEREC struct _filerec @@ -48,12 +49,12 @@ FILEREC FILEREC * filerec; FILEREC * last_fr; -INOBJ * cur_inobj; // Ptr current input obj (IFILE/IMACRO) -static INOBJ * f_inobj; // Ptr list of free INOBJs -static IFILE * f_ifile; // Ptr list of free IFILEs -static IMACRO * f_imacro; // Ptr list of free IMACROs +INOBJ * cur_inobj; // Ptr current input obj (IFILE/IMACRO) +static INOBJ * f_inobj; // Ptr list of free INOBJs +static IFILE * f_ifile; // Ptr list of free IFILEs +static IMACRO * f_imacro; // Ptr list of free IMACROs -static TOKEN tokbuf[TOKBUFSIZE]; // Token buffer (stack-like, all files) +static TOKEN tokbuf[TOKBUFSIZE]; // Token buffer (stack-like, all files) uint8_t chrtab[0x100] = { ILLEG, ILLEG, ILLEG, ILLEG, // NUL SOH STX ETX @@ -824,17 +825,11 @@ DEBUG { printf("[fpop: (post) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int) case SRC_IREPT: // Pop and release an IREPT { DEBUG { printf("dealloc IREPT\n"); } -// LONG * p = inobj->inobj.irept->ir_firstln; LLIST * p = inobj->inobj.irept->ir_firstln; // Deallocate repeat lines while (p != NULL) { -// Shamus: ggn confirmed that this will cause a segfault on 64-bit versions of -// RMAC. This is just stupid and wrong anyway, so we need to fix crapola -// like this... -// LONG * p1 = (LONG *)*p; -// p = p1; free(p->line); p = p->next; } @@ -1033,7 +1028,7 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } case SRC_IREPT: if ((ln = GetNextRepeatLine()) == NULL) { -DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); } + DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); } fpop(); goto retry; } @@ -1059,6 +1054,16 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); } if (*ln == '*' || *ln == ';' || ((*ln == '/') && (*(ln + 1) == '/'))) goto goteol; + // And here we have a very ugly hack for signalling a single line 'turn off + // optimization'. There's really no nice way to do this, so hack it is! + optimizeOff = 0; // Default is to take optimizations as they come + + if (*ln == '!') + { + optimizeOff = 1; // Signal that we don't want to optimize this line + ln++; // & skip over the darned thing + } + // Main tokenization loop; // o skip whitespace; // o handle end-of-line; diff --git a/token.h b/token.h index 1d824a9..f8df49a 100644 --- a/token.h +++ b/token.h @@ -84,6 +84,9 @@ #define MULTX 64 // Multiple-character tokens #define DOT 128 // [bwlsBWSL] for what follows a '.' +// Macro to check for specific optimizations or override +#define CHECK_OPTS(x) (optim_flags[x] && !optimizeOff) + // Conditional assembly structures IFENT { IFENT * if_prev; // Ptr prev .if state block (or NULL) @@ -156,6 +159,7 @@ extern char tolowertab[]; extern INOBJ * cur_inobj; extern int mjump_align; extern char * string[]; +int optimizeOff; // Exported functions int include(int, char *);