From bfca1619d658bc30835f4fb29c53ddfe206f4b17 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 28 Feb 2016 05:40:41 +0200 Subject: Fix copy-paste error in profiler's else handling. --- profile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 3d0b1cbc..d002e237 100644 --- a/profile.c +++ b/profile.c @@ -885,7 +885,7 @@ cleanup: && pc->branch_end == pc->nexti->nexti->branch_else->lasti) { pprint(pc->nexti, pc->branch_end, IN_ELSE_IF); } else { - fprintf(prof_fp, "{\n", op2str(pc->opcode)); + fprintf(prof_fp, "{\n"); indent_in(); pprint(pc->nexti, pc->branch_end, NO_PPRINT_FLAGS); indent_out(); -- cgit v1.2.3 From 21b584ce481970c9022c08148a6adbc0e489c432 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 29 Feb 2016 21:34:57 +0200 Subject: Fix profiling bug - printf with no arguments. --- profile.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index d002e237..178deb7e 100644 --- a/profile.c +++ b/profile.c @@ -1423,34 +1423,40 @@ pp_list(int nargs, const char *paren, const char *delim) erealloc(pp_args, NODE **, (nargs + 2) * sizeof(NODE *), "pp_list"); } - delimlen = strlen(delim); - len = -delimlen; - for (i = 1; i <= nargs; i++) { - r = pp_args[i] = pp_pop(); - len += r->pp_len + delimlen; - } - if (paren != NULL) { - assert(strlen(paren) == 2); - len += 2; + if (nargs == 0) + len = 2; + else { + delimlen = strlen(delim); + len = -delimlen; + for (i = 1; i <= nargs; i++) { + r = pp_args[i] = pp_pop(); + len += r->pp_len + delimlen; + } + if (paren != NULL) { + assert(strlen(paren) == 2); + len += 2; + } } emalloc(str, char *, len + 1, "pp_list"); s = str; if (paren != NULL) *s++ = paren[0]; - r = pp_args[nargs]; - memcpy(s, r->pp_str, r->pp_len); - s += r->pp_len; - pp_free(r); - for (i = nargs - 1; i > 0; i--) { - if (delimlen > 0) { - memcpy(s, delim, delimlen); - s += delimlen; - } - r = pp_args[i]; + if (nargs > 0) { + r = pp_args[nargs]; memcpy(s, r->pp_str, r->pp_len); s += r->pp_len; pp_free(r); + for (i = nargs - 1; i > 0; i--) { + if (delimlen > 0) { + memcpy(s, delim, delimlen); + s += delimlen; + } + r = pp_args[i]; + memcpy(s, r->pp_str, r->pp_len); + s += r->pp_len; + pp_free(r); + } } if (paren != NULL) *s++ = paren[1]; -- cgit v1.2.3 From b8d9a73257e1984eae80e61f0b751ddc4e9eab25 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 2 Mar 2016 20:35:59 +0200 Subject: Additional prints in instruction dump. --- profile.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 9e4a9b02..55bf42e0 100644 --- a/profile.c +++ b/profile.c @@ -192,6 +192,22 @@ pp_free(NODE *n) freenode(n); } +/* get_next_real_inst --- skip Op_comment */ + +static INSTRUCTION * +get_next_real_inst(INSTRUCTION *pc) +{ + if (pc == NULL) + return pc; + + for (; pc != NULL && pc->opcode == Op_comment; pc = pc->nexti) { +fprintf(stderr, "%s: opcode is %s\n", __func__, opcode2str(pc->opcode)); + continue; + } + + return pc; +} + /* pprint --- pretty print a program segment */ static void @@ -207,6 +223,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags) char *tmp; int rule; static int rule_count[MAXRULE]; + INSTRUCTION *next_real; for (pc = startp; pc != endp; pc = pc->nexti) { if (pc->source_line > 0) @@ -742,8 +759,16 @@ cleanup: t1 = pp_pop(); if (is_binary(t1->type)) pp_parenthesize(t1); - if (pc->source_line > 0) /* don't print implicit 'return' at end of function */ - fprintf(prof_fp, "%s %s\n", op2str(pc->opcode), t1->pp_str); + if (pc->source_line > 0) { /* don't print implicit 'return' at end of function */ + if (pc->nexti->opcode != Op_comment || pc->nexti->memory->comment_type != EOL_COMMENT) + fprintf(prof_fp, "%s %s\n", op2str(pc->opcode), t1->pp_str); + else { + fprintf(prof_fp, "%s %s", op2str(pc->opcode), t1->pp_str); + // print the comment + print_comment(pc->nexti, 0); + pc = pc->nexti; /* skip it */ + } + } pp_free(t1); break; @@ -929,8 +954,9 @@ cleanup: */ fprintf(prof_fp, "} %s ", op2str(pc->opcode)); - if (pc->nexti->nexti->opcode == Op_K_if - && pc->branch_end == pc->nexti->nexti->branch_else->lasti) { + next_real = get_next_real_inst(pc->nexti); + if (next_real->nexti->opcode == Op_K_if + && pc->branch_end == next_real->nexti->branch_else->nexti) { pprint(pc->nexti, pc->branch_end, IN_ELSE_IF); } else { fprintf(prof_fp, "{\n"); -- cgit v1.2.3 From 2693fc3368628e377bb9c29ba1ba1f6ab091fac5 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 2 Mar 2016 20:52:49 +0200 Subject: Revert b8d9a73257e1984eae80e61f0b751ddc4e9eab25. --- profile.c | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 55bf42e0..9e4a9b02 100644 --- a/profile.c +++ b/profile.c @@ -192,22 +192,6 @@ pp_free(NODE *n) freenode(n); } -/* get_next_real_inst --- skip Op_comment */ - -static INSTRUCTION * -get_next_real_inst(INSTRUCTION *pc) -{ - if (pc == NULL) - return pc; - - for (; pc != NULL && pc->opcode == Op_comment; pc = pc->nexti) { -fprintf(stderr, "%s: opcode is %s\n", __func__, opcode2str(pc->opcode)); - continue; - } - - return pc; -} - /* pprint --- pretty print a program segment */ static void @@ -223,7 +207,6 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags) char *tmp; int rule; static int rule_count[MAXRULE]; - INSTRUCTION *next_real; for (pc = startp; pc != endp; pc = pc->nexti) { if (pc->source_line > 0) @@ -759,16 +742,8 @@ cleanup: t1 = pp_pop(); if (is_binary(t1->type)) pp_parenthesize(t1); - if (pc->source_line > 0) { /* don't print implicit 'return' at end of function */ - if (pc->nexti->opcode != Op_comment || pc->nexti->memory->comment_type != EOL_COMMENT) - fprintf(prof_fp, "%s %s\n", op2str(pc->opcode), t1->pp_str); - else { - fprintf(prof_fp, "%s %s", op2str(pc->opcode), t1->pp_str); - // print the comment - print_comment(pc->nexti, 0); - pc = pc->nexti; /* skip it */ - } - } + if (pc->source_line > 0) /* don't print implicit 'return' at end of function */ + fprintf(prof_fp, "%s %s\n", op2str(pc->opcode), t1->pp_str); pp_free(t1); break; @@ -954,9 +929,8 @@ cleanup: */ fprintf(prof_fp, "} %s ", op2str(pc->opcode)); - next_real = get_next_real_inst(pc->nexti); - if (next_real->nexti->opcode == Op_K_if - && pc->branch_end == next_real->nexti->branch_else->nexti) { + if (pc->nexti->nexti->opcode == Op_K_if + && pc->branch_end == pc->nexti->nexti->branch_else->lasti) { pprint(pc->nexti, pc->branch_end, IN_ELSE_IF); } else { fprintf(prof_fp, "{\n"); -- cgit v1.2.3 From b60cdd6dc30f9f4845f43b7ca17a490233ec3918 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 3 Mar 2016 20:55:06 +0200 Subject: Fix a compile warning in profile.c. --- profile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'profile.c') diff --git a/profile.c b/profile.c index 178deb7e..842b04fb 100644 --- a/profile.c +++ b/profile.c @@ -1423,10 +1423,10 @@ pp_list(int nargs, const char *paren, const char *delim) erealloc(pp_args, NODE **, (nargs + 2) * sizeof(NODE *), "pp_list"); } + delimlen = strlen(delim); if (nargs == 0) len = 2; else { - delimlen = strlen(delim); len = -delimlen; for (i = 1; i <= nargs; i++) { r = pp_args[i] = pp_pop(); -- cgit v1.2.3