shithub: scc

Download patch

ref: d3898439422b292cc2220d15e5bf227d9a203e47
parent: 2a3b5ec079f3d0316712326b92dfd0bfb668244c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Sep 26 07:27:05 EDT 2016

[cc2] Add print node functions

These functions are intended only for debugging

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -228,8 +228,10 @@
 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 */
--- a/cc2/node.c
+++ b/cc2/node.c
@@ -46,6 +46,41 @@
 	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)
 {