[hackers] [scc] [cc2] Add print node functions || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 26 Sep 2016 12:00:42 +0200 (CEST)

commit cee1c1566cd93830e1d106d3d141c0eb0bffa000
Author: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
AuthorDate: Mon Sep 26 11:27:05 2016 +0200
Commit: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
CommitDate: Mon Sep 26 11:27:05 2016 +0200

    [cc2] Add print node functions
    
    These functions are intended only for debugging

diff --git a/cc2/cc2.h b/cc2/cc2.h
index a91cadf..cb0d9c4 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -228,8 +228,10 @@ extern void apply(Node *(*fun)(Node *));
 extern void cleannodes(void);
 extern void delnode(Node *np);
 extern void deltree(Node *np);
+extern void prtree(Node *np), prforest(char *msg);
 extern Node *newnode(int op);
 extern Node *addstmt(Node *np, int flags);
+extern Node *delstmt(void);
 extern Node *nextstmt(void);
 
 /* symbol.c */
diff --git a/cc2/node.c b/cc2/node.c
index 8299431..7306722 100644
--- a/cc2/node.c
+++ b/cc2/node.c
_AT_@ -46,6 +46,41 @@ newnode(int op)
         return np;
 }
 
+#ifndef NDEBUG
+#include <stdio.h>
+
+static void
+prnode(Node *np)
+{
+ if (np->left)
+ prnode(np->left);
+ if (np->right)
+ prnode(np->right);
+ fprintf(stderr, "\t%c%lu", np->op, np->type.size);
+}
+
+void
+prtree(Node *np)
+{
+ prnode(np);
+ putc('\n', stderr);
+}
+
+void
+prforest(char *msg)
+{
+ Node *np;
+
+ if (!curfun)
+ return;
+
+ fprintf(stderr, "%s {\n", msg);
+ for (np = curfun->u.stmt; np; np = np->next)
+ prtree(np);
+ fputs("}\n", stderr);
+}
+#endif
+
 Node *
 addstmt(Node *np, int flag)
 {
Received on Mon Sep 26 2016 - 12:00:42 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 26 2016 - 12:12:19 CEST