ref: 94ca1b27fc57c64bf0ee1dc95f1c58555aaf6e2a
parent: 990dcf7fb41e4b4d050ffb6080ccf794922dd88d
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Nov 1 11:58:57 EDT 2021
cc1: Improve prtree() Prtree() is usually used as a debug mechanism. For this reason is better if it can return the same parameter that it receives, because using it in this way means that it can be used as a replacement of functions that return a node pointer.
--- a/src/cmd/cc/cc1/cc1.h
+++ b/src/cmd/cc/cc1/cc1.h
@@ -458,7 +458,7 @@
#define accept(t) ((yytoken == (t)) ? next() : 0)
/* code.c */
-extern void prtree(char *s, Node *np);
+extern Node *prtree(char *s, Node *np);
extern void emit(int, void *);
extern Node *node(int op, Type *tp, Node *left, Node *rigth);
extern Node *varnode(Symbol *sym);
--- a/src/cmd/cc/cc1/code.c
+++ b/src/cmd/cc/cc1/code.c
@@ -164,14 +164,18 @@
(*opcode[np->op])(np->op, np);
}
-void
+Node *
prtree(char *s, Node *np)
{
+ FILE *tmp = outfp;
+
outfp = stderr;
fprintf(outfp, "DBG prtree %s", s);
emitnode(np);
putc('\n', outfp);
- outfp = stdout;
+ outfp = tmp;
+
+ return np;
}
void