]> Shamusworld >> Repos - rmac/blobdiff - token.c
Fix for slow .incbin performance.
[rmac] / token.c
diff --git a/token.c b/token.c
index 2877b481172bb209c3deae622e100629fa126e6a..53f76a98c2e283e4e9042c4987aac4d081201e54 100644 (file)
--- a/token.c
+++ b/token.c
@@ -16,6 +16,7 @@
 #define DEF_KW                         // Declare keyword values 
 #include "kwtab.h"                     // Incl generated keyword tables & defs
 
+
 int lnsave;                                    // 1; strcpy() text of current line
 int curlineno;                         // Current line number
 int totlines;                          // Total # of lines
@@ -116,34 +117,10 @@ static char * riscregname[] = {
 };
 
 
-// Removing this, provided it doesn't cause unwanted side-effects :-P
-#if 0
-//
-// Make `fnum' the Current `curfname'
-// NOTE: This is currently only called from error() in error.c
-//
-void setfnum(WORD fnum)
+void SetFilenameForErrorReporting(void)
 {
-#if 0
-       // NOTE: fnum is ZERO based, this can cause problems if you're not careful!
-       FILEREC * fr = filerec;
-
-       DEBUG printf("[setfnum: fnum=%u]\n", fnum);
-
-       // Advance to the correct record...
-       while (fr != NULL && fnum != 0)
-       {
-               fr = fr->frec_next;
-               fnum--;
-       }
+       WORD fnum = cfileno;
 
-       if (fr == NULL)
-               curfname = "(*top*)";
-       else
-               curfname = fr->frec_name;
-
-       DEBUG printf("[setfnum: curfname=%s]\n", curfname);
-#else
        // Check for absolute top filename (this should never happen)
        if (fnum == -1)
        {
@@ -168,9 +145,7 @@ void setfnum(WORD fnum)
        }
 
        curfname = fr->frec_name;
-#endif
 }
-#endif
 
 
 //
@@ -604,6 +579,8 @@ char * getmln(void)
 //     ExpandMacro((char *)(strp + 1), imacro->im_lnbuf, LNSIZ);
        ExpandMacro(strp->line, imacro->im_lnbuf, LNSIZ);
 
+// bollocks
+#if 0
        if (!strcmp(imacro->im_macro->sname, "mjump") && !mjump_align)
        {
                // if we need to adjust the alignment of the jump source address to
@@ -627,6 +604,7 @@ char * getmln(void)
 
                mjump_align = 1;
        }
+#endif
 
        return imacro->im_lnbuf;
 }
@@ -653,7 +631,7 @@ char * getrln(void)
                        return NULL;
                }
 
-               strp = irept->ir_nextln;                        //strp
+               strp = irept->ir_nextln;
        }
 
        strcpy(irbuf, (char *)(irept->ir_nextln + 1));
@@ -686,13 +664,14 @@ int include(int handle, char * fname)
        ifile->ifoldlineno = curlineno;                 // Save old line number
        ifile->ifoldfname = curfname;                   // Save old filename
        ifile->ifno = cfileno;                                  // Save old file number
+
 //     cfileno = filecount++;                                  // Compute new file number
-       cfileno = ++filecount;                                  // Compute new file number
+       // NB: This *must* be preincrement, we're adding one to the filecount here!
+       cfileno = ++filecount;                                  // Compute NEW file number
        curfname = strdup(fname);                               // Set current filename (alloc storage)
        curlineno = 0;                                                  // Start on line zero
 
        // Add another file to the file-record
-//     fr = (FILEREC *)amem((LONG)sizeof(FILEREC));
        fr = (FILEREC *)malloc(sizeof(FILEREC));
        fr->frec_next = NULL;
        fr->frec_name = curfname;
@@ -703,9 +682,7 @@ int include(int handle, char * fname)
                last_fr->frec_next = fr;                        // Append to list of filerecs 
 
        last_fr = fr;
-
-       if (verb_flag)
-               printf("[include: curfname: %s, cfileno=%u]\n", curfname, cfileno);
+       DEBUG printf("[include: curfname: %s, cfileno=%u]\n", curfname, cfileno);
 
        return OK;
 }
@@ -795,10 +772,11 @@ int fpop(void)
 if (verb_flag) printf("[fpop (pre):  curfname=%s]\n", curfname);
                        curfname = ifile->ifoldfname;   // Set current filename
 if (verb_flag) printf("[fpop (post): curfname=%s]\n", curfname);
+if (verb_flag) printf("[fpop: (pre)  cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno);
                        curlineno = ifile->ifoldlineno; // Set current line# 
                        DEBUG printf("cfileno=%d ifile->ifno=%d\n", (int)cfileno, (int)ifile->ifno);
-if (verb_flag) printf("[fpop:        cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno);
                        cfileno = ifile->ifno;                  // Restore current file number
+if (verb_flag) printf("[fpop: (post) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno);
                        break;
                case SRC_IMACRO:                                        // Pop and release an IMACRO
                        imacro = inobj->inobj.imacro;
@@ -947,6 +925,7 @@ int tokln(void)
        case SRC_IFILE:
                if ((ln = getln()) == NULL)
                {
+if (verb_flag) printf("tokln: Calling fpop() from SRC_IFILE...\n");
                        fpop();                                                 // Pop input level
                        goto retry;                                             // Try for more lines 
                }
@@ -993,6 +972,7 @@ int tokln(void)
        case SRC_IREPT:
                if ((ln = getrln()) == NULL)
                {
+if (verb_flag) printf("tokln: Calling fpop() from SRC_IREPT...\n");
                        fpop();
                        goto retry;
                }
@@ -1578,6 +1558,7 @@ int d_goto(WORD unused)
        return error("goto label not found");
 }
 
+
 void DumpTokenBuffer(void)
 {
        TOKEN * t;
@@ -1666,3 +1647,4 @@ void DumpTokenBuffer(void)
 
        printf("[EOL]\n");
 }
+