scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 3bab86e457e6c4035faa26e237bc5ed7e85da472
parent da493b024ec13e759e5f5efd2e165120ca301e37
Author: Roberto E. Vargas Caballero <roberto.vargas@igrid-td.com>
Date:   Tue, 12 Apr 2016 17:01:49 +0200

[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

Diffstat:
cc2/arch/amd64-sysv/cgen.c | 4++--
cc2/arch/i386-sysv/cgen.c | 4++--
cc2/arch/qbe/cgen.c | 4++--
cc2/arch/z80/cgen.c | 20++++----------------
cc2/cc2.h | 3++-
cc2/main.c | 2+-
cc2/node.c | 12++++++++++++
7 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/cc2/arch/amd64-sysv/cgen.c b/cc2/arch/amd64-sysv/cgen.c @@ -7,7 +7,7 @@ generate(void) { } -void -addressability(void) +Node * +sethi(Node *np) { } diff --git a/cc2/arch/i386-sysv/cgen.c b/cc2/arch/i386-sysv/cgen.c @@ -7,7 +7,7 @@ generate(void) { } -void -addressability(void) +Node * +sethi(Node *np) { } diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -7,7 +7,7 @@ generate(void) { } -void -addressability(void) +Node * +sethi(Node *np) { } diff --git a/cc2/arch/z80/cgen.c b/cc2/arch/z80/cgen.c @@ -16,8 +16,8 @@ generate(void) * STATIC => 12 (value) * CONST => 20 $value */ -static Node * -address(Node *np) +Node * +sethi(Node *np) { Node *lp, *rp; @@ -43,9 +43,9 @@ address(Node *np) break; default: if (lp) - address(lp); + sethi(lp); if (rp) - address(rp); + sethi(rp); break; } @@ -65,15 +65,3 @@ address(Node *np) ++np->complex; return np; } - -void -addressability(void) -{ - Node *np; - - if (!curfun) - return; - - for (np = curfun->u.label; np; np = np->stmt) - address(np); -} diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -182,7 +182,7 @@ extern void parse(void); 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 writeout(void), endinit(void), newfun(void); 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); diff --git a/cc2/main.c b/cc2/main.c @@ -39,7 +39,7 @@ main(void) while (moreinput()) { parse(); optimize(); - addressability(); + apply(sethi); generate(); peephole(); writeout(); diff --git a/cc2/node.c b/cc2/node.c @@ -74,3 +74,15 @@ cleannodes(void) free(ap); } } + +void +apply(Node *(*fun)(Node *)) +{ + Node *np; + + if (!curfun) + return; + + for (np = curfun->u.label; np; np = np->stmt) + (*fun)(np); +}