aboutsummaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c69
1 files changed, 29 insertions, 40 deletions
diff --git a/profile.c b/profile.c
index eb788377..6d9db06e 100644
--- a/profile.c
+++ b/profile.c
@@ -43,15 +43,14 @@ const char *redir2str(int redirtype);
#define DONT_FREE 1
#define CAN_FREE 2
-#ifdef PROFILING
+
static RETSIGTYPE dump_and_exit(int signum) ATTRIBUTE_NORETURN;
static RETSIGTYPE just_dump(int signum);
-#endif
/* pretty printing related functions and variables */
static NODE *pp_stack = NULL;
-static char **fparms; /* function parameter names */
+static NODE *func_params; /* function parameters */
static FILE *prof_fp; /* where to send the profile */
static long indent_level = 0;
@@ -59,20 +58,7 @@ static long indent_level = 0;
#define SPACEOVER 0
-/* init_profiling --- do needed initializations, see also main.c */
-
-void
-init_profiling(int *flag ATTRIBUTE_UNUSED, const char *def_file ATTRIBUTE_UNUSED)
-{
-#ifdef PROFILING
- if (*flag == FALSE) {
- *flag = TRUE;
- set_prof_file(def_file);
- }
-#endif
-}
-
-/* set_prof_file --- set the output file for profiling */
+/* set_prof_file --- set the output file for profiling or pretty-printing */
void
set_prof_file(const char *file)
@@ -87,12 +73,11 @@ set_prof_file(const char *file)
}
}
-/* init_profiling_signals --- set up signal handling for pgawk */
+/* init_profiling_signals --- set up signal handling for gawk --profile */
void
init_profiling_signals()
{
-#ifdef PROFILING
#ifdef __DJGPP__
signal(SIGINT, dump_and_exit);
signal(SIGQUIT, just_dump);
@@ -104,7 +89,6 @@ init_profiling_signals()
signal(SIGUSR1, just_dump);
#endif
#endif /* !__DJGPP__ */
-#endif /* PROFILING */
}
/* indent --- print out enough tabs */
@@ -214,10 +198,10 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int in_for_header)
fprintf(prof_fp, "%s {", t1->pp_str);
pp_free(t1);
ip = (pc + 1)->firsti;
-#ifdef PROFILING
- if (ip->exec_count > 0)
+
+ if (do_profile && ip->exec_count > 0)
fprintf(prof_fp, " # %ld", ip->exec_count);
-#endif
+
fprintf(prof_fp, "\n");
} else {
fprintf(prof_fp, "{\n");
@@ -257,6 +241,9 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int in_for_header)
break;
case Op_store_var:
+ if (pc->initval != NULL)
+ pp_push(Op_push_i, pp_node(pc->initval), CAN_FREE);
+ /* fall through */
case Op_store_sub:
case Op_assign_concat:
case Op_push_lhs:
@@ -267,7 +254,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int in_for_header)
m = pc->memory;
switch (m->type) {
case Node_param_list:
- pp_push(pc->opcode, fparms[m->param_cnt], DONT_FREE);
+ pp_push(pc->opcode, func_params[m->param_cnt].param, DONT_FREE);
break;
case Node_var:
@@ -522,9 +509,13 @@ cleanup:
break;
case Op_builtin:
+ case Op_ext_builtin:
{
- static char *ext_func = "extension_function()";
- const char *fname = getfname(pc->builtin);
+ const char *fname;
+ if (pc->opcode == Op_builtin)
+ fname = getfname(pc->builtin);
+ else
+ fname = (pc + 1)->func_name;
if (fname != NULL) {
if (pc->expr_count > 0) {
tmp = pp_list(pc->expr_count, "()", ", ");
@@ -534,10 +525,10 @@ cleanup:
str = pp_concat(fname, "()", "");
pp_push(Op_builtin, str, CAN_FREE);
} else
- pp_push(Op_builtin, ext_func, DONT_FREE);
+ fatal(_("internal error: builtin with null fname"));
}
break;
-
+
case Op_K_print:
case Op_K_printf:
case Op_K_print_rec:
@@ -756,14 +747,15 @@ cleanup:
case Op_K_arrayfor:
{
- char *array, *item;
+ char *array;
+ const char *item;
ip = pc + 1;
t1 = pp_pop();
array = t1->pp_str;
m = ip->forloop_cond->array_var;
if (m->type == Node_param_list)
- item = fparms[m->param_cnt];
+ item = func_params[m->param_cnt].param;
else
item = m->vname;
indent(ip->forloop_body->exec_count);
@@ -909,7 +901,7 @@ pp_string_fp(Func_print print_func, FILE *fp, const char *in_str,
efree(s);
}
-#ifdef PROFILING
+
/* just_dump --- dump the profile and function stack and keep going */
static RETSIGTYPE
@@ -933,7 +925,6 @@ dump_and_exit(int signum)
exit(EXIT_FAILURE);
}
-#endif
/* dump_prog --- dump the program */
@@ -1321,9 +1312,8 @@ int
pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED)
{
int j;
- char **pnames;
- NODE *f;
static int first = TRUE;
+ NODE *func;
int pcount;
if (first) {
@@ -1331,15 +1321,14 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED)
fprintf(prof_fp, _("\n\t# Functions, listed alphabetically\n"));
}
- f = pc->func_body;
+ func = pc->func_body;
fprintf(prof_fp, "\n");
indent(pc->nexti->exec_count);
- fprintf(prof_fp, "%s %s(", op2str(Op_K_function), f->lnode->param);
- pnames = f->parmlist;
- fparms = pnames;
- pcount = f->lnode->param_cnt;
+ fprintf(prof_fp, "%s %s(", op2str(Op_K_function), func->vname);
+ pcount = func->param_cnt;
+ func_params = func->fparms;
for (j = 0; j < pcount; j++) {
- fprintf(prof_fp, "%s", pnames[j]);
+ fprintf(prof_fp, "%s", func_params[j].param);
if (j < pcount - 1)
fprintf(prof_fp, ", ");
}