shithub: scc

Download patch

ref: 25ee0a4512e705ff8017b87c8fc6ae6dc94732ce
parent: 8ab588d0ba2eaa191b6b93fdb4053db29fdcf8fa
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Feb 16 13:32:56 EST 2015

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.

--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -17,7 +17,7 @@
 	char type;
 	union {
 		struct {
-			Type *type;
+			Type type;
 			char sclass;
 			short off;
 		} v;
@@ -35,7 +35,7 @@
 struct node {
 	char op;
 	char subop;
-	Type *type;
+	Type type;
 	uint8_t complex;
 	uint8_t addable;
 	union {
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -21,7 +21,7 @@
 	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 @@
 static void
 move(Node *np)
 {
-	Type *tp = np->type;
+	Type *tp = &np->type;
 	Symbol *sym;
 	char reg;
 
@@ -126,7 +126,7 @@
 
 	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 @@
 		}
 		break;
 	case OASSIG:
-		switch (np->type->size) {
+		switch (np->type.size) {
 		case 1:
 			switch (lp->op) {
 			case AUTO:
--- a/cc2/optm.c
+++ b/cc2/optm.c
@@ -18,16 +18,16 @@
 	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 @@
 Node *
 optimize(Node *np)
 {
-	np = optcasts(np, np->type);
+	np = optcasts(np, &np->type);
 	return np;
 }
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -93,7 +93,7 @@
 		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 @@
 	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 @@
 
 	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 @@
 
 	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 @@
 
 	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 @@
 	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 @@
 	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 @@
 
 	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 @@
 		break;
 	}
 
-	if (sym->u.v.type != NULL)
+	if (sym->u.v.type.size == 0)
 		return;
 
 	if (curfun)
@@ -477,7 +477,7 @@
 {
 	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
@@ -484,7 +484,7 @@
 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;
 }