scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit ce395c866892026f04bedf55761dff941ee7ba78
parent 9b1fb289b5fcb87d7f1b2b64372d476a20f4e7f1
Author: Roberto E. Vargas Caballero <roberto.vargas@igrid-td.com>
Date:   Thu, 31 Mar 2016 18:18:14 +0200

[cc2] Remove label() from the target interface

Label() was a really low level interface, which didn't fit
properly with qbe.

Diffstat:
Mcc2/arch/amd64-sysv/code.c | 22+++++++++++-----------
Mcc2/arch/i386-sysv/code.c | 22+++++++++++-----------
Mcc2/arch/qbe/code.c | 5-----
Mcc2/arch/z80/code.c | 2+-
Mcc2/cc2.h | 1-
Mcc2/parser.c | 52++++++++++++++++++++++++++++------------------------
6 files changed, 51 insertions(+), 53 deletions(-)

diff --git a/cc2/arch/amd64-sysv/code.c b/cc2/arch/amd64-sysv/code.c @@ -132,16 +132,6 @@ size2asm(Type *tp) void -defsym(Symbol *sym, int alloc) -{ - label(sym); - if (!alloc) - return; - size2asm(&sym->type); - puts("0"); -} - -void data(Node *np) { size2asm(&np->type); @@ -149,7 +139,7 @@ data(Node *np) putchar('\n'); } -void +static void label(Symbol *sym) { int seg, flags = sym->type.flags; @@ -184,6 +174,16 @@ label(Symbol *sym) } void +defsym(Symbol *sym, int alloc) +{ + label(sym); + if (!alloc) + return; + size2asm(&sym->type); + puts("0"); +} + +void writeout(void) { } diff --git a/cc2/arch/i386-sysv/code.c b/cc2/arch/i386-sysv/code.c @@ -131,16 +131,6 @@ size2asm(Type *tp) } void -defsym(Symbol *sym, int alloc) -{ - label(sym); - if (!alloc) - return; - size2asm(&sym->type); - puts("0"); -} - -void data(Node *np) { size2asm(&np->type); @@ -148,7 +138,7 @@ data(Node *np) putchar('\n'); } -void +static void label(Symbol *sym) { int seg, flags = sym->type.flags; @@ -183,6 +173,16 @@ label(Symbol *sym) } void +defsym(Symbol *sym, int alloc) +{ + label(sym); + if (!alloc) + return; + size2asm(&sym->type); + puts("0"); +} + +void writeout(void) { } diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -18,11 +18,6 @@ data(Node *np) } void -label(Symbol *sym) -{ -} - -void writeout(void) { } diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c @@ -59,7 +59,7 @@ code(int op, Node *to, Node *from) { } -void +static void label(Symbol *sym) { int seg, flags = sym->type.flags; diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -162,7 +162,6 @@ extern void generate(void); extern void peephole(void); /* code.c */ -extern void label(Symbol *sym); extern void data(Node *np); extern void defsym(Symbol *sym, int alloc); extern void writeout(void); diff --git a/cc2/parser.c b/cc2/parser.c @@ -498,25 +498,35 @@ array(void) static void decl(Symbol *sym) { - switch (sym->kind) { - case EXTRN: - defsym(sym, 0); - break; - case GLOB: - case PRIVAT: - case LOCAL: - defsym(sym, !ininit); - break; - case AUTO: - case REG: - if (funpars >= 0) { - if (funpars == NR_FUNPARAM) - error(EOUTPAR); - params[funpars++] = sym; + int alloc; + Type *tp = &sym->type; + + if (tp->flags & FUNF) { + curfun = sym; + return; + } else { + switch (sym->kind) { + case EXTRN: + alloc = 0; + break; + case GLOB: + case PRIVAT: + case LOCAL: + alloc = (tp->flags & INITF) == 0; break; + case AUTO: + case REG: + if (funpars >= 0) { + if (funpars == NR_FUNPARAM) + error(EOUTPAR); + params[funpars++] = sym; + } + return; + default: + abort(); } - break; } + defsym(sym, alloc); } static void @@ -544,14 +554,7 @@ vardecl(void) if (ininit) sym->type.flags |= INITF; - - if ((tp->flags & FUNF) == 0) { - decl(sym); - } else { - curfun = sym; - label(sym); - } - + decl(sym); delnode(np); } @@ -632,6 +635,7 @@ endfun(void) np = newnode(); np->op = ONOP; addnode(np); + /* TODO: process the function */ curfun = NULL; funpars = -1; endf = 1;