scc

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

commit 750ed60a7ec3af649c9cfa61f73077ed43b5e33d
parent c46dede9b17af6465d19865743fd289c81147f54
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 17 Sep 2014 09:42:23 +0200

Remove hardcoded HL in 2 byte additions

The destination maybe can be IY, so it is better use the register
of the left operand.

Diffstat:
Mcc2/cc2.h | 1+
Mcc2/cgen.c | 2+-
Mcc2/parser.c | 26++++++++++++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -87,6 +87,7 @@ enum nerrors { #define ONE '!' #define OOR 'o' #define OAND 'y' +#define OCAST 'c' #define ONEG '_' #define OCPL '~' #define OCOMMA ',' diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -252,7 +252,7 @@ cgen(Node *np) emit(LD, H, upper(lp->u.reg)); emit(LD, L, lower(lp->u.reg)); } - emit(ADD, HL, rp->u.reg); + emit(ADD, lp->u.reg, rp->u.reg); break; case 4: case 8: diff --git a/cc2/parser.c b/cc2/parser.c @@ -292,7 +292,33 @@ assignment(char *token) push(np); } +static void +cast(char *token) +{ + Node *np = newnode(); + + np->right = NULL; + np->left = pop(); + np->op = OCAST; + np->type = gettype(token+1); + push(np); +} + static void (*optbl[])(char *) = { + [L_INT8] = cast, + [L_INT16] = cast, + [L_INT32] = cast, + [L_INT64] = cast, + [L_UINT8] = cast, + [L_UINT16] = cast, + [L_UINT32] = cast, + [L_UINT64] = cast, + [L_BOOL] = cast, + [L_FLOAT] = cast, + [L_DOUBLE] = cast, + [L_LDOUBLE] = cast, + [L_POINTER] = cast, + [L_VOID] = cast, ['+'] = operator, ['%'] = operator, ['-'] = operator,