Skip to content

Commit 6aa5ae3

Browse files
committed
Fix conditional compilation not skipping #emit directives
#emit directives inside #if ... #endif blocks were processed by the compiler regardless of the condition. --------- test code -------- main() { #if 0 #emit halt 1 #endif } ----- end of test code -----
1 parent e0a61e5 commit 6aa5ae3

File tree

1 file changed

+64
-62
lines changed

1 file changed

+64
-62
lines changed

source/compiler/sc2.c

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,72 +1228,74 @@ static int command(void)
12281228
break;
12291229
#if !defined NOEMIT
12301230
case tpEMIT: {
1231-
/* write opcode to output file */
1232-
char name[40];
1233-
int i;
1234-
while (*lptr<=' ' && *lptr!='\0')
1235-
lptr++;
1236-
for (i=0; i<40 && (isalpha(*lptr) || *lptr=='.'); i++,lptr++)
1237-
name[i]=(char)tolower(*lptr);
1238-
name[i]='\0';
1239-
stgwrite("\t");
1240-
stgwrite(name);
1241-
stgwrite(" ");
1242-
code_idx+=opcodes(1);
1243-
/* write parameter (if any) */
1244-
while (*lptr<=' ' && *lptr!='\0')
1245-
lptr++;
1246-
if (*lptr!='\0') {
1247-
symbol *sym;
1248-
tok=lex(&val,&str);
1249-
switch (tok) {
1250-
case tNUMBER:
1251-
case tRATIONAL:
1252-
outval(val,FALSE);
1253-
code_idx+=opargs(1);
1254-
break;
1255-
case tSYMBOL:
1256-
sym=findloc(str);
1257-
if (sym==NULL)
1258-
sym=findglb(str,sSTATEVAR);
1259-
if (sym==NULL || sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) {
1260-
error(17,str); /* undefined symbol */
1261-
} else {
1262-
if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) {
1263-
if ((sym->usage & uNATIVE)!=0) {
1264-
/* reserve a SYSREQ id if called for the first time */
1265-
if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0)
1266-
sym->addr=ntv_funcid++;
1267-
outval(sym->addr,FALSE);
1231+
if (!SKIPPING) {
1232+
/* write opcode to output file */
1233+
char name[40];
1234+
int i;
1235+
while (*lptr<=' ' && *lptr!='\0')
1236+
lptr++;
1237+
for (i=0; i<40 && (isalpha(*lptr) || *lptr=='.'); i++,lptr++)
1238+
name[i]=(char)tolower(*lptr);
1239+
name[i]='\0';
1240+
stgwrite("\t");
1241+
stgwrite(name);
1242+
stgwrite(" ");
1243+
code_idx+=opcodes(1);
1244+
/* write parameter (if any) */
1245+
while (*lptr<=' ' && *lptr!='\0')
1246+
lptr++;
1247+
if (*lptr!='\0') {
1248+
symbol *sym;
1249+
tok=lex(&val,&str);
1250+
switch (tok) {
1251+
case tNUMBER:
1252+
case tRATIONAL:
1253+
outval(val,FALSE);
1254+
code_idx+=opargs(1);
1255+
break;
1256+
case tSYMBOL:
1257+
sym=findloc(str);
1258+
if (sym==NULL)
1259+
sym=findglb(str,sSTATEVAR);
1260+
if (sym==NULL || sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) {
1261+
error(17,str); /* undefined symbol */
1262+
} else {
1263+
if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) {
1264+
if ((sym->usage & uNATIVE)!=0) {
1265+
/* reserve a SYSREQ id if called for the first time */
1266+
if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0)
1267+
sym->addr=ntv_funcid++;
1268+
outval(sym->addr,FALSE);
1269+
} else {
1270+
/* normal function, write its name instead of the address
1271+
* so that the address will be resolved at assemble time
1272+
*/
1273+
stgwrite(".");
1274+
stgwrite(sym->name);
1275+
} /* if */
12681276
} else {
1269-
/* normal function, write its name instead of the address
1270-
* so that the address will be resolved at assemble time
1271-
*/
1272-
stgwrite(".");
1273-
stgwrite(sym->name);
1277+
outval(sym->addr,FALSE);
12741278
} /* if */
1275-
} else {
1276-
outval(sym->addr,FALSE);
1279+
/* mark symbol as "used", unknown whether for read or write */
1280+
markusage(sym,uREAD | uWRITTEN);
1281+
code_idx+=opargs(1);
12771282
} /* if */
1278-
/* mark symbol as "used", unknown whether for read or write */
1279-
markusage(sym,uREAD | uWRITTEN);
1280-
code_idx+=opargs(1);
1281-
} /* if */
1282-
break;
1283-
default: {
1284-
char s2[20];
1285-
extern char *sc_tokens[];/* forward declaration */
1286-
if (tok<256)
1287-
sprintf(s2,"%c",(char)tok);
1288-
else
1289-
strcpy(s2,sc_tokens[tok-tFIRST]);
1290-
error(1,sc_tokens[tSYMBOL-tFIRST],s2);
1291-
break;
1292-
} /* case */
1293-
} /* switch */
1283+
break;
1284+
default: {
1285+
char s2[20];
1286+
extern char *sc_tokens[];/* forward declaration */
1287+
if (tok<256)
1288+
sprintf(s2,"%c",(char)tok);
1289+
else
1290+
strcpy(s2,sc_tokens[tok-tFIRST]);
1291+
error(1,sc_tokens[tSYMBOL-tFIRST],s2);
1292+
break;
1293+
} /* case */
1294+
} /* switch */
1295+
} /* if */
1296+
stgwrite("\n");
1297+
check_empty(lptr);
12941298
} /* if */
1295-
stgwrite("\n");
1296-
check_empty(lptr);
12971299
break;
12981300
} /* case */
12991301
#endif

0 commit comments

Comments
 (0)