ref: 4698e1692871826efbc031b0d2c9991ea8ee6be5
parent: 6474d05ae74cc9a59f67bdc84ae4428983f09ffe
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Feb 12 07:20:58 EST 2015
Add prtree() to cc2 This function prints a tree, that is really useful for debugging.
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -5,6 +5,7 @@
typedef struct {
short size;
uint8_t align;
+ char letter;
bool sign : 1;
bool c_int : 1;
} Type;
@@ -116,3 +117,4 @@
extern void apply(Node *list[], void (*fun)(Node *));
extern Symbol *parse(void);
extern void code(char op, ...);
+extern void prtree(Node *np);
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -26,6 +26,7 @@
Type l_int8 = {
+ .letter = L_INT8,
.size = 1,
.align = 2,
.sign = 1,
@@ -33,6 +34,7 @@
};
Type l_int16 = {
+ .letter = L_INT16,
.size = 2,
.align = 2,
.sign = 1,
@@ -40,6 +42,7 @@
};
Type l_int32 = {
+ .letter = L_INT32,
.size = 4,
.align = 4,
.sign = 1,
@@ -47,6 +50,7 @@
};
Type l_int64 = {
+ .letter = L_INT64,
.size = 8,
.align = 8,
.sign = 1,
@@ -54,6 +58,7 @@
};
Type l_uint8 = {
+ .letter = L_UINT8,
.size = 1,
.align = 2,
.c_int = 1,
@@ -60,6 +65,7 @@
};
Type l_uint16 = {
+ .letter = L_UINT16,
.size = 2,
.align = 2,
.c_int = 1,
@@ -66,6 +72,7 @@
};
Type l_uint32 = {
+ .letter = L_UINT32,
.size = 4,
.align = 4,
.c_int = 1,
@@ -72,10 +79,29 @@
};
Type l_uint64 = {
+ .letter = L_UINT64,
.size = 8,
.align = 8,
.c_int = 1,
};
+
+
+static void
+prnode(Node *np)
+{
+ if (np->left)
+ prnode(np->left);
+ if (np->right)
+ prnode(np->right);
+ fprintf(stderr, "\t%c%c", np->op, np->type->letter);
+}
+
+void
+prtree(Node *np)
+{
+ prnode(np);
+ putc('\n', stderr);
+}
void
apply(Node *list[], void (*fun)(Node *))