scc

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

commit 5215b34485aa15d4dccfe7f2115c3d6701fdcf5c
parent d7890765b7b847f8856c3da07ead0de966b69b80
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 16 Apr 2014 07:22:45 +0200

Unify intcont() and floatconv()

All the conversions are based in converting to the
bigger type, and in integer conversions we use
the size field of type in order to do the conversions,
so using correct numbers here then we can use the
same code for integer and float conversions.

Diffstat:
expr.c | 59+++++++++++++----------------------------------------------
types.c | 9++++++---
2 files changed, 19 insertions(+), 49 deletions(-)

diff --git a/expr.c b/expr.c @@ -38,7 +38,7 @@ promote(Node *np) } static void -intconv(Node **p1, Node **p2) +typeconv(Node **p1, Node **p2) { Type *tp1, *tp2, *new1, *new2; Node *np1 = *p1, *np2 = *p2; @@ -64,11 +64,6 @@ intconv(Node **p1, Node **p2) *p2 = castcode(np2, new2); } -static void -floatconv(Node **np1, Node **np2) -{ -} - static Node * bitlogic(char op, Node *np1, Node *np2) { @@ -83,7 +78,7 @@ bitlogic(char op, Node *np1, Node *np2) if (t1 != INT || t2 != INT) error("No integer operand in bit logical operation"); if (tp1 != tp2) - intconv(&np1, &np2); + typeconv(&np1, &np2); return bincode(op, np1->type, np1, np2); } @@ -122,6 +117,11 @@ convert(Node *np, Type *tp1) switch (t2) { case ARY: case FTN: np = addr2ptr(np); + /* TODO: + * we assume conversion between pointers + * do not need any operation, but due to + * alignment problems that may be false + */ np->type = tp1; return np; } @@ -143,16 +143,13 @@ arithmetic(char op, Node *np1, Node *np2) GETBTYPE(np2, tp2, t2); switch (t1) { - case INT: + case INT: case FLOAT: switch (t2) { - case INT: + case INT: case FLOAT: if (tp1 != tp2) - intconv(&np1, &np2); + typeconv(&np1, &np2); tp1 = np1->type; break; - case FLOAT: - np2 = castcode(np1, np2->type); - break; case PTR: case ARY: SWAP(np1, np2, naux); SWAP(t1, t2, taux); @@ -161,20 +158,6 @@ arithmetic(char op, Node *np1, Node *np2) goto incorrect; } break; - case FLOAT: - switch (t2) { - case FLOAT: - if (tp1 != tp2) - floatconv(&np1, &np2); - tp1 = np1->type; - break; - case INT: - np2 = castcode(np2, np1->type); - break; - default: - goto incorrect; - } - break; case ARY: np1 = addr2ptr(np1); tp1 = np1->type; @@ -222,32 +205,16 @@ compare(char op, Node *np1, Node *np2) GETBTYPE(np2, tp2, t2); switch (t1) { - case INT: + case INT: case FLOAT: switch (t2) { - case INT: + case INT: case FLOAT: if (tp1 != tp2) - intconv(&np1, &np2); - break; - case FLOAT: - np1 = castcode(np1, tp2); + typeconv(&np1, &np2); break; default: goto incompatibles; } break; - case FLOAT: - switch (t2) { - case INT: - np2 = castcode(np2, tp1); - break; - case FLOAT: - if (tp1 != tp2) - floatconv(&np1, &np2); - break; - defualt: - goto incompatibles; - } - break; case ARY: case FTN: np1 = addr2ptr(np1); tp1 = UNQUAL(np1->type); diff --git a/types.c b/types.c @@ -86,17 +86,20 @@ Type *floattype = &(Type) { .op = FLOAT, .letter = 'F', - .defined = 1 + .defined = 1, + .u.size = 10 }, *doubletype = &(Type) { .op = FLOAT, .letter = 'D', - .defined = 1 + .defined = 1, + .u.size = 11 }, *ldoubletype = &(Type) { .op = FLOAT, .letter = 'H', - .defined = 1 + .defined = 1, + .u.size = 12 }; Type *