scc

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

commit a8b9e699e5f953f3521cbe2e3e9ad431f307823c
parent 2c5658c7d684eef9de76ff7715f7da6debb69d8f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 25 Mar 2014 13:54:43 +0100

This commit is a shit

I have commit a lot of different things not directly related between
them.

Diffstat:
Mcode.c | 21+++++++++++++++++++--
Acode.h | 10++++++++++
Mdecl.c | 7++++---
Mexpr.c | 12++++++++++--
Astmt.c | 26++++++++++++++++++++++++++
5 files changed, 69 insertions(+), 7 deletions(-)

diff --git a/code.c b/code.c @@ -18,4 +18,22 @@ emitsym(struct symbol *sym) else c = 'A'; printf("\t%c%d", c, sym->id); -} -\ No newline at end of file +} + +void +emitfun(struct symbol *sym) +{ + printf("X%s\n", sym->name); +} + +void +emitframe(struct symbol *sym) +{ + puts("{"); +} + +void +emitret(struct symbol *sym) +{ + puts("}"); +} diff --git a/code.h b/code.h @@ -0,0 +1,10 @@ + +#ifndef CODE_H_ +#define CODE_H_ + +struct symbol; + +extern void emitsym(struct symbol *sym), emitfun(struct symbol *sym), + emitframe(struct symbol *sym), emitret(struct symbol *sym); + +#endif diff --git a/decl.c b/decl.c @@ -6,7 +6,6 @@ #include "sizes.h" #include "cc.h" #include "tokens.h" -#include "syntax.h" #include "symbol.h" #include "machine.h" @@ -56,6 +55,7 @@ static struct symbol * newiden(uint8_t ns) { struct symbol *sym; + extern uint8_t curctx; if (yylval.sym && yylval.sym->ctx == curctx) error("redeclaration of '%s'", yytext); @@ -492,14 +492,15 @@ extdecl(void) if (yytoken != ';') { do { - extern void printtype(struct ctype *tp); sym = declarator(tp, NS_IDEN, ID_EXPECTED); - printtype(sym->type); if (!(sclass & STATIC)) sym->s.isglobal = 1; if (ISFUN(sym->type)) { + emitfun(sym); if (yytoken == '{') { + emitframe(sym); context(compound); + emitret(sym); freesyms(NS_LABEL); return; } diff --git a/expr.c b/expr.c @@ -32,18 +32,26 @@ primary(void) expect(')'); break; default: - tp = NULL; + error("unexpected '%s'", yytoken); } return tp; } +static struct ctype * +postfix(void) +{ + struct ctype * tp; + + tp = primary(); +} + struct ctype * expr(void) { register struct ctype *tp; do - tp = primary(); + tp = postfix(); while (yytoken == ','); return tp; diff --git a/stmt.c b/stmt.c @@ -0,0 +1,25 @@ + +#include <stdint.h> + +#include "symbol.h" +#include "tokens.h" + + +void +compound(void) +{ + extern struct ctype *expr(void); + extern void decl(void); + + expect('{'); + while (!accept('}')) { + switch (yytoken) { + case TYPE: case SCLASS: case TQUALIFIER: + decl(); + break; + default: + expr(); + } + expect(';'); + } +} +\ No newline at end of file