scc

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

commit 1c3ae449cdff510ea0a8d628f60f8749442abe10
parent 60f62db06595ad07503f3a587607d466c0d460a0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 10 Sep 2014 17:14:27 +0200

Use different symbols for function and global statics

They are basically different, because function static are local names,
while global static are global (of course). In both cases we have to
reserve static memory for them, but they use different tables in cc2.

Diffstat:
Mcc1/code.c | 10++++++----
Mcc2/parser.c | 17++++++++++-------
2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -69,10 +69,12 @@ emitsym2(Symbol *sym) { char c; - if (sym->s.isglobal) - c = 'G'; - else if (sym->s.isstatic) + if (sym->s.isstatic && !sym->s.isglobal) c = 'T'; + else if (sym->s.isstatic && sym->s.isglobal) + c = 'Y'; + else if (sym->s.isglobal) + c = 'G'; else if (sym->s.isregister) c = 'Q'; else @@ -189,7 +191,7 @@ void emitfun(Symbol *sym) { printf("%c%d\tF\t%s\t{\n", - sym->s.isglobal ? 'G' : 'T', sym->id, sym->name); + sym->s.isglobal ? 'G' : 'Y', sym->id, sym->name); } void diff --git a/cc2/parser.c b/cc2/parser.c @@ -165,8 +165,6 @@ variable(char *token) switch (token[0]) { case 'T': - if (!curfun) - goto global; op = MEM; goto local; case 'P': @@ -182,6 +180,7 @@ variable(char *token) break; case 'X': /* TODO */ + case 'Y': case 'G': global: sym = global(token); @@ -293,6 +292,7 @@ static void (*optbl[])(char *) = { ['^'] = operator, [':'] = assignment, [';'] = increment, + ['Y'] = variable, ['A'] = variable, ['T'] = variable, ['G'] = variable, @@ -352,10 +352,10 @@ declaration(char *token) curfun->u.f.pars = sym; break; case 'T': - if (!curfun) { - sym = global(token); - break; - } + if (!curfun) + error(ESYNTAX); + sym = local(token); + break; case 'R': case 'A': if (!curfun) error(ESYNTAX); @@ -367,6 +367,9 @@ declaration(char *token) sym = global(token); sym->extrn = 1; break; + case 'Y': + sym = global(token); + break; case 'G': sym = global(token); sym->public = 1; @@ -435,7 +438,7 @@ parse(void) case 'S': /* struct */ break; - case 'T': case 'G': case 'A': case 'R': case 'P': + case 'Y': case 'T': case 'G': case 'A': case 'R': case 'P': fun = declaration; break; case '}':