Add "debug" diagnotic printing, and use it.

Debug diagnostics are silent for verbosity levels less than 1.
This commit is contained in:
Bill Currie 2011-01-28 13:28:45 +09:00
parent a37bdd9fb5
commit 834417b8c8
3 changed files with 34 additions and 5 deletions

View file

@ -48,6 +48,8 @@ struct expr_s *warning (struct expr_s *e, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
struct expr_s *notice (struct expr_s *e, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
void debug (struct expr_s *e, const char *mft, ...)
__attribute__ ((format (printf, 2, 3)));
//@}

View file

@ -96,6 +96,33 @@ _warning (expr_t *e, const char *fmt, va_list args)
fputs ("\n", stderr);
}
void
debug (expr_t *e, const char *fmt, ...)
{
va_list args;
if (options.verbosity < 1)
return;
va_start (args, fmt);
if (options.notices.promote) {
_warning (e, fmt, args);
} else {
string_t file = pr.source_file;
int line = pr.source_line;
report_function (e);
if (e) {
file = e->file;
line = e->line;
}
fprintf (stderr, "%s:%d: debug: ", GETSTR (file), line);
vfprintf (stderr, fmt, args);
fputs ("\n", stderr);
}
va_end (args);
}
expr_t *
notice (expr_t *e, const char *fmt, ...)
{

View file

@ -735,9 +735,9 @@ statement_expr (sblock_t *sblock, expr_t *e)
break;
default:
if (e->e.expr.op < 256)
notice (e, "e %c", e->e.expr.op);
debug (e, "e %c", e->e.expr.op);
else
notice (e, "e %d", e->e.expr.op);
debug (e, "e %d", e->e.expr.op);
if (options.warnings.executable)
warning (e, "Non-executable statement;"
" executing programmer instead.");
@ -753,7 +753,7 @@ statement_uexpr (sblock_t *sblock, expr_t *e)
switch (e->e.expr.op) {
case 'r':
notice (e, "RETURN");
debug (e, "RETURN");
opcode = "<RETURN>";
if (!e->e.expr.e1 && !options.traditional)
opcode = "<RETURN_V>";
@ -768,7 +768,7 @@ statement_uexpr (sblock_t *sblock, expr_t *e)
sblock = statement_branch (sblock, e);
break;
default:
notice (e, "e ue %d", e->e.expr.op);
debug (e, "e ue %d", e->e.expr.op);
if (options.warnings.executable)
warning (e, "Non-executable statement;"
" executing programmer instead.");
@ -862,7 +862,7 @@ remove_dead_blocks (sblock_t *blocks)
statement_t *s;
ex_label_t *label = 0;
notice (0, "removing dead block %p", sb);
debug (0, "removing dead block %p", sb);
sblock->next = sb->next;
free_sblock (sb);