From 1a608c25a1db8441408d700131eccc254d9ac9b5 Mon Sep 17 00:00:00 2001 From: Sergei Marochkin Date: Fri, 11 Nov 2016 19:27:09 +0300 Subject: [PATCH] Add -R param to enable or disable recursion report --- source/compiler/sc.h | 1 + source/compiler/sc1.c | 6 +++++- source/compiler/scvars.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 8c625d5..e6842b8 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -817,6 +817,7 @@ SC_VDECL int pc_optimize; /* (peephole) optimization level */ SC_VDECL int pc_memflags; /* special flags for the stack/heap usage */ SC_VDECL int pc_naked; /* if true mark following function as naked */ SC_VDECL int pc_compat; /* running in compatibility mode? */ +SC_VDECL int pc_recursion; /* enable detailed recursion report? */ SC_VDECL constvalue sc_automaton_tab; /* automaton table */ SC_VDECL constvalue sc_state_tab; /* state table */ diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 63fb705..6b76991 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -1097,6 +1097,9 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam case 'p': strlcpy(pname,option_value(ptr),_MAX_PATH); /* set name of implicit include file */ break; + case 'R': + pc_recursion=toggle_option(ptr,pc_recursion); + break; #if !defined SC_LIGHT case 'r': strlcpy(rname,option_value(ptr),_MAX_PATH); /* set name of report file */ @@ -1417,6 +1420,7 @@ static void about(void) pc_printf(" 1 JIT-compatible optimizations only\n"); pc_printf(" 2 full optimizations\n"); pc_printf(" -p set name of \"prefix\" file\n"); + pc_printf(" -R[+/-] add detailed recursion report with call chains (default=%c)\n",pc_recursion ? '+' : '-'); #if !defined SC_LIGHT pc_printf(" -r[name] write cross reference report to console or to specified file\n"); #endif @@ -4606,7 +4610,7 @@ static long max_stacksize(symbol *root,int *recursion) assert(symstack[1]==NULL); recursion_detected=0; size=max_stacksize_recurse(symstack,sym,rsymstack,0L,&maxparams,&recursion_detected); - if (recursion_detected) { + if (recursion_detected && pc_recursion) { if (rsymstack[1]==NULL) { pc_printf("recursion detected: function %s directly calls itself\n", sym->name); } else { diff --git a/source/compiler/scvars.c b/source/compiler/scvars.c index 60cf03b..bb59691 100644 --- a/source/compiler/scvars.c +++ b/source/compiler/scvars.c @@ -92,6 +92,7 @@ SC_VDEFINE int pc_optimize=sOPTIMIZE_NOMACRO; /* (peephole) optimization level * SC_VDEFINE int pc_memflags=0; /* special flags for the stack/heap usage */ SC_VDEFINE int pc_naked=FALSE; /* if true mark following function as naked */ SC_VDEFINE int pc_compat=FALSE; /* running in compatibility mode? */ +SC_VDEFINE int pc_recursion=FALSE; /* enable detailed recursion report? */ SC_VDEFINE constvalue sc_automaton_tab = { NULL, "", 0, 0}; /* automaton table */ SC_VDEFINE constvalue sc_state_tab = { NULL, "", 0, 0}; /* state table */