shithub: scc

Download patch

ref: 750ed60a7ec3af649c9cfa61f73077ed43b5e33d
parent: c46dede9b17af6465d19865743fd289c81147f54
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Sep 17 05:42:23 EDT 2014

Remove hardcoded HL in 2 byte additions

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

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -87,6 +87,7 @@
 #define ONE       '!'
 #define OOR       'o'
 #define OAND      'y'
+#define OCAST     'c'
 #define ONEG      '_'
 #define OCPL      '~'
 #define OCOMMA    ','
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -252,7 +252,7 @@
 				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:
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -292,7 +292,33 @@
 	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,