From afc5c481f97b85b803b9b973d52684deceb715d0 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 30 Jul 2013 14:26:50 -0400 Subject: Start new branch that adds comments to profiling. --- profile.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'profile.c') diff --git a/profile.c b/profile.c index eae24b1c..5c7555e6 100644 --- a/profile.c +++ b/profile.c @@ -873,6 +873,28 @@ cleanup: indent(pc->exec_count); break; + case Op_comment: + { + char *text; + size_t count; + bool after_newline = false; + + count = pc->memory->stlen; + text = pc->memory->stptr; + + indent(SPACEOVER); + for (; count > 0; count--, text++) { + if (after_newline) { + indent(SPACEOVER); + after_newline = false; + } + putc(*text, prof_fp); + if (*text == '\n') + after_newline = true; + } + } + break; + default: cant_happen(); } -- cgit v1.2.3 From 9a7e5828f29d3f5daba5dc5ef1f6b9cd87f596b8 Mon Sep 17 00:00:00 2001 From: Stephen Davies Date: Sun, 24 Aug 2014 10:24:05 +0930 Subject: Progress in collecting comments and with comments within a block. No joy with comments before BEGIN or END and, before { or after }. Changed my email --- profile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 5c7555e6..51ef9715 100644 --- a/profile.c +++ b/profile.c @@ -882,7 +882,7 @@ cleanup: count = pc->memory->stlen; text = pc->memory->stptr; - indent(SPACEOVER); + indent(SPACEOVER); /* is this correct? Where should comments go? */ for (; count > 0; count--, text++) { if (after_newline) { indent(SPACEOVER); -- cgit v1.2.3 From ae131ae925aa5ba54fb7f8ae105e5cbbf3655f06 Mon Sep 17 00:00:00 2001 From: Stephen Davies Date: Wed, 3 Sep 2014 12:23:22 +0930 Subject: ll except functions looking OK --- profile.c | 72 ++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 24 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 51ef9715..4db29c9a 100644 --- a/profile.c +++ b/profile.c @@ -36,7 +36,8 @@ static bool is_scalar(int type); static int prec_level(int type); static void pp_push(int type, char *s, int flag); static NODE *pp_pop(void); -static void pp_free(NODE *n); +static void pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header); +static void print_comment(INSTRUCTION *pc, long in); const char *redir2str(int redirtype); #define pp_str vname @@ -174,9 +175,12 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) char *str; NODE *t2; INSTRUCTION *ip; + INSTRUCTION *ic; + INSTRUCTION *i2; NODE *m; char *tmp; int rule; + long lind; static int rule_count[MAXRULE]; for (pc = startp; pc != endp; pc = pc->nexti) { @@ -189,16 +193,30 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) rule = pc->in_rule; if (rule != Rule) { + ip = (pc + 1)->firsti; + if (ip->opcode == Op_comment){ + /* print pre-begin/end comments */ + print_comment(ip, 0); + ip = pc->nexti->nexti; + } if (! rule_count[rule]++) fprintf(prof_fp, _("\t# %s block(s)\n\n"), ruletab[rule]); fprintf(prof_fp, "\t%s {\n", ruletab[rule]); - ip = (pc + 1)->firsti; } else { if (! rule_count[rule]++) fprintf(prof_fp, _("\t# Rule(s)\n\n")); - ip = pc->nexti; - indent(ip->exec_count); + ic = ip = pc->nexti; + i2 = (pc + 1)->firsti; + lind = ip->exec_count; + /*print pre-block comments */ + if(ip->opcode == Op_exec_count && ip->nexti->opcode == Op_comment)ip = ip->nexti; + if(ip->opcode == Op_comment){ + print_comment(ip, lind); + if (ip->nexti->nexti == (pc + 1)->firsti) + ip = ip->nexti->nexti; + } if (ip != (pc + 1)->firsti) { /* non-empty pattern */ + indent(lind); pprint(ip->nexti, (pc + 1)->firsti, false); t1 = pp_pop(); fprintf(prof_fp, "%s {", t1->pp_str); @@ -210,7 +228,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) fprintf(prof_fp, "\n"); } else { - fprintf(prof_fp, "{\n"); + fprintf(prof_fp, "\t{\n"); ip = (pc + 1)->firsti; } ip = ip->nexti; @@ -874,27 +892,11 @@ cleanup: break; case Op_comment: - { - char *text; - size_t count; - bool after_newline = false; - - count = pc->memory->stlen; - text = pc->memory->stptr; - - indent(SPACEOVER); /* is this correct? Where should comments go? */ - for (; count > 0; count--, text++) { - if (after_newline) { - indent(SPACEOVER); - after_newline = false; - } - putc(*text, prof_fp); - if (*text == '\n') - after_newline = true; - } - } + print_comment(pc, 0); break; + case Op_list: + break; default: cant_happen(); } @@ -977,6 +979,28 @@ print_lib_list(FILE *prof_fp) fprintf(prof_fp, "\n"); } +/* print comment text with proper indentation */ +static void +print_comment(INSTRUCTION* pc, long in){ + char *text; + size_t count; + bool after_newline = false; + + count = pc->memory->stlen; + text = pc->memory->stptr; + + indent(in); /* is this correct? Where should comments go? */ + for (; count > 0; count--, text++) { + if (after_newline) { + indent(in); + after_newline = false; + } + putc(*text, prof_fp); + if (*text == '\n') + after_newline = true; + } +} + /* dump_prog --- dump the program */ /* -- cgit v1.2.3 From cb92ab7aa657c57446cc9e0087f1364adaac8fee Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 4 Sep 2014 08:52:50 +0300 Subject: Improve printing empty for loop header in profiler. --- profile.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index eae24b1c..d07bea4a 100644 --- a/profile.c +++ b/profile.c @@ -731,20 +731,28 @@ cleanup: ip = pc + 1; indent(ip->forloop_body->exec_count); fprintf(prof_fp, "%s (", op2str(pc->opcode)); - pprint(pc->nexti, ip->forloop_cond, true); - fprintf(prof_fp, "; "); - if (ip->forloop_cond->opcode == Op_no_op && - ip->forloop_cond->nexti == ip->forloop_body) + /* If empty for looop header, print it a little more nicely. */ + if ( pc->nexti->opcode == Op_no_op + && ip->forloop_cond == pc->nexti + && pc->target_continue->opcode == Op_jmp) { + fprintf(prof_fp, ";;"); + } else { + pprint(pc->nexti, ip->forloop_cond, true); fprintf(prof_fp, "; "); - else { - pprint(ip->forloop_cond, ip->forloop_body, true); - t1 = pp_pop(); - fprintf(prof_fp, "%s; ", t1->pp_str); - pp_free(t1); - } - pprint(pc->target_continue, pc->target_break, true); + if (ip->forloop_cond->opcode == Op_no_op && + ip->forloop_cond->nexti == ip->forloop_body) + fprintf(prof_fp, "; "); + else { + pprint(ip->forloop_cond, ip->forloop_body, true); + t1 = pp_pop(); + fprintf(prof_fp, "%s; ", t1->pp_str); + pp_free(t1); + } + + pprint(pc->target_continue, pc->target_break, true); + } fprintf(prof_fp, ") {\n"); indent_in(); pprint(ip->forloop_body->nexti, pc->target_continue, false); -- cgit v1.2.3 From 4282c7757598300ee050374f3649ffee070ed680 Mon Sep 17 00:00:00 2001 From: Stephen Davies Date: Sun, 7 Sep 2014 17:24:24 +0930 Subject: function comments 1 --- profile.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 4db29c9a..8eb31b24 100644 --- a/profile.c +++ b/profile.c @@ -101,10 +101,11 @@ indent(long count) { int i; - if (count == 0) - fprintf(prof_fp, "\t"); - else - fprintf(prof_fp, "%6ld ", count); + if ( do_profile) + if (count == 0) + fprintf(prof_fp, "\t"); + else + fprintf(prof_fp, "%6ld ", count); assert(indent_level >= 0); for (i = 0; i < indent_level; i++) @@ -197,13 +198,13 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) if (ip->opcode == Op_comment){ /* print pre-begin/end comments */ print_comment(ip, 0); - ip = pc->nexti->nexti; + ip = ip->nexti->nexti; } - if (! rule_count[rule]++) + if (do_profile && ! rule_count[rule]++) fprintf(prof_fp, _("\t# %s block(s)\n\n"), ruletab[rule]); fprintf(prof_fp, "\t%s {\n", ruletab[rule]); } else { - if (! rule_count[rule]++) + if (do_profile && ! rule_count[rule]++) fprintf(prof_fp, _("\t# Rule(s)\n\n")); ic = ip = pc->nexti; i2 = (pc + 1)->firsti; @@ -1015,7 +1016,8 @@ dump_prog(INSTRUCTION *code) (void) time(& now); /* \n on purpose, with \n in ctime() output */ - fprintf(prof_fp, _("\t# gawk profile, created %s\n"), ctime(& now)); + if (do_profile) + fprintf(prof_fp, _("\t# gawk profile, created %s\n"), ctime(& now)); print_lib_list(prof_fp); pprint(code, NULL, false); } @@ -1515,14 +1517,23 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED) static bool first = true; NODE *func; int pcount; + INSTRUCTION *fp; if (first) { first = false; - fprintf(prof_fp, _("\n\t# Functions, listed alphabetically\n")); + if (do_profile) + fprintf(prof_fp, _("\n\t# Functions, listed alphabetically\n")); } + fp = pc->nexti->nexti; func = pc->func_body; fprintf(prof_fp, "\n"); +/* print any function comment */ + if (fp->opcode == Op_comment && fp->source_line == 0){ + print_comment(fp, 0); + fp = fp->nexti; + } + fprintf(prof_fp, "\t"); indent(pc->nexti->exec_count); fprintf(prof_fp, "%s %s(", op2str(Op_K_function), func->vname); pcount = func->param_cnt; @@ -1534,7 +1545,7 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED) } fprintf(prof_fp, ")\n\t{\n"); indent_in(); - pprint(pc->nexti->nexti, NULL, false); /* function body */ + pprint(fp, NULL, false); /* function body */ indent_out(); fprintf(prof_fp, "\t}\n"); return 0; -- cgit v1.2.3 From a1df6304be3c217877919097d2e4b3b16de6cd02 Mon Sep 17 00:00:00 2001 From: Stephen Davies Date: Mon, 8 Sep 2014 13:46:17 +0930 Subject: profile.c fixes --- profile.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 8eb31b24..f1ced7e1 100644 --- a/profile.c +++ b/profile.c @@ -176,8 +176,6 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) char *str; NODE *t2; INSTRUCTION *ip; - INSTRUCTION *ic; - INSTRUCTION *i2; NODE *m; char *tmp; int rule; @@ -198,7 +196,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) if (ip->opcode == Op_comment){ /* print pre-begin/end comments */ print_comment(ip, 0); - ip = ip->nexti->nexti; + ip = ip->nexti; } if (do_profile && ! rule_count[rule]++) fprintf(prof_fp, _("\t# %s block(s)\n\n"), ruletab[rule]); @@ -206,8 +204,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) } else { if (do_profile && ! rule_count[rule]++) fprintf(prof_fp, _("\t# Rule(s)\n\n")); - ic = ip = pc->nexti; - i2 = (pc + 1)->firsti; + ip = pc->nexti; lind = ip->exec_count; /*print pre-block comments */ if(ip->opcode == Op_exec_count && ip->nexti->opcode == Op_comment)ip = ip->nexti; @@ -1533,7 +1530,8 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED) print_comment(fp, 0); fp = fp->nexti; } - fprintf(prof_fp, "\t"); + if (!do_profile) + fprintf(prof_fp, "\t"); indent(pc->nexti->exec_count); fprintf(prof_fp, "%s %s(", op2str(Op_K_function), func->vname); pcount = func->param_cnt; -- cgit v1.2.3 From ae1c0daca3998e5be8369e632e093f9f6dce1a70 Mon Sep 17 00:00:00 2001 From: Stephen Davies Date: Mon, 8 Sep 2014 15:13:21 +0930 Subject: fix indents --- profile.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index f1ced7e1..e23a17ac 100644 --- a/profile.c +++ b/profile.c @@ -200,7 +200,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) } if (do_profile && ! rule_count[rule]++) fprintf(prof_fp, _("\t# %s block(s)\n\n"), ruletab[rule]); - fprintf(prof_fp, "\t%s {\n", ruletab[rule]); + fprintf(prof_fp, "%s {\n", ruletab[rule]); } else { if (do_profile && ! rule_count[rule]++) fprintf(prof_fp, _("\t# Rule(s)\n\n")); @@ -226,7 +226,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) fprintf(prof_fp, "\n"); } else { - fprintf(prof_fp, "\t{\n"); + fprintf(prof_fp, "{\n"); ip = (pc + 1)->firsti; } ip = ip->nexti; @@ -234,7 +234,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) indent_in(); pprint(ip, (pc + 1)->lasti, false); indent_out(); - fprintf(prof_fp, "\t}\n\n"); + fprintf(prof_fp, "}\n\n"); pc = (pc + 1)->lasti; break; @@ -1530,7 +1530,7 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED) print_comment(fp, 0); fp = fp->nexti; } - if (!do_profile) + if (do_profile) fprintf(prof_fp, "\t"); indent(pc->nexti->exec_count); fprintf(prof_fp, "%s %s(", op2str(Op_K_function), func->vname); @@ -1541,11 +1541,11 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED) if (j < pcount - 1) fprintf(prof_fp, ", "); } - fprintf(prof_fp, ")\n\t{\n"); + fprintf(prof_fp, ")\n{\n"); indent_in(); pprint(fp, NULL, false); /* function body */ indent_out(); - fprintf(prof_fp, "\t}\n"); + fprintf(prof_fp, "}\n"); return 0; } -- cgit v1.2.3 From d7c8dfd41bd5671ddfa6c81b2ef1779cab06e56b Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 10 Sep 2014 08:14:35 +0300 Subject: Fix some minor indentation nits in profiling. --- profile.c | 76 +++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 31 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index e23a17ac..e2211e1b 100644 --- a/profile.c +++ b/profile.c @@ -101,7 +101,7 @@ indent(long count) { int i; - if ( do_profile) + if (do_profile) if (count == 0) fprintf(prof_fp, "\t"); else @@ -193,22 +193,28 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) if (rule != Rule) { ip = (pc + 1)->firsti; - if (ip->opcode == Op_comment){ - /* print pre-begin/end comments */ + + /* print pre-begin/end comments */ + if (ip->opcode == Op_comment) { print_comment(ip, 0); ip = ip->nexti; } - if (do_profile && ! rule_count[rule]++) - fprintf(prof_fp, _("\t# %s block(s)\n\n"), ruletab[rule]); + + if (do_profile) { + if (! rule_count[rule]++) + fprintf(prof_fp, _("\t# %s block(s)\n\n"), ruletab[rule]); + indent(0); + } fprintf(prof_fp, "%s {\n", ruletab[rule]); } else { if (do_profile && ! rule_count[rule]++) fprintf(prof_fp, _("\t# Rule(s)\n\n")); ip = pc->nexti; lind = ip->exec_count; - /*print pre-block comments */ - if(ip->opcode == Op_exec_count && ip->nexti->opcode == Op_comment)ip = ip->nexti; - if(ip->opcode == Op_comment){ + /* print pre-block comments */ + if (ip->opcode == Op_exec_count && ip->nexti->opcode == Op_comment) + ip = ip->nexti; + if (ip->opcode == Op_comment) { print_comment(ip, lind); if (ip->nexti->nexti == (pc + 1)->firsti) ip = ip->nexti->nexti; @@ -234,6 +240,8 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) indent_in(); pprint(ip, (pc + 1)->lasti, false); indent_out(); + if (do_profile) + indent(0); fprintf(prof_fp, "}\n\n"); pc = (pc + 1)->lasti; break; @@ -979,24 +987,25 @@ print_lib_list(FILE *prof_fp) /* print comment text with proper indentation */ static void -print_comment(INSTRUCTION* pc, long in){ - char *text; - size_t count; - bool after_newline = false; - - count = pc->memory->stlen; - text = pc->memory->stptr; - - indent(in); /* is this correct? Where should comments go? */ - for (; count > 0; count--, text++) { - if (after_newline) { - indent(in); - after_newline = false; - } - putc(*text, prof_fp); - if (*text == '\n') - after_newline = true; - } +print_comment(INSTRUCTION* pc, long in) +{ + char *text; + size_t count; + bool after_newline = false; + + count = pc->memory->stlen; + text = pc->memory->stptr; + + indent(in); /* is this correct? Where should comments go? */ + for (; count > 0; count--, text++) { + if (after_newline) { + indent(in); + after_newline = false; + } + putc(*text, prof_fp); + if (*text == '\n') + after_newline = true; + } } /* dump_prog --- dump the program */ @@ -1525,13 +1534,13 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED) fp = pc->nexti->nexti; func = pc->func_body; fprintf(prof_fp, "\n"); -/* print any function comment */ - if (fp->opcode == Op_comment && fp->source_line == 0){ + + /* print any function comment */ + if (fp->opcode == Op_comment && fp->source_line == 0) { print_comment(fp, 0); fp = fp->nexti; } - if (do_profile) - fprintf(prof_fp, "\t"); + indent(pc->nexti->exec_count); fprintf(prof_fp, "%s %s(", op2str(Op_K_function), func->vname); pcount = func->param_cnt; @@ -1541,10 +1550,15 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED) if (j < pcount - 1) fprintf(prof_fp, ", "); } - fprintf(prof_fp, ")\n{\n"); + fprintf(prof_fp, ")\n"); + if (do_profile) + indent(0); + fprintf(prof_fp, "{\n"); indent_in(); pprint(fp, NULL, false); /* function body */ indent_out(); + if (do_profile) + indent(0); fprintf(prof_fp, "}\n"); return 0; } -- cgit v1.2.3 From 66479f2ca1fbbf3b96cd2e1b15c0119b209df54a Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 27 Sep 2014 22:25:57 +0300 Subject: Minor improvement in profiling output. --- profile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index d07bea4a..b0fbbedb 100644 --- a/profile.c +++ b/profile.c @@ -190,7 +190,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, bool in_for_header) if (rule != Rule) { if (! rule_count[rule]++) - fprintf(prof_fp, _("\t# %s block(s)\n\n"), ruletab[rule]); + fprintf(prof_fp, _("\t# %s rules(s)\n\n"), ruletab[rule]); fprintf(prof_fp, "\t%s {\n", ruletab[rule]); ip = (pc + 1)->firsti; } else { -- cgit v1.2.3 From ed633f19bdbb66ac12aaf66cf46b458558eaedbd Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 1 Oct 2014 22:06:31 +0300 Subject: Some cleanups and doc additions. --- profile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index ddb9c357..0a137e29 100644 --- a/profile.c +++ b/profile.c @@ -101,11 +101,12 @@ indent(long count) { int i; - if (do_profile) + if (do_profile) { if (count == 0) fprintf(prof_fp, "\t"); else fprintf(prof_fp, "%6ld ", count); + } assert(indent_level >= 0); for (i = 0; i < indent_level; i++) -- cgit v1.2.3 From 4959339c8a962b54bf33fd9e3d9f46b3f1c3c29e Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 2 Oct 2014 20:06:36 +0300 Subject: Code review and minor whitespace cleanups. --- profile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 0a137e29..da41a560 100644 --- a/profile.c +++ b/profile.c @@ -912,6 +912,7 @@ cleanup: case Op_list: break; + default: cant_happen(); } @@ -994,7 +995,8 @@ print_lib_list(FILE *prof_fp) fprintf(prof_fp, "\n"); } -/* print comment text with proper indentation */ +/* print_comment --- print comment text with proper indentation */ + static void print_comment(INSTRUCTION* pc, long in) { -- cgit v1.2.3 From 42bcb6246432790af31958d5445cd035fe9966a5 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 4 Oct 2014 23:29:29 +0300 Subject: Fix --gen-pot with long strings. --- profile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index b0fbbedb..84e7f9da 100644 --- a/profile.c +++ b/profile.c @@ -909,11 +909,11 @@ pp_string_fp(Func_print print_func, FILE *fp, const char *in_str, slen = strlen(str); for (count = 0; slen > 0; slen--, str++) { + print_func(fp, "%c", *str); if (++count >= BREAKPOINT && breaklines) { print_func(fp, "%c\n%c", delim, delim); count = 0; - } else - print_func(fp, "%c", *str); + } } efree(s); } -- cgit v1.2.3