- Source_File *sf = arg;
- Sym *b;
- long cnt;
- static long last_count;
-
- if (line_num == 1) {
- last_count = -1;
- } /* if */
-
- b = 0;
- if (line_num <= sf->num_lines) {
- b = sf->line[line_num - 1];
- } /* if */
- if (!b) {
- cnt = -1;
- } else {
- ++num_executable_lines;
- cnt = b->ncalls;
- } /* if */
- if (cnt > 0) {
- ++num_lines_executed;
- } /* if */
- if (cnt < 0 && bb_annotate_all_lines) {
- cnt = last_count;
- } /* if */
-
- if (cnt < 0) {
- strcpy(buf, "\t\t");
- } else if (cnt < bb_min_calls) {
- strcpy(buf, " ##### -> ");
- } else {
- sprintf(buf, "%12ld -> ", cnt);
- } /* if */
- last_count = cnt;
-} /* annotate_with_count */
-
-
-/*
- * Annotate the files named in SOURCE_FILES with basic-block statistics
- * (execution counts). After each source files, a few statistics
- * regarding that source file are printed.
- */
+ Source_File *sf = (Source_File *) arg;
+ Sym *b;
+ unsigned int i;
+ static unsigned long last_count;
+ unsigned long last_print = (unsigned long) -1;
+
+ b = NULL;
+
+ if (line_num <= sf->num_lines)
+ b = (Sym *) sf->line[line_num - 1];
+
+ if (!b)
+ {
+ for (i = 0; i < width; i++)
+ buf[i] = ' ';
+ buf[width] = '\0';
+ }
+ else
+ {
+ char tmpbuf[NBBS * 30];
+ char *p;
+ unsigned long ncalls;
+ int ncalls_set;
+ unsigned int len;
+
+ ++num_executable_lines;
+
+ p = tmpbuf;
+ *p = '\0';
+
+ ncalls = 0;
+ ncalls_set = 0;
+
+ /* If this is a function entry point, label the line no matter what.
+ Otherwise, we're in the middle of a function, so check to see
+ if the first basic-block address is larger than the starting
+ address of the line. If so, then this line begins with a
+ a portion of the previous basic-block, so print that prior
+ execution count (if bb_annotate_all_lines is set). */
+ if (b->is_func)
+ {
+ sprintf (p, "%lu", b->ncalls);
+ p += strlen (p);
+ last_count = b->ncalls;
+ last_print = last_count;
+ ncalls = b->ncalls;
+ ncalls_set = 1;
+ }
+ else if (bb_annotate_all_lines
+ && b->bb_addr[0] && b->bb_addr[0] > b->addr)
+ {
+ sprintf (p, "%lu", last_count);
+ p += strlen (p);
+ last_print = last_count;
+ ncalls = last_count;
+ ncalls_set = 1;
+ }
+
+ /* Loop through all of this line's basic-blocks. For each one,
+ update last_count, then compress sequential identical counts
+ (if bb_annotate_all_lines) and print the execution count. */
+
+ for (i = 0; i < NBBS && b->bb_addr[i]; i++)
+ {
+ last_count = b->bb_calls[i];
+ if (! ncalls_set)
+ {
+ ncalls = 0;
+ ncalls_set = 1;
+ }
+ ncalls += last_count;
+
+ if (bb_annotate_all_lines && last_count == last_print)
+ continue;
+
+ if (p > tmpbuf)
+ *p++ = ',';
+ sprintf (p, "%lu", last_count);
+ p += strlen (p);
+
+ last_print = last_count;
+ }
+
+ /* We're done. If nothing has been printed on this line,
+ print the last execution count (bb_annotate_all_lines),
+ which could be from either a previous line (if there were
+ no BBs on this line), or from this line (if all our BB
+ counts were compressed out because they were identical). */
+
+ if (bb_annotate_all_lines && p == tmpbuf)
+ {
+ sprintf (p, "%lu", last_count);
+ p += strlen (p);
+ ncalls = last_count;
+ ncalls_set = 1;
+ }
+
+ if (! ncalls_set)
+ {
+ unsigned int c;
+
+ for (c = 0; c < width; c++)
+ buf[c] = ' ';
+ buf[width] = '\0';
+ return;
+ }
+
+ ++num_lines_executed;
+
+ if (ncalls < bb_min_calls)
+ {
+ strcpy (tmpbuf, "#####");
+ p = tmpbuf + 5;
+ }
+
+ strcpy (p, " -> ");
+ p += 4;
+
+ len = p - tmpbuf;
+ if (len >= width)
+ {
+ strncpy (buf, tmpbuf, width);
+ buf[width] = '\0';
+ }
+ else
+ {
+ unsigned int c;
+
+ strcpy (buf + width - len, tmpbuf);
+ for (c = 0; c < width - len; ++c)
+ buf[c] = ' ';
+ }
+ }
+}
+
+/* Annotate the files named in SOURCE_FILES with basic-block statistics
+ (execution counts). After each source files, a few statistics
+ regarding that source file are printed. */
+