From 9a16724b6ae09713d2d8df1333dc4fd9f53126c0 Mon Sep 17 00:00:00 2001 From: Y-Less Date: Wed, 24 Oct 2018 11:07:00 +0200 Subject: [PATCH] Write `.lst` after the second pass. (#375) --- source/compiler/sc.h | 1 + source/compiler/sc1.c | 54 +++++++++++++++++++++++++------------------ source/compiler/sc2.c | 2 +- source/compiler/sc4.c | 4 ++-- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index e417ae9..23ef5a9 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -280,6 +280,7 @@ enum { enum { statIDLE, /* not compiling yet */ statFIRST, /* first pass */ + statSECOND, /* second pass */ statWRITE, /* writing output */ statSKIP, /* skipping output */ }; diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index fcec5ec..2ead157 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -575,20 +575,6 @@ int pc_compile(int argc, char *argv[]) fline++; /* keep line number up to date */ skipinput=fline; sc_status=statFIRST; - /* write starting options (from the command line or the configuration file) */ - if (sc_listing) { - char string[150]; - sprintf(string,"#pragma ctrlchar 0x%02x\n" - "#pragma pack %s\n" - "#pragma semicolon %s\n" - "#pragma tabsize %d\n", - sc_ctrlchar, - sc_packstr ? "true" : "false", - sc_needsemicolon ? "true" : "false", - sc_tabsize); - pc_writeasm(outf,string); - } /* if */ - setfiledirect(inpfname); /* do the first pass through the file (or possibly two or more "first passes") */ sc_parsenum=0; inpfmark=pc_getpossrc(inpf_org); @@ -629,7 +615,10 @@ int pc_compile(int argc, char *argv[]) } while (sc_reparse); /* second (or third) pass */ - sc_status=statWRITE; /* set, to enable warnings */ + if (sc_listing) + sc_status=statSECOND; + else + sc_status=statWRITE; /* set, to enable warnings */ state_conflict(&glbtab); /* write a report, if requested */ @@ -649,8 +638,28 @@ int pc_compile(int argc, char *argv[]) } /* if */ } /* if */ #endif - if (sc_listing) - goto cleanup; + + sc_ctrlchar=sc_ctrlchar_org; + sc_packstr=lcl_packstr; + sc_needsemicolon=lcl_needsemicolon; + sc_tabsize=lcl_tabsize; + + /*if (sc_listing) + goto cleanup;*/ + /* write starting options (from the command line or the configuration file) */ + if (sc_listing) { + char string[150]; + sprintf(string,"#pragma ctrlchar 0x%02x\n" + "#pragma pack %s\n" + "#pragma semicolon %s\n" + "#pragma tabsize %d\n", + sc_ctrlchar, + sc_packstr ? "true" : "false", + sc_needsemicolon ? "true" : "false", + sc_tabsize); + pc_writeasm(outf,string); + } /* if */ + setfiledirect(inpfname); /* ??? for re-parsing the listing file instead of the original source * file (and doing preprocessing twice): @@ -666,10 +675,6 @@ int pc_compile(int argc, char *argv[]) delete_substtable(); #endif resetglobals(); - sc_ctrlchar=sc_ctrlchar_org; - sc_packstr=lcl_packstr; - sc_needsemicolon=lcl_needsemicolon; - sc_tabsize=lcl_tabsize; errorset(sRESET,0); /* reset the source file */ inpf=inpf_org; @@ -677,7 +682,10 @@ int pc_compile(int argc, char *argv[]) pc_resetsrc(inpf,inpfmark); /* reset file position */ fline=skipinput; /* reset line number */ lexinit(); /* clear internal flags of lex() */ - sc_status=statWRITE; /* allow to write --this variable was reset by resetglobals() */ + if (sc_listing) + sc_status=statSECOND; + else + sc_status=statWRITE; /* allow to write --this variable was reset by resetglobals() */ setstringconstants(); writeleader(&glbtab); setfileconst(inpfname); @@ -690,6 +698,8 @@ int pc_compile(int argc, char *argv[]) } /* if */ preprocess(); /* fetch first line */ parse(); /* process all input */ + if (sc_listing) + goto cleanup; /* inpf is already closed when readline() attempts to pop of a file */ writetrailer(); /* write remaining stuff */ diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 3398c59..6f627c2 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -1911,7 +1911,7 @@ SC_FUNC void preprocess(void) lptr=pline; /* reset "line pointer" to start of the parsing buffer */ } /* if */ #endif - if (sc_status==statFIRST && sc_listing && freading + if (sc_status==statSECOND && freading && (iscommand==CMD_NONE || iscommand==CMD_EMPTYLINE || iscommand==CMD_DIRECTIVE)) { listline++; diff --git a/source/compiler/sc4.c b/source/compiler/sc4.c index 0f5d1af..a11d3eb 100644 --- a/source/compiler/sc4.c +++ b/source/compiler/sc4.c @@ -263,7 +263,7 @@ SC_FUNC void setline(int chkbounds) SC_FUNC void setfiledirect(char *name) { - if (sc_status==statFIRST && sc_listing) { + if (sc_status==statSECOND && sc_listing) { assert(name!=NULL); pc_writeasm(outf,"\n#file \""); pc_writeasm(outf,name); @@ -281,7 +281,7 @@ SC_FUNC void setfileconst(char *name) SC_FUNC void setlinedirect(int line) { - if (sc_status==statFIRST && sc_listing) { + if (sc_status==statSECOND && sc_listing) { char string[40]; sprintf(string,"#line %d\n",line); pc_writeasm(outf,string);