scc

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

commit 19f5c0a15f0e21510092ded91507a7a6e5feb9cf
parent 1cdf7496909e5ec1532ad2fb1903c86f19f57ca6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  7 Jun 2016 08:40:34 +0200

[cc2] Add newlabel()

This function is going to be useful in different targets and in a lot of
different situations, so it is a good idea to have it in cc2/code.c.

Diffstat:
cc2/arch/qbe/cgen.c | 7++-----
cc2/cc2.h | 1+
cc2/code.c | 9+++++++++
3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -410,11 +410,8 @@ cgen(Node *np) case OBRANCH: next = np->next; load(np, LOADL); - if (next->label) { - sym = getsym(TMPSYM); - sym->kind = SLABEL; - next->label = sym; - } + if (!next->label) + next->label = newlabel(); ifyes = label2node(np->u.sym); ifno = label2node(next->label); op = ASBRANCH; diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -207,6 +207,7 @@ extern void code(int op, Node *to, Node *from1, Node *from2); extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *); extern void setlabel(Symbol *sym); extern Node *label2node(Symbol *sym); +extern Symbol *newlabel(void); /* node.c */ #define SETCUR 1 diff --git a/cc2/code.c b/cc2/code.c @@ -57,6 +57,15 @@ addr(Node *np, Addr *addr) } } +Symbol * +newlabel(void) +{ + Symbol *sym = getsym(TMPSYM); + + sym->kind = SLABEL; + return sym; +} + Node * label2node(Symbol *sym) {