Fix for bug #67 (thanks to ggn for reporting!).
authorShamus Hammons <jlhamm@acm.org>
Sun, 15 May 2016 23:25:37 +0000 (18:25 -0500)
committerShamus Hammons <jlhamm@acm.org>
Sun, 15 May 2016 23:25:37 +0000 (18:25 -0500)
Turns out the tokenizer would not properly tokenize DOTx constructs
unless they were hanging off the end of a symbol. This should fix that
once and for all.

mach.c
token.c
version.h

diff --git a/mach.c b/mach.c
index b3e36c7dc382c93b84599a1979f8da85920c7280..ae5065bf87c85a5c381d72ee917ceb3b96575d0d 100644 (file)
--- a/mach.c
+++ b/mach.c
@@ -62,40 +62,39 @@ MNTAB machtab[] = {
 //   { (WORD)-1, (unsigned long)-1L, (unsigned long)-1L, 0x0000, 0, m_badmode }, // 0 
    { 0xFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000, 0, m_badmode }, // 0 
    #include "68ktab.h"
-   {  0,  0L,  0L, 0x0000, 0, m_unimp   }                   // Last entry
+   {  0,  0L,  0L, 0x0000, 0, m_unimp   }            // Last entry
 };
 
 // Register number << 9
 WORD reg_9[8] = {
-      0, 1<<9, 2<<9, 3<<9,
-   4<<9, 5<<9, 6<<9, 7<<9
+       0, 1 << 9, 2 << 9, 3 << 9, 4 << 9, 5 << 9, 6 << 9, 7 << 9
 };
 
 // SIZB==>00, SIZW==>01, SIZL==>10, SIZN==>01 << 6
 WORD siz_6[] = {
-   (WORD)-1,                                                // n/a 
-   0,                                                       // SIZB
-   1<<6, (WORD)-1,                                          // SIZW, n/a 
-   2<<6, (WORD)-1, (WORD)-1, (WORD)-1,                      // SIZL, n/a, n/a, n/a 
-   1<<6                                                     // SIZN 
+       (WORD)-1,                                        // n/a 
+       0,                                               // SIZB
+       1<<6, (WORD)-1,                                  // SIZW, n/a 
+       2<<6, (WORD)-1, (WORD)-1, (WORD)-1,              // SIZL, n/a, n/a, n/a 
+       1<<6                                             // SIZN 
 };
 
 // Byte/word/long size for MOVE instrs
 WORD siz_12[] = {
    (WORD)-1,
-   0x1000,                                                  // Byte 
-   0x3000, (WORD)-1,                                        // Word 
-   0x2000, (WORD)-1, (WORD)-1, (WORD)-1,                    // Long
-   0x3000                                                   // Word (SIZN)
+   0x1000,                                           // Byte 
+   0x3000, (WORD)-1,                                 // Word 
+   0x2000, (WORD)-1, (WORD)-1, (WORD)-1,             // Long
+   0x3000                                            // Word (SIZN)
 };
 
 // Word/long size (0=.w, 1=.l) in bit 8
 WORD lwsiz_8[] = {
-   (WORD)-1,                                                // n/a
-   (WORD)-1,                                                // SIZB
-   0, (WORD)-1,                                             // SIZW, n/a
-   1<<8, (WORD)-1, (WORD)-1, (WORD)-1,                      // SIZL, n/a, n/a, n/a
-   0                                                        // SIZN
+   (WORD)-1,                                         // n/a
+   (WORD)-1,                                         // SIZB
+   0, (WORD)-1,                                      // SIZW, n/a
+   1<<8, (WORD)-1, (WORD)-1, (WORD)-1,               // SIZL, n/a, n/a, n/a
+   0                                                 // SIZN
 };
 
 // Addressing mode in bits 6..11 (register/mode fields are reversed)
