From 622cef2655a59d715480af165caed8cd4ba0040c Mon Sep 17 00:00:00 2001 From: ggn Date: Mon, 16 Nov 2015 13:54:03 +0200 Subject: [PATCH 01/16] TEXT/DATA/BSS sizes printed at the end of assembly only when -v is invoked. --- object.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/object.c b/object.c index baed1bd..cef73ee 100644 --- a/object.c +++ b/object.c @@ -220,6 +220,13 @@ int WriteObject(int fd) LONG trsize, drsize; // Size of relocations long unused; // For supressing 'write' warnings + if (verb_flag) + { + printf("TEXT segment: %d bytes\n", sect[TEXT].sloc); + printf("DATA segment: %d bytes\n", sect[DATA].sloc); + printf("BSS segment: %d bytes\n", sect[BSS].sloc); + } + // Write requested object file... switch (obj_format) { -- 2.37.2 From 917bfc1503181b7e762b73b9560bb834c12c64fa Mon Sep 17 00:00:00 2001 From: ggn Date: Mon, 16 Nov 2015 13:53:02 +0200 Subject: [PATCH 02/16] Extended switch -s to also warn about automatically applied 68000 optimisations. Added switch -w to turn off all automatic optimisations. --- mach.c | 9 +++++++-- parmode.h | 6 +++++- rmac.c | 9 ++++++++- rmac.h | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mach.c b/mach.c index 46193d7..b3e36c7 100644 --- a/mach.c +++ b/mach.c @@ -13,6 +13,7 @@ #include "token.h" #include "procln.h" #include "riscasm.h" +#include "rmac.h" #define DEF_KW #include "kwtab.h" @@ -439,10 +440,12 @@ int m_move(WORD inst, WORD size) int siz = (int)size; // Try to optimize to MOVEQ - if (siz == SIZL && am0 == IMMED && am1 == DREG + if (optim_flag && siz == SIZL && am0 == IMMED && am1 == DREG && (a0exattr & (TDB|DEFINED)) == DEFINED && a0exval + 0x80 < 0x100) { m_moveq((WORD)0x7000, (WORD)0); + if (sbra_flag) + warn("move.l #size,dx converted to moveq"); } else { @@ -555,11 +558,13 @@ int m_br(WORD inst, WORD siz) // Optimize branch instr. size if (siz == SIZN) { - if (v != 0 && v + 0x80 < 0x100) + if (optim_flag && v != 0 && v + 0x80 < 0x100) { // Fits in .B inst |= v & 0xFF; D_word(inst); + if (sbra_flag) + warn("Bcc.w/BSR.w converted to .s"); return 0; } else diff --git a/parmode.h b/parmode.h index 38f6f94..c72b470 100644 --- a/parmode.h +++ b/parmode.h @@ -252,8 +252,12 @@ CHK_FOR_DISPn: // Defined, absolute values from $FFFF8000..$00007FFF get optimized // to absolute short - if ((AnEXATTR & (TDB|DEFINED)) == DEFINED && (AnEXVAL + 0x8000) < 0x10000) + if (optim_flag && (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) diff --git a/rmac.c b/rmac.c index 0683739..910cb88 100644 --- a/rmac.c +++ b/rmac.c @@ -45,7 +45,7 @@ char * firstfname; // First source filename char * cmdlnexec; // Executable name, pointer to ARGV[0] char * searchpath; // Search path for include files char defname[] = "noname.o"; // Default output filename - +int optim_flag; // Optimise all the things! // // Manipulate file extension. @@ -142,7 +142,9 @@ void DisplayHelp(void) " d: double phrase (16 bytes)\n" " q: quad phrase (32 bytes)\n" " -s Warn about possible short branches\n" + " and applied optimisations\n" " -u Force referenced and undefined symbols global\n" + " -w Turn off optimisations done automatically\n" " -v Set verbose mode\n" " -y[pagelen] Set page line length (default: 61)\n" "\n", cmdlnexec); @@ -200,6 +202,7 @@ int Process(int argc, char ** argv) orgactive = 0; // Not in RISC org section orgwarning = 0; // No ORG warning issued segpadsize = 2; // Initialise segment padding size + optim_flag = 1; // Automatically optimise // Initialise modules InitSymbolTable(); // Symbol table @@ -357,6 +360,10 @@ int Process(int argc, char ** argv) DisplayVersion(); break; + case 'w': + case 'W': + optim_flag=0; + break; case 'x': // Turn on debugging case 'X': debug = 1; diff --git a/rmac.h b/rmac.h index 25d2afd..f7b39e3 100644 --- a/rmac.h +++ b/rmac.h @@ -211,6 +211,7 @@ extern int sbra_flag; extern int obj_format; extern int legacy_flag; extern LONG PRGFLAGS; +extern int optim_flag; // Exported functions char * fext(char *, char *, int); -- 2.37.2 From d62afdca3afd97820bcc18c8e95ef19c374174e6 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Tue, 17 Nov 2015 07:42:32 -0600 Subject: [PATCH 03/16] Bump version #. --- version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.h b/version.h index 47c0b7b..1df3fbd 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 4 // Minor version number -#define PATCH 3 // Patch release number +#define PATCH 4 // Patch release number #endif // __VERSION_H__ -- 2.37.2 From 0e4dead2b7d779a6b1612554afa62f3a198dcdfb Mon Sep 17 00:00:00 2001 From: ggn Date: Tue, 17 Nov 2015 19:19:39 +0200 Subject: [PATCH 04/16] The rest of the .PRGFLAGS patch. Sorry! --- object.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/object.c b/object.c index cef73ee..82fc76a 100644 --- a/object.c +++ b/object.c @@ -231,6 +231,10 @@ int WriteObject(int fd) switch (obj_format) { case BSD: + if (verb_flag) + { + printf("Total : %d bytes\n", sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc); + } ssize = ((LONG)sy_assign(NULL, NULL)); // Assign index numbers to the symbols tds = sect[TEXT].sloc + sect[DATA].sloc; // Get size of TEXT and DATA segment buf = malloc(0x600000); // Allocate 6mb object file image memory @@ -311,6 +315,18 @@ int WriteObject(int fd) break; case ALCYON: + if (verb_flag) + { + if (prg_flag) + { + printf("TOS header : 28 bytes\n"); + printf("Total : %d bytes\n", 28 + sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc); + } + else + { + printf("Total : %d bytes\n", sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc); + } + } /* * Compute size of symbol table; * assign numbers to the symbols... @@ -329,24 +345,24 @@ int WriteObject(int fd) if (t < ssize) t = ssize; - buf = malloc(t + HDRSIZE) + HDRSIZE; + buf = (char *)((int)malloc(t + HDRSIZE) + HDRSIZE); /* * Build object file header * just before the text+data image */ chptr = buf - HDRSIZE; /* -> base of header */ - D_word(0x601a); /* magic number */ - t = sect[TEXT].sloc; /* TEXT size */ + D_word(0x601a); /* 00 - magic number */ + t = sect[TEXT].sloc; /* 02 - TEXT size */ D_long(t); - t = sect[DATA].sloc; /* DATA size */ + t = sect[DATA].sloc; /* 06 - DATA size */ D_long(t); - t = sect[BSS].sloc; /* BSS size */ + t = sect[BSS].sloc; /* 0a - BSS size */ D_long(t); - D_long(ssize); /* symbol table size */ - D_long(0); /* stack size (unused) */ - D_long(0); /* entry point (unused) */ - D_word(0); /* relocation information exists */ + D_long(ssize); /* 0e - symbol table size */ + D_long(0); /* 12 - stack size (unused) */ + D_long(PRGFLAGS); /* 16 - PRGFLAGS */ + D_word(0); /* 1a - relocation information exists */ /* * Construct text and data segments; -- 2.37.2 From 1d8c5b2261388e34637a41f82104718fdd06044b Mon Sep 17 00:00:00 2001 From: ggn Date: Tue, 17 Nov 2015 19:05:00 +0200 Subject: [PATCH 05/16] Moved some messages from -v to -x --- direct.c | 2 +- procln.c | 2 +- rmac.c | 1 + token.c | 20 ++++++++++---------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/direct.c b/direct.c index 750d587..e96aacb 100644 --- a/direct.c +++ b/direct.c @@ -772,7 +772,7 @@ int d_bss(void) // int d_ds(WORD siz) { -if (verb_flag) +if (debug) printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); VALUE eval; diff --git a/procln.c b/procln.c index 5860734..04b8ddd 100644 --- a/procln.c +++ b/procln.c @@ -137,7 +137,7 @@ loop: // Line processing loop label // Get another line of tokens if (TokenizeLine() == TKEOF) { -if (verb_flag) printf("Assemble: Found TKEOF flag...\n"); +if (debug) printf("Assemble: Found TKEOF flag...\n"); if (list_flag && listflag) // Flush last line of source listeol(); diff --git a/rmac.c b/rmac.c index 910cb88..ee8d9ee 100644 --- a/rmac.c +++ b/rmac.c @@ -146,6 +146,7 @@ void DisplayHelp(void) " -u Force referenced and undefined symbols global\n" " -w Turn off optimisations done automatically\n" " -v Set verbose mode\n" + " -x Turn on debugging mode\n" " -y[pagelen] Set page line length (default: 61)\n" "\n", cmdlnexec); } diff --git a/token.c b/token.c index 3031895..66399d6 100644 --- a/token.c +++ b/token.c @@ -679,8 +679,8 @@ int include(int handle, char * fname) INOBJ * inobj; FILEREC * fr; - // Verbose mode - if (verb_flag) + // Debug mode + if (debug) printf("[include: %s, cfileno=%u]\n", fname, cfileno); // Alloc and initialize include-descriptors @@ -742,21 +742,21 @@ int fpop(void) switch (inobj->in_type) { case SRC_IFILE: // Pop and release an IFILE - if (verb_flag) + if (debug) printf("[Leaving: %s]\n", curfname); ifile = inobj->inobj.ifile; ifile->if_link = f_ifile; f_ifile = ifile; close(ifile->ifhandle); // Close source file -if (verb_flag) printf("[fpop (pre): curfname=%s]\n", curfname); +if (debug) 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); +if (debug) printf("[fpop (post): curfname=%s]\n", curfname); +if (debug) 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); cfileno = ifile->ifno; // Restore current file number -if (verb_flag) printf("[fpop: (post) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno); +if (debug) 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; @@ -911,8 +911,8 @@ retry: case SRC_IFILE: if ((ln = GetNextLine()) == NULL) { -if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); - if (fpop() == 0) // Pop input level +if (debug) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); + if (fpop()==0) // Pop input level goto retry; // Try for more lines else { @@ -965,7 +965,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); case SRC_IREPT: if ((ln = GetNextRepeatLine()) == NULL) { -if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); +if (debug) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); fpop(); goto retry; } -- 2.37.2 From c7c27ef02a3d5c7d17e5728910961a4a1eeacfe3 Mon Sep 17 00:00:00 2001 From: ggn Date: Tue, 17 Nov 2015 18:59:56 +0200 Subject: [PATCH 06/16] .error and .warn directives implemented. --- direct.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/direct.c b/direct.c index e96aacb..1750272 100644 --- a/direct.c +++ b/direct.c @@ -77,8 +77,8 @@ int (*dirtab[])() = { d_title, // 44 title d_subttl, // 45 subttl eject, // 46 eject - d_unimpl, // 47 error - d_unimpl, // 48 warn + d_error, // 47 error + d_warn, // 48 warn d_noclear, // 49 .noclear d_equrundef, // 50 .equrundef/.regundef d_ccundef, // 51 .ccundef @@ -91,6 +91,48 @@ int (*dirtab[])() = { }; +// +// .error - Abort compilation, printing an error message +// +int d_error(char *str) +{ + if (*tok == EOL) + return error("error directive encountered - aborting assembling"); + else + { + switch(*tok) + { + case STRING: + return error(string[tok[1]]); + break; + default: + return error("error directive encountered - aborting assembling"); + } + } +} + + +// +// .warn - Just display a warning on screen +// +int d_warn(char *str) +{ + if (*tok == EOL) + return warn("WARNING WARNING WARNING"); + else + { + switch(*tok) + { + case STRING: + return warn(string[tok[1]]); + break; + default: + return warn("WARNING WARNING WARNING"); + } + } +} + + // // .org - Set origin // -- 2.37.2 From fda6ba86616d173dfb43c84c2e2b11eac099d85b Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Tue, 17 Nov 2015 14:01:56 -0600 Subject: [PATCH 07/16] Bump version #. --- version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.h b/version.h index 1df3fbd..97f1919 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 4 // Minor version number -#define PATCH 4 // Patch release number +#define PATCH 5 // Patch release number #endif // __VERSION_H__ -- 2.37.2 From 21b541fc477234e0823876eabf8ee556eb94c78e Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sun, 6 Dec 2015 21:29:06 -0600 Subject: [PATCH 08/16] Removed naked 'abs' (sans leading dot) from mntab. The problem with having .abs *and* abs (as an alternate) is that the naked abs conflicts with the RISC asm instruction ABS R#. There's no good way to detect this ahead time, and it's a bad idea to do so anyway. So don't do it! --- direct.c | 1 + mntab | 1 - version.h | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/direct.c b/direct.c index 1750272..89e4ee0 100644 --- a/direct.c +++ b/direct.c @@ -997,6 +997,7 @@ int d_dcb(WORD siz) VALUE evalc, eval; WORD eattr; +printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); if ((scattr & SBSS) != 0) return error("illegal initialization of section"); diff --git a/mntab b/mntab index 25dc52b..9bbc003 100644 --- a/mntab +++ b/mntab @@ -12,7 +12,6 @@ text 6 .offset 7 offset 7 .abs 7 -abs 7 .comm 8 comm 8 .init 9 diff --git a/version.h b/version.h index 97f1919..906bea9 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 4 // Minor version number -#define PATCH 5 // Patch release number +#define PATCH 6 // Patch release number #endif // __VERSION_H__ -- 2.37.2 From 5373852f573b91ebda175d3dc7fc111e2c5ca872 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 24 Dec 2015 14:36:53 -0600 Subject: [PATCH 09/16] Possible fix for bug #68 (crash when running on ARM). --- token.c | 4 ++-- version.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/token.c b/token.c index 66399d6..cd3c2ff 100644 --- a/token.c +++ b/token.c @@ -1213,12 +1213,12 @@ if (debug) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *p++ = EOS; continue; case '$': // $, hex constant - if ((int)chrtab[*ln] & HDIGIT) + if (chrtab[*ln] & HDIGIT) { v = 0; // Parse the hex value - while ((int)hextab[*ln] >= 0) + while (hextab[*ln] >= 0) v = (v << 4) + (int)hextab[*ln++]; // ggn: Okay, some comments here are in order I think.... diff --git a/version.h b/version.h index 906bea9..7e04041 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 4 // Minor version number -#define PATCH 6 // Patch release number +#define PATCH 7 // Patch release number #endif // __VERSION_H__ -- 2.37.2 From 9e2fe1917a6ad9127e620eb908bba20421e52c89 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 7 Jan 2016 07:35:17 -0600 Subject: [PATCH 10/16] Hopefully final fix for bug #68 (crash on ARM). --- token.c | 2 +- version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/token.c b/token.c index cd3c2ff..7bba199 100644 --- a/token.c +++ b/token.c @@ -24,7 +24,7 @@ int mjump_align = 0; // mjump alignment flag char lntag; // Line tag char * curfname; // Current filename char tolowertab[128]; // Uppercase ==> lowercase -char hextab[128]; // Table of hex values +int8_t hextab[128]; // Table of hex values char dotxtab[128]; // Table for ".b", ".s", etc. char irbuf[LNSIZ]; // Text for .rept block line char lnbuf[LNSIZ]; // Text of current line diff --git a/version.h b/version.h index 7e04041..a6cbffd 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 4 // Minor version number -#define PATCH 7 // Patch release number +#define PATCH 8 // Patch release number #endif // __VERSION_H__ -- 2.37.2 From bbaae2c20d534943356e82ebd22ca5425a1868d9 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Fri, 15 Apr 2016 09:56:45 -0500 Subject: [PATCH 11/16] Fix for bug #71 (thanks to ggn for reporting! :-) --- direct.c | 6 +++--- version.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/direct.c b/direct.c index 89e4ee0..c0b5be5 100644 --- a/direct.c +++ b/direct.c @@ -814,8 +814,7 @@ int d_bss(void) // int d_ds(WORD siz) { -if (debug) - printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); + DEBUG { printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); } VALUE eval; @@ -997,7 +996,8 @@ int d_dcb(WORD siz) VALUE evalc, eval; WORD eattr; -printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); + DEBUG { printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); } + if ((scattr & SBSS) != 0) return error("illegal initialization of section"); diff --git a/version.h b/version.h index a6cbffd..c8fe5b5 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 4 // Minor version number -#define PATCH 8 // Patch release number +#define PATCH 9 // Patch release number #endif // __VERSION_H__ -- 2.37.2 From ae7127773aa49608da898bb9f9a0e5f87a3c1816 Mon Sep 17 00:00:00 2001 From: ggn Date: Wed, 27 Apr 2016 22:58:42 +0300 Subject: [PATCH 12/16] When selecting ST .o output (-fa), don't write a .prg but an object file instead. --- object.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/object.c b/object.c index 82fc76a..590f263 100644 --- a/object.c +++ b/object.c @@ -228,9 +228,8 @@ int WriteObject(int fd) } // Write requested object file... - switch (obj_format) - { - case BSD: + if (obj_format==BSD || (obj_format==ALCYON && prg_flag==0)) + { if (verb_flag) { printf("Total : %d bytes\n", sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc); @@ -312,9 +311,9 @@ int WriteObject(int fd) if (buf) free(buf); // Free allocated memory - break; - - case ALCYON: + } + else if (obj_format==ALCYON) + { if (verb_flag) { if (prg_flag) @@ -400,7 +399,6 @@ int WriteObject(int fd) */ tds = markimg(buf, tds, sect[TEXT].sloc, 1); write(fd, buf, tds); - break; } return 0; -- 2.37.2 From bf97c76e7e6a87b0495cb037b094b6d8b5027a40 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sun, 8 May 2016 08:56:55 -0500 Subject: [PATCH 13/16] Version bump. Thanks to ggn for the report & patch (bug #73)! --- version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.h b/version.h index c8fe5b5..5354b8e 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 4 // Minor version number -#define PATCH 9 // Patch release number +#define PATCH 10 // Patch release number #endif // __VERSION_H__ -- 2.37.2 From e968236d060c7dbae1647d5f54b27d4070b63b06 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Mon, 9 May 2016 13:13:41 -0500 Subject: [PATCH 14/16] Possible fix for bug #72 (no warning on unclosed .ifs). --- procln.c | 5 ++--- token.c | 18 +++++++++++++----- version.h | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/procln.c b/procln.c index 04b8ddd..3b8c607 100644 --- a/procln.c +++ b/procln.c @@ -36,7 +36,6 @@ static IFENT * f_ifent; // Freelist of ifents static int disabled; // Assembly conditionally disabled int just_bss; // 1, ds.b in microprocessor mode VALUE pcloc; // Value of "PC" at beginning of line -IFENT * ifent; // Current ifent SYM * lab_sym; // Label on line (or NULL) const char extra_stuff[] = "extra (unexpected) text found after addressing mode"; @@ -265,13 +264,13 @@ as68label: switch (state) { case MN_IF: - d_if (); + d_if(); goto loop; case MN_ELSE: d_else(); goto loop; case MN_ENDIF: - d_endif (); + d_endif(); goto loop; case MN_IIF: // .iif --- immediate if if (disabled || expr(exprbuf, &eval, &eattr, &esym) != OK) diff --git a/token.c b/token.c index 7bba199..77fec1e 100644 --- a/token.c +++ b/token.c @@ -730,18 +730,26 @@ int fpop(void) { // Pop IFENT levels until we reach the conditional assembly context we // were at when the input object was entered. + int numUnmatched = 0; + while (ifent != inobj->in_ifent) { - if (d_endif() != 0) // Something bad happened during endif parsing? - return -1; // If yes, bail instead of getting stuck in a loop + if (d_endif() != 0) // Something bad happened during endif parsing? + return -1; // If yes, bail instead of getting stuck in a loop + + numUnmatched++; } - tok = inobj->in_otok; // Restore tok and otok + // Give a warning to the user that we had to wipe their bum for them + if (numUnmatched > 0) + warni("missing %d .endif(s)", numUnmatched); + + tok = inobj->in_otok; // Restore tok and otok etok = inobj->in_etok; switch (inobj->in_type) { - case SRC_IFILE: // Pop and release an IFILE + case SRC_IFILE: // Pop and release an IFILE if (debug) printf("[Leaving: %s]\n", curfname); @@ -912,7 +920,7 @@ retry: if ((ln = GetNextLine()) == NULL) { if (debug) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); - if (fpop()==0) // Pop input level + if (fpop() == 0) // Pop input level goto retry; // Try for more lines else { diff --git a/version.h b/version.h index 5354b8e..fa8b08b 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 4 // Minor version number -#define PATCH 10 // Patch release number +#define PATCH 11 // Patch release number #endif // __VERSION_H__ -- 2.37.2 From 40f1a3ec69fd0f0dade867d8ffcb840add5b21f1 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sun, 15 May 2016 18:25:37 -0500 Subject: [PATCH 15/16] Fix for bug #67 (thanks to ggn for reporting!). 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 | 39 +++++++++++++++++---------------------- token.c | 31 ++++++++++++++++++++++++++----- version.h | 2 +- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/mach.c b/mach.c index b3e36c7..ae5065b 100644 --- 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 #,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 77fec1e..5b3d073 100644 --- 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 diff --git a/version.h b/version.h index fa8b08b..b95358f 100644 --- 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__ -- 2.37.2 From 171a457e86f686cf2adddc91baa9d9e703264259 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Mon, 12 Sep 2016 19:16:03 -0500 Subject: [PATCH 16/16] Small fix to make compilation C99 compliant. This probably won't help on Visual Studio, unless you can tell the build system there to use a C99 compliant compiler (MS's track record in this area is abysmal). --- makefile | 2 +- rmac.h | 41 +++++++++++++++-------------------------- version.h | 2 +- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/makefile b/makefile index 33b9cfe..cd52ffe 100644 --- a/makefile +++ b/makefile @@ -8,7 +8,7 @@ rm = /bin/rm -f CC = $(CROSS)gcc HOSTCC = gcc -CFLAGS = -g -D__GCCUNIX__ -I. -O2 +CFLAGS = -std=c99 -g -D__GCCUNIX__ -I. -O2 SRCS = amode.c debug.c direct.c eagen.c error.c expr.c listing.c mach.c macro.c mark.c object.c procln.c riscasm.c rmac.c sect.c symbol.c token.c diff --git a/rmac.h b/rmac.h index f7b39e3..337096d 100644 --- a/rmac.h +++ b/rmac.h @@ -9,10 +9,19 @@ #ifndef __RMAC_H__ #define __RMAC_H__ +#include +#include +#include +#include +#include +#include + // // TARGET SPECIFIC BUILD SETTINGS // #if defined(WIN32) || defined (WIN64) + #include + #include // Release platform - windows #define PLATFORM "Win32" #define _OPEN_FLAGS _O_TRUNC|_O_CREAT|_O_BINARY|_O_RDWR @@ -40,49 +49,29 @@ #define WARNING(desc) DO_PRAGMA(message (#desc)) #endif - #include - #include - #include - #include - #include - #include - #include - #include #else #ifdef __GCCUNIX__ + #include + #include // Release platform - mac OS-X or linux #define PLATFORM "OSX/Linux" #define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR #define _OPEN_INC O_RDONLY - #define _PERM_MODE S_IREAD|S_IWRITE + #define _PERM_MODE S_IRUSR|S_IWUSR // WARNING WARNING WARNING #define DO_PRAGMA(x) _Pragma (#x) #define WARNING(desc) DO_PRAGMA(message (#desc)) - #include - #include - #include - #include - #include - #include - #include - #include #else // Release platform - not specified + #include #define PLATFORM "Unknown" #define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR #define _OPEN_INC O_RDONLY - #define _PERM_MODE S_IREAD|S_IWRITE - // Defined here, even though the platfrom may not support it... + #define _PERM_MODE S_IREAD|S_IWRITE + // Defined here, even though the platform may not support it... #define DO_PRAGMA(x) _Pragma (#x) #define WARNING(desc) DO_PRAGMA(message (#desc)) - #include - #include - #include - #include - #include - #include - #include #endif #endif diff --git a/version.h b/version.h index b95358f..b4f423c 100644 --- a/version.h +++ b/version.h @@ -13,6 +13,6 @@ #define MAJOR 1 // Major version number #define MINOR 4 // Minor version number -#define PATCH 12 // Patch release number +#define PATCH 13 // Patch release number #endif // __VERSION_H__ -- 2.37.2