scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit cee1c1566cd93830e1d106d3d141c0eb0bffa000
parent 009c13bcf646d01965d6e981ae4a67b3abab41ab
Author: Roberto E. Vargas Caballero <roberto.vargas@igrid-td.com>
Date:   Mon, 26 Sep 2016 11:27:05 +0200

[cc2] Add print node functions

These functions are intended only for debugging

Diffstat:
Mcc2/cc2.h | 2++
Mcc2/node.c | 35+++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -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 @@ -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) {