@@ -162,13 +161,9 @@ int m_ea(WORD inst, WORD siz)
        {
                // OR-in register number 
                if (flg & 8)
-               {
                        inst |= reg_9[a1reg];           // ea1reg in bits 9..11 
-               }
                else
-               {
                        inst |= reg_9[a0reg];           // ea0reg in bits 9..11 
-               }
        }
 
        if (flg & 1)
@@ -433,7 +428,6 @@ int m_link(WORD inst, WORD siz)
 // 
 // Optimize MOVE.L #<smalldata>,D0 to a MOVEQ
 //
-//int m_move(WORD inst, int siz)
 int m_move(WORD inst, WORD size)
 {
        // Cast the passed in value to an int
@@ -444,6 +438,7 @@ int m_move(WORD inst, WORD size)
                && (a0exattr & (TDB|DEFINED)) == DEFINED && a0exval + 0x80 < 0x100)
        {
                m_moveq((WORD)0x7000, (WORD)0);
+
                if (sbra_flag)
                        warn("move.l #size,dx converted to moveq");
        }
diff --git a/token.c b/token.c
index 77fec1efbeac0071594df0dbd22de787d8b02dd8..5b3d0737b02ea308f19938d86ec1ec3bfd3fcc53 100644 (file)
--- a/token.c
+++ b/token.c
@@ -1027,6 +1027,27 @@ if (debug) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n");
 
                        v = 0;                                  // Assume no DOT attrib follows symbol
                        stuffnull = 1;
+
+                       // In some cases, we need to check for a DOTx at the *beginning*
+                       // of a symbol, as the "start" of the line we're currently looking
+                       // at could be somewhere in the middle of that line!
+                       if (*ln == '.')
+                       {
+                               // Make sure that it's *only* a .[bwsl] following, and not the
+                               // start of a local symbol:
+                               if ((chrtab[*(ln + 1)] & DOT)
+                                       && (dotxtab[*(ln + 1)] != 0)
+                                       && !(chrtab[*(ln + 2)] & CTSYM))
+                               {
+                                       // We found a legitimate DOTx construct, so add it to the
+                                       // token stream:
+                                       ln++;
+                                       stuffnull = 0;
+                                       *tk++ = (TOKEN)dotxtab[*ln++];
+                                       continue;
+                               }
+                       }
+
                        p = nullspot = ln++;    // Nullspot -> start of this symbol
 
                        // Find end of symbol (and compute its length)
@@ -1044,13 +1065,13 @@ if (debug) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n");
                                // the chararacter after THAT one must not have a start-symbol
                                // attribute (to prevent symbols that look like, for example,
                                // "zingo.barf", which might be a good idea anyway....)
-                               if ((((int)chrtab[*ln] & DOT) == 0) || ((int)dotxtab[*ln] <= 0))
-                                       return error("[bwsl] must follow `.' in symbol");
+                               if (((chrtab[*ln] & DOT) == 0) || (dotxtab[*ln] == 0))
+                                       return error("[bwsl] must follow '.' in symbol");
 
                                v = (VALUE)dotxtab[*ln++];
 
-                               if ((int)chrtab[*ln] & CTSYM)
-                                       return error("misuse of `.', not allowed in symbols");
+                               if (chrtab[*ln] & CTSYM)
+                                       return error("misuse of '.', not allowed in symbols");
                        }
 
                        // If the symbol is small, check to see if it's really the name of
@@ -1102,7 +1123,7 @@ if (debug) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n");
                        }
 
                        // If not tokenized keyword OR token was not found
-                       if (j < 0 || state < 0)
+                       if ((j < 0) || (state < 0))
                        {
                                *tk++ = SYMBOL;
 //#warning
index fa8b08b7188604ec01b4a29ff7977bd3165ddf7a..b95358f85a41dca0a769766611662382319c0c45 100644 (file)
--- a/version.h
+++ b/version.h
@@ -13,6 +13,6 @@
 
 #define MAJOR   1              // Major version number
 #define MINOR   4              // Minor version number
-#define PATCH   11             // Patch release number
+#define PATCH   12             // Patch release number
 
 #endif // __VERSION_H__