X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=token.c;h=2d3742fedc6d2643ef3d50f6ecfe118120777aed;hb=1df6df8dae6679e81b24a547bfc491474117391c;hp=807f08fc34b4f2789b90bc557e5758dc11711018;hpb=37694c99b02f939fc259c1e180359afb887acd55;p=rmac diff --git a/token.c b/token.c index 807f08f..2d3742f 100644 --- a/token.c +++ b/token.c @@ -699,7 +699,7 @@ char * GetNextRepeatLine(void) DEBUG { printf("end-repeat-block\n"); } return NULL; } - + reptuniq++; // strp = irept->ir_nextln; } // Mark the current macro line in the irept object @@ -708,8 +708,33 @@ char * GetNextRepeatLine(void) // error reporting anyway) irept->lineno = irept->ir_nextln->lineno; -// strcpy(irbuf, (char *)(irept->ir_nextln + 1)); - strcpy(irbuf, irept->ir_nextln->line); + // Copy the rept lines verbatim, unless we're in nest level 0. + // Then, expand any \~ labels to unique numbers (Rn) + if (rptlevel) + { + strcpy(irbuf, irept->ir_nextln->line); + } + else + { + uint32_t linelen = strlen(irept->ir_nextln->line); + uint8_t *p_line = irept->ir_nextln->line; + char *irbufwrite = irbuf; + for (int i = 0; i <= linelen; i++) + { + uint8_t c; + c = *p_line++; + if (c == '\\' && *p_line == '~') + { + p_line++; + irbufwrite += sprintf(irbufwrite, "R%u", reptuniq); + } + else + { + *irbufwrite++ = c; + } + } + } + DEBUG { printf("repeat line='%s'\n", irbuf); } // irept->ir_nextln = (LONG *)*strp; irept->ir_nextln = irept->ir_nextln->next; @@ -949,6 +974,8 @@ int TokenizeLine(void) int stuffnull; // 1:terminate SYMBOL '\0' at *nullspot uint8_t c1; int stringNum = 0; // Pointer to string locations in tokenized line + SYM* sy; // For looking up symbols (.equr) + int equrundef = 0; // Flag for equrundef scanning retry: @@ -980,26 +1007,6 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } curlineno++; // Bump line number lntag = SPACE; - if (as68_flag) - { - // AS68 compatibility, throw away all lines starting with - // back-quotes, tildes, or '*' - // On other lines, turn the first '*' into a semi-colon. - if (*ln == '`' || *ln == '~' || *ln == '*') - *ln = ';'; - else - { - for(p=ln; *p!=EOS; p++) - { - if (*p == '*') - { - *p = ';'; - break; - } - } - } - } - break; // Macro-block: @@ -1194,10 +1201,54 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); } case 121: // date j = -1; } + + // If we detected equrundef/regundef set relevant flag + if (j == KW_EQURUNDEF) + { + equrundef = 1; + j = -1; + //printf("line %d, equrundef found\n", curlineno); + } // If not tokenized keyword OR token was not found if ((j < 0) || (state < 0)) { + // Only proceed if no equrundef has been detected. In that case we need to store the symbol + // because the directive handler (d_equrundef) will run outside this loop, further into procln.c + if (!equrundef) + { + // Last attempt: let's see if this is an equated register + char temp = *ln; + *ln = 0; + sy = lookup(nullspot, LABEL, 0); + *ln = temp; + if (sy) + { + if (sy->sattre & EQUATEDREG) + { + uint32_t register_token = sy->svalue; + if (rgpu || rdsp) + { + // If we are in GPU or DSP mode then mark the register bank. + // We will use it during EvaluateRegisterFromTokenStream() + // when we check if we can use the equated register with the currently + // selected bank. + // Note (ggn): I find all this superfluous. Do we really want to be so + // protective? Plus, the current implementation happily skips + // these checks on .equr that are set during fixups - oops! + register_token |= 0x80000000; // Mark that this is an .equr + if (sy->sattre & BANK_1) + { + register_token |= 0x40000000; // Mark bank 1 + } + } + *tk.u32++ = register_token; + stuffnull = 0; + continue; + } + } + } + // Ok, that failed, let's store the symbol instead *tk.u32++ = SYMBOL; string[stringNum] = nullspot; *tk.u32++ = stringNum;