shithub: scc

Download patch

ref: 83a996bf5a87158c15f114e8c475d04dd42301de
parent: c097639e7efa2061e1a1b6409f11da28096216e6
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Apr 25 16:10:45 EDT 2016

[cc2] Conver statement list into a double link

We need a double list because we are going to do some modifications
to the elements of the list, mainly in optimizations. Since stmt
operations are node operations is more logical if we move it to
node.c, where all the node functions live.

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -138,7 +138,7 @@
 	char kind;
 	union {
 		TSIZE off;
-		Node *nlabel;
+		Node *stmt;
 		Inst *ilabel;
 	} u;
 	Symbol *next;
@@ -160,7 +160,7 @@
 	} u;
 	Symbol *label;
 	Node *left, *right;
-	Node *stmt;
+	Node *next, *prev;
 };
 
 struct addr {
@@ -208,6 +208,7 @@
 extern void delnode(Node *np);
 extern void deltree(Node *np);
 extern Node *newnode(void);
+extern Node *addstmt(Node *np);
 
 /* symbol.c */
 #define TMPSYM  0
--- a/cc2/node.c
+++ b/cc2/node.c
@@ -18,7 +18,7 @@
 };
 
 static struct arena *arena;
-static Node *freep;
+static Node *freep, *stmtp;
 static int inhome;
 
 Node *
@@ -44,6 +44,20 @@
 	return memset(np, 0, sizeof(*np));
 }
 
+Node *
+addstmt(Node *np)
+{
+	if (!curfun->u.stmt)
+		curfun->u.stmt = np;
+	else
+		stmtp->next = np;
+	np->next = NULL;
+	np->prev = stmtp;
+	stmtp = np;
+
+	return np;
+}
+
 void
 delnode(Node *np)
 {
@@ -73,6 +87,7 @@
 	}
 	arena = NULL;
 	freep = NULL;
+	stmtp = NULL;
 }
 
 void
@@ -83,6 +98,6 @@
 	if (!curfun)
 		return;
 
-	for (np = curfun->u.nlabel; np; np = np->stmt)
+	for (np = curfun->u.stmt; np; np = np->next)
 		(*fun)(np);
 }
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -131,7 +131,6 @@
 };
 
 static int sclass, inpars, ininit, endf, lineno;
-static Node *stmtp;
 static void *stack[STACKSIZ], **sp = stack;
 
 static void
@@ -566,16 +565,6 @@
 
 	delnode(np);
 	delnode(off);
-}
-
-static void
-addstmt(Node *np)
-{
-	if (!curfun->u.nlabel)
-		curfun->u.nlabel = np;
-	else
-		stmtp->stmt = np;
-	stmtp = np;
 }
 
 static void