Write .lst after the second pass. (#375)

This commit is contained in:
Y-Less 2018-10-24 11:07:00 +02:00 committed by Barnaby Keene
parent 19dabbbeb0
commit 9a16724b6a
4 changed files with 36 additions and 25 deletions

View File

@ -280,6 +280,7 @@ enum {
enum {
statIDLE, /* not compiling yet */
statFIRST, /* first pass */
statSECOND, /* second pass */
statWRITE, /* writing output */
statSKIP, /* skipping output */
};

View File

@ -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 */

View File

@ -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++;

View File

@ -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);