From 834417b8c8194d2323ddd0e9516fc5cfa75e2ef6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 28 Jan 2011 13:28:45 +0900 Subject: [PATCH] Add "debug" diagnotic printing, and use it. Debug diagnostics are silent for verbosity levels less than 1. --- tools/qfcc/include/diagnostic.h | 2 ++ tools/qfcc/source/diagnostic.c | 27 +++++++++++++++++++++++++++ tools/qfcc/source/statements.c | 10 +++++----- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/tools/qfcc/include/diagnostic.h b/tools/qfcc/include/diagnostic.h index ff2753632..e8f2d4c6a 100644 --- a/tools/qfcc/include/diagnostic.h +++ b/tools/qfcc/include/diagnostic.h @@ -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))); //@} diff --git a/tools/qfcc/source/diagnostic.c b/tools/qfcc/source/diagnostic.c index 311da5166..5b6adb96a 100644 --- a/tools/qfcc/source/diagnostic.c +++ b/tools/qfcc/source/diagnostic.c @@ -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, ...) { diff --git a/tools/qfcc/source/statements.c b/tools/qfcc/source/statements.c index d0d47d35d..7ab52ae04 100644 --- a/tools/qfcc/source/statements.c +++ b/tools/qfcc/source/statements.c @@ -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 = ""; if (!e->e.expr.e1 && !options.traditional) opcode = ""; @@ -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);