scc

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

commit 7741d58782520663fdc12c27a0c10b795b8d7fad
parent d1c3a0d77670defbdac8bc39a5182170934d8063
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 30 Mar 2014 22:04:47 +0200

Remove the complex types

It is obvious we are not going to implemente the complex types,
because it is a non sense in a compiler for a z80.

Diffstat:
Mcc.h | 13++++---------
Mdecl.c | 29+++++------------------------
Mtypes.c | 154+++++++++++++++----------------------------------------------------------------
3 files changed, 37 insertions(+), 159 deletions(-)

diff --git a/cc.h b/cc.h @@ -45,11 +45,9 @@ struct symbol; struct ctype { uint8_t op; /* type builder operator */ - short size; /* size of variables */ + char letter; /* letter of the type */ short nelem; /* number of elements in arrays */ unsigned defined : 1; /* type defined (is not a forward reference) */ - unsigned cplex : 1; /* complex specifier */ - unsigned imag : 1; unsigned sign : 1; /* sign type */ struct symbol *sym; /* symbol of the tag identifier */ struct ctype *type; /* base type */ @@ -79,7 +77,6 @@ union value { int i; struct symbol *sym; uint8_t ns, token; - short offset; }; struct symbol { @@ -105,7 +102,7 @@ typedef struct symbol Symbol; extern void freesyms(uint8_t ns); extern Type *qualifier(Type *tp, uint8_t qlf), - *ctype(int8_t type, int8_t sign, int8_t size, int8_t cplex), + *ctype(int8_t type, int8_t sign, int8_t size), *mktype(Type *tp, uint8_t op, Symbol *tag, uint16_t nelem); @@ -121,9 +118,7 @@ extern Type *voidtype, *ushortype, *shortype, *longtype, *ulongtype, *ullongtype, *llongtype, - *floattype, *cfloattype, *ifloattype, - *doubletype, *cdoubletype, *idoubletype, - *ldoubletype, *cldoubletype,*ildoubletype; + *floattype, *doubletype, *ldoubletype; #define ISQUAL(t) (isqual((t)->op)) #define UNQUAL(t) (ISQUAL(t) ? (t)->type : (t)) @@ -222,7 +217,7 @@ enum { extern void emitsym(Node *), emitunary(Node *), emitbin(Node *); extern Node - *node(void (*code)(Node *), Type *tp, union unode u, uint8_t nchilds), + *node(Inst code, Type *tp, union unode u, uint8_t nchilds), *unarycode(char op, Type *tp, Node *child), *bincode(char op, Node *np1, Node *np2); diff --git a/decl.c b/decl.c @@ -166,9 +166,9 @@ static Type * specifier(int8_t *sclass) { Type *tp = NULL; - int8_t qlf, sign, type, cls, cplex, size, t; + int8_t qlf, sign, type, cls, size, t; - qlf = sign = type = cls = size = cplex = 0; + qlf = sign = type = cls = size = 0; for (;;) { register uint8_t *p; @@ -201,8 +201,6 @@ specifier(int8_t *sclass) } case SHORT: p = &size; break; - case COMPLEX: case IMAGINARY: - p = &cplex; break; } break; default: @@ -226,7 +224,6 @@ check_types: type = INT; } if (sign && type != INT && type != CHAR || - cplex && type != FLOAT && type != DOUBLE || size == SHORT && type != INT || size == LONG && type != INT && type != DOUBLE || size == LONG+LONG && type != INT) { @@ -235,7 +232,7 @@ check_types: if (sclass) *sclass = cls; if (!tp) - tp = ctype(type, sign, size, cplex); + tp = ctype(type, sign, size); return (qlf) ? qualifier(tp, qlf) : tp; invalid_type: @@ -262,7 +259,6 @@ newfield(Type *tp, Symbol *sym) { register struct field *p, *q; register char *s, *t; - static short size, offset; static uint8_t op; static char *err; @@ -279,25 +275,10 @@ newfield(Type *tp, Symbol *sym) p = xmalloc(sizeof(*p)); p->next = NULL; p->sym = sym; - size = sym->type->size; - if (!q) { + if (!q) tp->u.fields = p; - if (op != ENUM) { - tp->size = size; - sym->u.offset = 0; - } - } else { + else q->next = p; - if (tp->op == STRUCT) { - offset = ALIGN(size, tp->size); - sym->u.offset = offset; - tp->size = offset + size; - } else if (op == UNION) { - sym->u.offset = 0; - if (tp->size < size) - tp->size = size; - } - } return; diff --git a/types.c b/types.c @@ -11,101 +11,72 @@ Type *voidtype = &(Type) { - .op = VOID + .op = VOID, + .letter = 'W' }, *booltype = &(Type) { .op = INT, + .letter = 'B' }, *uchartype = &(Type) { .op = INT, - .size = CHARSIZE, + .letter = 'M', .sign = 1 }, *chartype = &(Type) { .op = INT, - .size = CHARSIZE, + .letter = 'C', }, *uinttype = &(Type) { .op = INT, - .size = INTSIZE, + .letter = 'U', .sign = 1 }, *inttype = &(Type) { .op = INT, - .size = INTSIZE, - .sign = 1 + .letter = 'I', }, *ushortype = &(Type) { .op = INT, - .size = SHORTSIZE, + .letter = 'E' }, *shortype = &(Type) { .op = INT, - .size = SHORTSIZE, + .letter = 'K', }, *longtype = &(Type) { .op = INT, - .size = LONGSIZE, + .letter = 'L' }, *ulongtype = &(Type) { .op = INT, - .size = LONGSIZE, + .letter = 'Z', .sign = 1 }, *ullongtype = &(Type) { .op = INT, - .size = LLONGSIZE, + .letter = 'O', .sign = 1 }, *llongtype = &(Type) { .op = INT, - .size = LLONGSIZE, + .letter = 'G', }, *floattype = &(Type) { .op = FLOAT, - .size = FLOATSIZE - }, - *cfloattype = &(Type) { - .op = FLOAT, - .size = FLOATSIZE, - .cplex = 1 - }, - *ifloattype = &(Type) { - .op = FLOAT, - .size = FLOATSIZE, - .imag = 1 + .letter = 'F' }, *doubletype = &(Type) { .op = FLOAT, - .size = FLOATSIZE - }, - *cdoubletype = &(Type) { - .op = FLOAT, - .size = 0, - .cplex = 1 - }, - *idoubletype = &(Type) { - .op = FLOAT, - .size = 0, - .imag = 1 + .letter = 'D' }, *ldoubletype = &(Type) { .op = FLOAT, - .size = LLFLOATSIZE - }, - *cldoubletype = &(Type) { - .op = FLOAT, - .size = 0, - .cplex = 1 - }, - *ildoubletype = &(Type) { - .op = FLOAT, - .size = 0, - .imag = 1 + .letter = 'H' }; Type * -ctype(int8_t type, int8_t sign, int8_t size, int8_t cplex) +ctype(int8_t type, int8_t sign, int8_t size) { if (type == CHAR && !sign) sign = options.charsign; @@ -125,21 +96,9 @@ ctype(int8_t type, int8_t sign, int8_t size, int8_t cplex) case LONG+LONG: return (sign) ? ullongtype : llongtype; } case FLOAT: switch (size) { - case 0: switch (cplex) { - case 0: return floattype; - case COMPLEX: return cfloattype; - case IMAGINARY: return ifloattype; - } - case LONG: switch (cplex) { - case 0: return doubletype; - case COMPLEX: return cdoubletype; - case IMAGINARY: return ifloattype; - } - case LONG+LONG: switch (cplex) { - case 0: return ldoubletype; - case COMPLEX: return cldoubletype; - case IMAGINARY: return ildoubletype; - } + case 0: return floattype; + case LONG: return doubletype; + case LONG+LONG: return ldoubletype; } } } @@ -150,8 +109,8 @@ mktype(Type *tp, uint8_t op, { static Type *typetab[NR_TYPE_HASH], **tbl; static uint8_t t; - static unsigned short size; register Type *bp; + char letter; t = (op ^ (uint8_t) ((unsigned short) tp >> 3)) & NR_TYPE_HASH-1; @@ -166,12 +125,12 @@ mktype(Type *tp, uint8_t op, } switch (op) { - case PTR: size = PTRSIZE; break; - case FTN: size = 0; break; - case ARY: size = tp->size * nelem; break; - case ENUM: size = INTSIZE; - case STRUCT: size = 0; break; - default: size = tp->size; break; + case PTR: letter = 'R'; break; + case FTN: letter = 'F'; break; + case ARY: letter = 'V'; break; + case ENUM: letter = 'E'; break; + case STRUCT: letter = 'S'; break; + default: abort(); } bp = xmalloc(sizeof(*bp)); bp->next = *tbl; @@ -179,7 +138,7 @@ mktype(Type *tp, uint8_t op, bp->op = op; bp->nelem = nelem; bp->sym = sym; - bp->size = size; + bp->letter = letter; return *tbl = bp; } @@ -197,60 +156,3 @@ qualifier(Type *tp, uint8_t qlf) return mktype(tp, qlf|TQUALIFIER, NULL, 0); } -#include <stdio.h> - -static void -ptype(Type *tp) -{ - uint8_t op; - struct funpar *fp; - - if (!tp) - return; - op = tp->op; - if (op & TQUALIFIER) { - if (op & CONST) - fputs("const ", stdout); - if (op & VOLATILE) - fputs("volatile ", stdout); - if (op & RESTRICT) - fputs("restrict ", stdout); - } else { - switch (op) { - case PTR: fputs("pointer ", stdout); break; - case ARY: fputs("array ", stdout); break; - case STRUCT: fputs("struct", stdout); break; - case UNION: fputs("union", stdout); break; - case ENUM: fputs("enum", stdout); break; - case BOOL: fputs("bool", stdout); break; - case INT: - printf("int size=%u sign=%u", tp->size, tp->sign); - break; - case FLOAT: - printf("float size=%u cplex=%u", tp->size, tp->cplex); - break; - case TYPENAME: - printf("typename %s type ", tp->sym->name); - break; - case FTN: - fputs("function(", stdout); - for (fp = tp->u.pars; fp; fp = fp->next) { - ptype(tp); - if (fp->next) - fputs(", ", stdout); - } - fputs(") ", stdout); - break; - } - } - ptype(tp->type); -} - -void -printtype(Type *tp) -{ - printf("type = %p ", tp); - ptype(tp); - putchar('\n'); -} -