shithub: scc

Download patch

ref: dfc2beaa2c71a595983aefba6782ad412a4662b6
parent: d50069c79f745e969bbfacd15798947778a18552
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Apr 12 13:01:49 EDT 2016

[cc2] Rename addressability() to apply()

Addressability() was basically running over the nodes of the current
function and calling a function for every statement. This is a general
function and it is better to pass it the function we can call for
every statement.
Since the function is now a generic function, the best place for it
is in node.c

--- a/cc2/arch/amd64-sysv/cgen.c
+++ b/cc2/arch/amd64-sysv/cgen.c
@@ -7,7 +7,7 @@
 {
 }
 
-void
-addressability(void)
+Node *
+sethi(Node *np)
 {
 }
--- a/cc2/arch/i386-sysv/cgen.c
+++ b/cc2/arch/i386-sysv/cgen.c
@@ -7,7 +7,7 @@
 {
 }
 
-void
-addressability(void)
+Node *
+sethi(Node *np)
 {
 }
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -7,7 +7,7 @@
 {
 }
 
-void
-addressability(void)
+Node *
+sethi(Node *np)
 {
 }
--- a/cc2/arch/z80/cgen.c
+++ b/cc2/arch/z80/cgen.c
@@ -16,8 +16,8 @@
  *     STATIC => 12        (value)
  *     CONST => 20         $value
  */
-static Node *
-address(Node *np)
+Node *
+sethi(Node *np)
 {
 	Node *lp, *rp;
 
@@ -43,9 +43,9 @@
 		break;
 	default:
 		if (lp)
-			address(lp);
+			sethi(lp);
 		if (rp)
-			address(rp);
+			sethi(rp);
 		break;
 	}
 
@@ -64,16 +64,4 @@
 	if (np->complex == 0)
 		++np->complex;
 	return np;
-}
-
-void
-addressability(void)
-{
-	Node *np;
-
-	if (!curfun)
-		return;
-
-	for (np = curfun->u.label; np; np = np->stmt)
-		address(np);
 }
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -182,7 +182,7 @@
 extern void optimize(void);
 
 /* cgen.c */
-extern void addressability(void);
+extern Node *sethi(Node *np);
 extern void generate(void);
 
 /* peep.c */
@@ -194,6 +194,7 @@
 extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
 
 /* node.c */
+extern void apply(Node *(*fun)(Node *));
 extern void cleannodes(void);
 extern void delnode(Node *np);
 extern void deltree(Node *np);
--- a/cc2/main.c
+++ b/cc2/main.c
@@ -39,7 +39,7 @@
 	while (moreinput()) {
 		parse();
 		optimize();
-		addressability();
+		apply(sethi);
 		generate();
 		peephole();
 		writeout();
--- a/cc2/node.c
+++ b/cc2/node.c
@@ -74,3 +74,15 @@
 		free(ap);
 	}
 }
+
+void
+apply(Node *(*fun)(Node *))
+{
+	Node *np;
+
+	if (!curfun)
+		return;
+
+	for (np = curfun->u.label; np; np = np->stmt)
+		(*fun)(np);
+}
--