ref: 1fb38e3bfef9e594f46b257c63ed0acb6c9a1cba
parent: 05bdb414f7c5f42f335679f0c3461c391e0ed20c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Mar 17 10:03:10 EDT 2015
Fix generation of immediate and register nodes These nodes were broken after the last commits, and this commit fix them although it introduces some new problems (for example a memory leak), but they will be fixed later.
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -56,6 +56,8 @@
bool public : 1;
bool extrn : 1;
union {
+ /* TODO: Admit inmediate of other type */
+ TINT imm;
struct {
Type type;
char sclass;
@@ -62,10 +64,6 @@
short off;
} v;
struct {
- /* TODO: Admit inmediate of other type */
- TINT imm;
- } i;
- struct {
short addr;
} l;
struct {
@@ -123,9 +121,6 @@
A = 1, B, C, D, E, H, L, IYL, IYH, NREGS,
SP = NREGS, AF, HL, DE, BC, IX, IY
};
-
-extern Type Funct, l_int8, l_int16, l_int32, l_int64,
- l_uint8, l_uint16, l_uint32, l_uint64;
extern Symbol *curfun;
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -159,6 +159,7 @@
abort();
}
np->op = REG;
+ np->reg = reg;
}
static void
@@ -353,7 +354,6 @@
cgen(p, np);
cgen(q, np);
}
-
(*opnodes[np->op])(np);
}
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -94,7 +94,7 @@
addr->u.reg = np->reg;
break;
case CONST:
- /* TODO: Take the immediate from some place */
+ addr->u.i = np->sym->u.imm;
break;
case AUTO:
addr->u.i = np->sym->u.v.off;
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -234,8 +234,11 @@
np->op = CONST;
np->type = l_int16;
- /* TODO: assign the integer to something */
+ /* FIX: memory leak */
+ np->sym = xmalloc(sizeof(Symbol *));
+ np->sym->u.imm = i;
np->left = np->right = NULL;
+ return np;
}
static void