ref: 7a2a1f936d8ca77484fa4ddb3b1244ecd350a8b5
parent: 68ab5ce9603446bf4a4098e7d03f32f9be99171f
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Aug 13 08:58:34 EDT 2015
Add DBG() macro This macro removes all the debug output when NDEBUG is defined
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -207,12 +207,12 @@
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 @@
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:
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -537,7 +537,7 @@
yytoken = operator();
exit:
- fprintf(stderr, "TOKEN %s\n", yytext);
+ DBG(stderr, "TOKEN %s\n", yytext);
lex_ns = NS_IDEN;
return yytoken;
}
--- a/inc/cc.h
+++ b/inc/cc.h
@@ -7,6 +7,12 @@
#endif
#endif
+#ifndef NDEBUG
+#define DBG(...) fprintf(__VA_ARGS__)
+#else
+#define DBG(...)
+#endif
+
#define TINT long
#define TUINT unsigned long
#define TFLOAT double