scc

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

commit 25ee0a4512e705ff8017b87c8fc6ae6dc94732ce
parent 8ab588d0ba2eaa191b6b93fdb4053db29fdcf8fa
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 16 Feb 2015 18:32:56 +0100

Integrate type in node in cc2

This type is going to be important because in some moment we will
be able to modify the type of the node, so we don't want to modify the
common type.

Diffstat:
cc2/cc2.h | 4++--
cc2/cgen.c | 8++++----
cc2/optm.c | 8++++----
cc2/parser.c | 22+++++++++++-----------
4 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -17,7 +17,7 @@ struct symbol { char type; union { struct { - Type *type; + Type type; char sclass; short off; } v; @@ -35,7 +35,7 @@ struct symbol { struct node { char op; char subop; - Type *type; + Type type; uint8_t complex; uint8_t addable; union { diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -21,7 +21,7 @@ allocreg(Node *np) char reg16[] = {BC, HL, DE, IY, 0}; char *bp, c; - switch (np->type->size) { + switch (np->type.size) { case 1: for (bp = reg8; (c = *bp); ++bp) { if (reguse[c]) @@ -50,7 +50,7 @@ allocreg(Node *np) static void move(Node *np) { - Type *tp = np->type; + Type *tp = &np->type; Symbol *sym; char reg; @@ -126,7 +126,7 @@ cgen(Node *np, Node *parent) switch (np->op) { case OADD: - switch (np->type->size) { + switch (np->type.size) { case 1: if (rp->u.reg == A) { conmute(np); @@ -162,7 +162,7 @@ cgen(Node *np, Node *parent) } break; case OASSIG: - switch (np->type->size) { + switch (np->type.size) { case 1: switch (lp->op) { case AUTO: diff --git a/cc2/optm.c b/cc2/optm.c @@ -18,16 +18,16 @@ repeat: switch (np->op) { case OCAST: /* TODO: be careful with the sign */ - if (np->type->c_int && np->type->size >= tp->size) { + if (np->type.c_int && np->type.size >= tp->size) { np = np->left; goto repeat; } break; case OASSIG: - tp = np->type; + tp = &np->type; break; default: - np->type = tp; + np->type = *tp; } np->left = optcasts(np->left, tp); @@ -38,6 +38,6 @@ repeat: Node * optimize(Node *np) { - np = optcasts(np, np->type); + np = optcasts(np, &np->type); return np; } diff --git a/cc2/parser.c b/cc2/parser.c @@ -93,7 +93,7 @@ prnode(Node *np) prnode(np->left); if (np->right) prnode(np->right); - fprintf(stderr, "\t%c%c", np->op, np->type->letter); + fprintf(stderr, "\t%c%c", np->op, np->type.letter); } void @@ -249,7 +249,7 @@ immediate(char *token) Node *np = newnode(); np->op = CONST; - np->type = gettype(token+1); + np->type = *gettype(token+1); np->u.imm = atoi(token+2); np->left = np->right = NULL; push(np); @@ -262,7 +262,7 @@ unary(char *token) np->right = NULL; np->left = pop(); - np->type = gettype(token+1); + np->type = *gettype(token+1); np->op = token[0]; push(np); } @@ -274,7 +274,7 @@ operator(char *token) np->right = pop(); np->left = pop(); - np->type = gettype(token+1); + np->type = *gettype(token+1); np->op = token[0]; push(np); } @@ -297,7 +297,7 @@ increment(char *token) np->right = pop(); np->left = pop(); - np->type = gettype(token+2); + np->type = *gettype(token+2); np->op = token[0]; switch (np->subop = token[1]) { case '-': case '+': @@ -321,7 +321,7 @@ assignment(char *token) case OSHL: case OSHR: case OBAND: case OBOR: case OBXOR: np->subop = *++token; default: - np->type = gettype(token); + np->type = *gettype(token); break; } push(np); @@ -335,7 +335,7 @@ cast(char *token) np->right = NULL; np->left = pop(); np->op = OCAST; - np->type = gettype(token+1); + np->type = *gettype(token+1); push(np); } @@ -439,7 +439,7 @@ declaration(uint8_t t, char class, char *token) if ((s = strtok(NULL, "\t")) == NULL) error(ESYNTAX); - sym->u.v.type = gettype(s); + sym->u.v.type = *gettype(s); if ((s = strtok(NULL, "\t")) != NULL) sym->name = xstrdup(s); @@ -460,7 +460,7 @@ globdcl(char *token) break; } - if (sym->u.v.type != NULL) + if (sym->u.v.type.size == 0) return; if (curfun) @@ -477,14 +477,14 @@ paramdcl(char *token) { Symbol *sym = declaration(PARAMETER, AUTO, token); sym->u.v.off = -curfun->u.f.params; - curfun->u.f.params += sym->u.v.type->size; + curfun->u.f.params += sym->u.v.type.size; } static void localdcl(char *token) { Symbol *sym = declaration(LOCAL, token[0], token); - curfun->u.f.locals += sym->u.v.type->size; + curfun->u.f.locals += sym->u.v.type.size; sym->u.v.off = 1-curfun->u.f.locals; }