From ae2699ca98cdd4b0325c2717942029c7d0b7d779 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 29 Sep 2014 15:12:47 +0200 Subject: [PATCH 1/4] Compiler: Disable estimated memory usage --- compiler/libpc300/sc1.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/libpc300/sc1.c b/compiler/libpc300/sc1.c index 5414392f..d66d6ed2 100755 --- a/compiler/libpc300/sc1.c +++ b/compiler/libpc300/sc1.c @@ -719,17 +719,17 @@ cleanup: #if !defined SC_LIGHT if (errnum==0 && strlen(errfname)==0) { int recursion; - long stacksize=max_stacksize(&glbtab,&recursion); + //long stacksize=max_stacksize(&glbtab,&recursion); int flag_exceed=0; if (sc_amxlimit > 0 && (long)(hdrsize+code_idx+glb_declared*sizeof(cell)+sc_stksize*sizeof(cell)) >= sc_amxlimit) flag_exceed=1; - if ((sc_debug & sSYMBOLIC)!=0 || verbosity>=2 || stacksize+32>=(long)sc_stksize || flag_exceed) { + if ((sc_debug & sSYMBOLIC)!=0 || verbosity>=2 /*|| stacksize+32>=(long)sc_stksize*/ || 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)sc_stksize*sizeof(cell)); - if (stacksize>0) - pc_printf("Estimated usage: %8ld bytes\n", stacksize*sizeof(cell)); + /*if (stacksize>0) + pc_printf("Estimated usage: %8ld bytes\n", stacksize*sizeof(cell));*/ pc_printf("Total requirements:%8ld bytes\n", (long)hdrsize+(long)code_idx+(long)glb_declared*sizeof(cell)+(long)sc_stksize*sizeof(cell)); } /* if */ if (flag_exceed) From e7c7313f77656d237dda5775f94a19560fc9cd57 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 29 Sep 2014 15:54:39 +0200 Subject: [PATCH 2/4] Compiler: Add a flag for warnings-as-errors --- compiler/libpc300/libpawnc.c | 12 ++++++++++-- compiler/libpc300/sc.h | 1 + compiler/libpc300/sc1.c | 4 ++++ compiler/libpc300/sc5.c | 14 +++++++++++--- compiler/libpc300/scvars.c | 1 + 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/compiler/libpc300/libpawnc.c b/compiler/libpc300/libpawnc.c index cd4d496d..c1d1f597 100755 --- a/compiler/libpc300/libpawnc.c +++ b/compiler/libpc300/libpawnc.c @@ -52,7 +52,7 @@ void extern __attribute__((visibility("default"))) EXCOMPILER(int argc, char **argv) # endif { - pc_compile(argc, argv); + pc_compile(argc, argv); } #endif /* PAWNC_DLL */ @@ -112,8 +112,16 @@ static char *prefix[3]={ "error", "fatal error", "warning" }; if (number!=0) { char *pre; + int idx; - pre=prefix[number/100]; + if (number < 100 || (number >= 200 && sc_warnings_are_errors)) + idx = 0; + else if (number < 200) + idx = 1; + else + idx = 2; + + pre=prefix[idx]; if (firstline>=0) pc_printf("%s(%d -- %d) : %s %03d: ",filename,firstline,lastline,pre,number); else diff --git a/compiler/libpc300/sc.h b/compiler/libpc300/sc.h index 9eb47438..2d8c8c24 100755 --- a/compiler/libpc300/sc.h +++ b/compiler/libpc300/sc.h @@ -798,6 +798,7 @@ SC_VDECL int rational_digits; /* number of fractional digits */ SC_VDECL int sc_allowproccall;/* allow/detect tagnames in lex() */ SC_VDECL short sc_is_utf8; /* is this source file in UTF-8 encoding */ SC_VDECL char *pc_deprecate; /* if non-NULL, mark next declaration as deprecated */ +SC_VDECL int sc_warnings_are_errors; SC_VDECL constvalue sc_automaton_tab; /* automaton table */ SC_VDECL constvalue sc_state_tab; /* state table */ diff --git a/compiler/libpc300/sc1.c b/compiler/libpc300/sc1.c index d66d6ed2..ffe84699 100755 --- a/compiler/libpc300/sc1.c +++ b/compiler/libpc300/sc1.c @@ -1052,6 +1052,9 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam strncpy(ename,option_value(ptr),_MAX_PATH); /* set name of error file */ ename[_MAX_PATH-1]='\0'; break; + case 'E': + sc_warnings_are_errors = 1; + break; #if defined __WIN32__ || defined _WIN32 || defined _Windows case 'H': hwndFinish=(HWND)atoi(option_value(ptr)); @@ -1399,6 +1402,7 @@ static void about(void) pc_printf(" -t TAB indent size (in character positions, default=%d)\n",sc_tabsize); pc_printf(" -v verbosity level; 0=quiet, 1=normal, 2=verbose (default=%d)\n",verbosity); pc_printf(" -w disable a specific warning by its number\n"); + pc_printf(" -E treat warnings as errors\n"); pc_printf(" -X abstract machine size limit in bytes\n"); pc_printf(" -\\ use '\\' for escape characters\n"); pc_printf(" -^ use '^' for escape characters\n"); diff --git a/compiler/libpc300/sc5.c b/compiler/libpc300/sc5.c index e5f74c90..b6234ee5 100755 --- a/compiler/libpc300/sc5.c +++ b/compiler/libpc300/sc5.c @@ -75,6 +75,9 @@ static short lastfile; char *msg,*pre,*filename; va_list argptr; char string[128]; + int is_warning; + + is_warning = (number >= 200 && !sc_warnings_are_errors); /* errflag is reset on each semicolon. * In a two-pass compiler, an error should not be reported twice. Therefore @@ -103,8 +106,13 @@ static short lastfile; errnum++; /* a fatal error also counts as an error */ } else { msg=warnmsg[number-200]; - pre=prefix[2]; - warnnum++; + if (sc_warnings_are_errors) { + pre=prefix[0]; + errnum++; + } else { + pre=prefix[2]; + warnnum++; + } } /* if */ strexpand(string,(unsigned char *)msg,sizeof string,SCPACK_TABLE); @@ -164,7 +172,7 @@ static short lastfile; errorcount=0; lastline=fline; lastfile=fcurrent; - if (number<200) + if (!is_warning) errorcount++; if (errorcount>=3) error(107); /* too many error/warning messages on one line */ diff --git a/compiler/libpc300/scvars.c b/compiler/libpc300/scvars.c index 1c297060..8afba17f 100755 --- a/compiler/libpc300/scvars.c +++ b/compiler/libpc300/scvars.c @@ -87,6 +87,7 @@ SC_VDEFINE int sc_allowproccall=0; /* allow/detect tagnames in lex() */ SC_VDEFINE short sc_is_utf8=FALSE; /* is this source file in UTF-8 encoding */ SC_VDEFINE char *pc_deprecate = NULL;/* if non-null, mark next declaration as deprecated */ SC_VDEFINE int sc_showincludes=0; /* show include files */ +SC_VDEFINE int sc_warnings_are_errors=0; SC_VDEFINE constvalue sc_automaton_tab = { NULL, "", 0, 0}; /* automaton table */ SC_VDEFINE constvalue sc_state_tab = { NULL, "", 0, 0}; /* state table */ From 199b41af0a64707c8d79aa48a796ad5daf84c8c9 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 29 Sep 2014 15:55:16 +0200 Subject: [PATCH 3/4] Compiler: Treat pawn warnings as errors when building --- plugins/AMBuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/AMBuilder b/plugins/AMBuilder index f995c3bd..6717c134 100644 --- a/plugins/AMBuilder +++ b/plugins/AMBuilder @@ -62,6 +62,7 @@ amxxpc_argv = [ '-i' + os.path.relpath(os.path.join(builder.sourcePath, 'plugins', 'include'), os.path.join(builder.buildPath, builder.buildFolder)), '-h', + '-E', ] def build_plugin(script_path, amxx_file, extra_argv = []): From 3b3e78d65b3b363a80540d97fead4a1df955ed86 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 29 Sep 2014 20:36:14 +0200 Subject: [PATCH 4/4] Compiler: Remove commented code in previous commit --- compiler/libpc300/sc1.c | 127 +--------------------------------------- 1 file changed, 1 insertion(+), 126 deletions(-) diff --git a/compiler/libpc300/sc1.c b/compiler/libpc300/sc1.c index ffe84699..7d5967f0 100755 --- a/compiler/libpc300/sc1.c +++ b/compiler/libpc300/sc1.c @@ -719,17 +719,14 @@ cleanup: #if !defined SC_LIGHT if (errnum==0 && strlen(errfname)==0) { int recursion; - //long stacksize=max_stacksize(&glbtab,&recursion); int flag_exceed=0; if (sc_amxlimit > 0 && (long)(hdrsize+code_idx+glb_declared*sizeof(cell)+sc_stksize*sizeof(cell)) >= sc_amxlimit) flag_exceed=1; - if ((sc_debug & sSYMBOLIC)!=0 || verbosity>=2 /*|| stacksize+32>=(long)sc_stksize*/ || flag_exceed) { + if ((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)sc_stksize*sizeof(cell)); - /*if (stacksize>0) - pc_printf("Estimated usage: %8ld bytes\n", stacksize*sizeof(cell));*/ pc_printf("Total requirements:%8ld bytes\n", (long)hdrsize+(long)code_idx+(long)glb_declared*sizeof(cell)+(long)sc_stksize*sizeof(cell)); } /* if */ if (flag_exceed) @@ -4251,128 +4248,6 @@ static void reduce_referrers(symbol *root) } while (restart>0); } -#if !defined SC_LIGHT -static long max_stacksize_recurse(symbol **sourcesym,symbol *sym,long basesize,int *pubfuncparams,int *recursion) -{ - long size,maxsize; - int i,stkpos; - - assert(sourcesym!=NULL); - assert(sym!=NULL); - assert(sym->ident==iFUNCTN); - assert((sym->usage & uNATIVE)==0); - assert(recursion!=NULL); - - maxsize=sym->x.stacksize; - for (i=0; inumrefers; i++) { - if (sym->refer[i]!=NULL) { - assert(sym->refer[i]->ident==iFUNCTN); - assert((sym->refer[i]->usage & uNATIVE)==0); /* a native function cannot refer to a user-function */ - for (stkpos=0; sourcesym[stkpos]!=NULL; stkpos++) { - if (sym->refer[i]==sourcesym[stkpos]) { /* recursion detection */ - if ((sc_debug & sSYMBOLIC)!=0 || verbosity>=2) { - char symname[2*sNAMEMAX+16];/* allow space for user defined operators */ - funcdisplayname(symname,sym->name); - errorset(sSETFILE,sym->fnumber); - errorset(sSETLINE,sym->lnumber); - error(234,symname); /* recursive function */ - } /* if */ - *recursion=1; - goto break_recursion; /* recursion was detected, quit loop */ - } /* if */ - } /* for */ - /* add this symbol to the stack */ - sourcesym[stkpos]=sym; - sourcesym[stkpos+1]=NULL; - /* check size of callee */ - size=max_stacksize_recurse(sourcesym,sym->refer[i],sym->x.stacksize,pubfuncparams,recursion); - if (maxsizeusage & uPUBLIC)!=0) { - /* Find out how many parameters a public function has, then see if this - * is bigger than some maximum - */ - arginfo *arg=sym->dim.arglist; - int count=0; - assert(arg!=0); - while (arg->ident!=0) { - count++; - arg++; - } /* while */ - assert(pubfuncparams!=0); - if (count>*pubfuncparams) - *pubfuncparams=count; - } /* if */ - - errorset(sEXPRRELEASE,0); /* clear error data */ - errorset(sRESET,0); - - return maxsize+basesize; -} - -static long max_stacksize(symbol *root,int *recursion) -{ - /* Loop over all non-native functions. For each function, loop - * over all of its referrers, accumulating the stack requirements. - * Detect (indirect) recursion with a "mark-and-sweep" algorithm. - * I (mis-)use the "compound" field of the symbol structure for - * the marker, as this field is unused for functions. - * - * Note that the stack is shared with the heap. A host application - * may "eat" cells from the heap as well, through amx_Allot(). The - * stack requirements are thus only an estimate. - */ - long size,maxsize; - int maxparams,numfunctions; - symbol *sym; - symbol **symstack; - - assert(root!=NULL); - assert(recursion!=NULL); - /* count number of functions (for allocating the stack for recursion detection) */ - numfunctions=0; - for (sym=root->next; sym!=NULL; sym=sym->next) { - if (sym->ident==iFUNCTN) { - assert(sym->compound==0); - if ((sym->usage & uNATIVE)==0) - numfunctions++; - } /* if */ - } /* if */ - /* allocate function symbol stack */ - symstack=(symbol **)malloc((numfunctions+1)*sizeof(symbol*)); - if (symstack==NULL) - error(103); /* insufficient memory (fatal error) */ - memset(symstack,0,(numfunctions+1)*sizeof(symbol*)); - - maxsize=0; - maxparams=0; - *recursion=0; /* assume no recursion */ - for (sym=root->next; sym!=NULL; sym=sym->next) { - /* drop out if this is not a user-implemented function */ - if (sym->ident!=iFUNCTN || (sym->usage & uNATIVE)!=0) - continue; - /* accumulate stack size for this symbol */ - symstack[0]=sym; - assert(symstack[1]==NULL); - size=max_stacksize_recurse(symstack,sym,0L,&maxparams,recursion); - assert(size>=0); - if (maxsize