scc

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

commit 414ccc5a4e31eb805c5031d43f01d73c373019f7
parent 091ac73575727b8f19c47d1af325874f0b538993
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 16 Apr 2014 11:21:55 +0200

First version of emitdcl()

This first version is not full functional, but it enough
in order  to can begin with a code evaluator.

Diffstat:
cc.h | 1+
code.c | 29+++++++++++++++++++++++++----
decl.c | 6+++---
3 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/cc.h b/cc.h @@ -233,6 +233,7 @@ enum { }; extern void + emitdcl(Symbol *), emitsym(Node *), emitunary(Node *), emitbin(Node *), emitexp(Node *), emitconst(Node *np); diff --git a/code.c b/code.c @@ -60,10 +60,9 @@ node(Inst code, Type *tp, union unode u, uint8_t nchilds) return np; } -void -emitsym(Node *np) +static void +emitsym2(Symbol *sym) { - Symbol *sym = np->u.sym; char c; if (sym->s.isglobal) @@ -74,7 +73,29 @@ emitsym(Node *np) c = 'Q'; else c = 'A'; - printf("\t%c%d", c, sym->id); + printf("%c%d", c, sym->id); +} + +void +emitsym(Node *np) +{ + putchar('\t'); + emitsym2(np->u.sym); +} + +static void +emittype(Type *tp) +{ + putchar(tp->letter); +} + +void +emitdcl(Symbol *sym) +{ + emitsym2(sym); + putchar('\t'); + emittype(sym->type); + putchar('\n'); } void diff --git a/decl.c b/decl.c @@ -440,11 +440,11 @@ decl(void) case STATIC: sym->s.isstatic = 1; break; case EXTERN: /* TODO: */; break; case TYPEDEF: /* TODO: */;break; - case AUTO: /* TODO: */; break; - default: sym->s.isauto = 1; + case AUTO: default: sym->s.isauto = 1; } if (accept('=')) - initializer(sym->type); + initializer(sym->type); /* TODO: emit initializer */ + emitdcl(sym); } while (accept(',')); } }