commit 7a2a1f936d8ca77484fa4ddb3b1244ecd350a8b5
parent 68ab5ce9603446bf4a4098e7d03f32f9be99171f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 13 Aug 2015 12:58:34 +0200
Add DBG() macro
This macro removes all the debug output when NDEBUG is defined
Diffstat:
3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/cc1/cpp.c b/cc1/cpp.c
@@ -207,12 +207,12 @@ expand(char *begin, Symbol *sym)
if (!parsepars(arguments, arglist, atoi(s)))
return 0;
for (n = 0; n < atoi(s); ++n)
- fprintf(stderr, "MACRO par%d:%s\n", n, arglist[n]);
+ DBG(stderr, "MACRO par%d:%s\n", n, arglist[n]);
elen = copymacro(buffer, s+3, INPUTSIZ-1, arglist);
substitute:
- fprintf(stderr, "MACRO '%s' expanded to :'%s'\n", macroname, buffer);
+ DBG(stderr, "MACRO '%s' expanded to :'%s'\n", macroname, buffer);
rlen = strlen(input->p); /* rigth length */
llen = begin - input->line; /* left length */
ilen = input->p - begin; /* invocation length */
@@ -334,7 +334,7 @@ define(void)
if (!getdefs(args, n, buff+3, LINESIZ-3))
goto delete;
sym->u.s = xstrdup(buff);
- fprintf(stderr, "MACRO '%s' defined as '%s'\n", sym->name, buff);
+ DBG(stderr, "MACRO '%s' defined as '%s'\n", sym->name, buff);
return;
delete:
diff --git a/cc1/lex.c b/cc1/lex.c
@@ -537,7 +537,7 @@ next(void)
yytoken = operator();
exit:
- fprintf(stderr, "TOKEN %s\n", yytext);
+ DBG(stderr, "TOKEN %s\n", yytext);
lex_ns = NS_IDEN;
return yytoken;
}
diff --git a/inc/cc.h b/inc/cc.h
@@ -7,6 +7,12 @@ typedef unsigned bool;
#endif
#endif
+#ifndef NDEBUG
+#define DBG(...) fprintf(__VA_ARGS__)
+#else
+#define DBG(...)
+#endif
+
#define TINT long
#define TUINT unsigned long
#define TFLOAT double