Rewrite the assembly pipeline.
This patch uses SmxBuilder from spcomp2 to replace the old assemble() pipeline. Instead of generating into an old AMX structure, and then decoding that into SMX, we now directly generate into SMX. This greatly simplifies code generation and smx building.
This commit is contained in:
+11
-40
@@ -200,16 +200,11 @@ int pc_compile(int argc, char *argv[])
|
||||
char incfname[_MAX_PATH];
|
||||
char reportname[_MAX_PATH];
|
||||
char codepage[MAXCODEPAGE+1];
|
||||
FILE *binf;
|
||||
void *inpfmark;
|
||||
int lcl_packstr,lcl_needsemicolon,lcl_tabsize,lcl_require_newdecls;
|
||||
#if !defined SC_LIGHT
|
||||
int hdrsize=0;
|
||||
#endif
|
||||
char *ptr;
|
||||
|
||||
/* set global variables to their initial value */
|
||||
binf=NULL;
|
||||
initglobals();
|
||||
errorset(sRESET,0);
|
||||
errorset(sEXPRRELEASE,0);
|
||||
@@ -315,14 +310,6 @@ int pc_compile(int argc, char *argv[])
|
||||
outf=(FILE*)pc_openasm(outfname); /* first write to assembler file (may be temporary) */
|
||||
if (outf==NULL)
|
||||
error(161,outfname);
|
||||
/* immediately open the binary file, for other programs to check */
|
||||
if (sc_asmfile || sc_listing) {
|
||||
binf=NULL;
|
||||
} else {
|
||||
binf=(FILE*)pc_openbin(binfname);
|
||||
if (binf==NULL)
|
||||
error(161,binfname);
|
||||
} /* if */
|
||||
setconstants(); /* set predefined constants and tagnames */
|
||||
for (i=0; i<skipinput; i++) /* skip lines in the input file */
|
||||
if (pc_readsrc(inpf_org,pline,sLINEMAX)!=NULL)
|
||||
@@ -463,33 +450,27 @@ int pc_compile(int argc, char *argv[])
|
||||
cleanup:
|
||||
if (inpf!=NULL) /* main source file is not closed, do it now */
|
||||
pc_closesrc(inpf);
|
||||
/* write the binary file (the file is already open) */
|
||||
|
||||
// Write the binary file.
|
||||
if (!(sc_asmfile || sc_listing) && errnum==0 && jmpcode==0) {
|
||||
assert(binf!=NULL);
|
||||
pc_resetasm(outf); /* flush and loop back, for reading */
|
||||
#if !defined SC_LIGHT
|
||||
hdrsize=
|
||||
#endif
|
||||
assemble(binf,outf); /* assembler file is now input */
|
||||
} /* if */
|
||||
pc_resetasm(outf);
|
||||
assemble(binfname, outf);
|
||||
}
|
||||
|
||||
if (outf!=NULL) {
|
||||
pc_closeasm(outf,!(sc_asmfile || sc_listing));
|
||||
outf=NULL;
|
||||
} /* if */
|
||||
if (binf!=NULL) {
|
||||
pc_closebin(binf,errnum!=0);
|
||||
binf=NULL;
|
||||
} /* if */
|
||||
|
||||
#if !defined SC_LIGHT
|
||||
#if !defined SC_LIGHT
|
||||
if (errnum==0 && strlen(errfname)==0) {
|
||||
#if 0 //bug in compiler -- someone's script caused this function to infrecurs
|
||||
# if 0 //bug in compiler -- someone's script caused this function to infrecurs
|
||||
int recursion;
|
||||
long stacksize=max_stacksize(&glbtab,&recursion);
|
||||
#endif
|
||||
# endif
|
||||
int flag_exceed=0;
|
||||
if (pc_amxlimit>0) {
|
||||
long totalsize=hdrsize+code_idx;
|
||||
long totalsize=code_idx;
|
||||
if (pc_amxram==0)
|
||||
totalsize+=(glb_declared+pc_stksize)*sizeof(cell);
|
||||
if (totalsize>=pc_amxlimit)
|
||||
@@ -498,20 +479,10 @@ cleanup:
|
||||
if (pc_amxram>0 && (glb_declared+pc_stksize)*sizeof(cell)>=(unsigned long)pc_amxram)
|
||||
flag_exceed=1;
|
||||
if ((!norun && (sc_debug & sSYMBOLIC)!=0) || verbosity>=2 || flag_exceed) {
|
||||
pc_printf("Header size: %8ld bytes\n", (long)hdrsize);
|
||||
pc_printf("Code size: %8ld bytes\n", (long)code_idx);
|
||||
pc_printf("Data size: %8ld bytes\n", (long)glb_declared*sizeof(cell));
|
||||
pc_printf("Stack/heap size: %8ld bytes\n", (long)pc_stksize*sizeof(cell));
|
||||
#if 0
|
||||
pc_printf("estimated max. usage");
|
||||
if (recursion)
|
||||
pc_printf(": unknown, due to recursion\n");
|
||||
else if ((pc_memflags & suSLEEP_INSTR)!=0)
|
||||
pc_printf(": unknown, due to the \"sleep\" instruction\n");
|
||||
else
|
||||
pc_printf("=%ld cells (%ld bytes)\n",stacksize,stacksize*sizeof(cell));
|
||||
#endif
|
||||
pc_printf("Total requirements:%8ld bytes\n", (long)hdrsize+(long)code_idx+(long)glb_declared*sizeof(cell)+(long)pc_stksize*sizeof(cell));
|
||||
pc_printf("Total requirements:%8ld bytes\n", (long)code_idx+(long)glb_declared*sizeof(cell)+(long)pc_stksize*sizeof(cell));
|
||||
} /* if */
|
||||
if (flag_exceed)
|
||||
error(166,pc_amxlimit+pc_amxram); /* this causes a jump back to label "cleanup" */
|
||||
|
||||
Reference in New Issue
Block a user