shithub: scc

Download patch

ref: 5215b34485aa15d4dccfe7f2115c3d6701fdcf5c
parent: d7890765b7b847f8856c3da07ead0de966b69b80
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Apr 16 03:22:45 EDT 2014

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.

--- a/expr.c
+++ b/expr.c
@@ -38,7 +38,7 @@
 }
 
 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 @@
 		*p2 = castcode(np2, new2);
 }
 
-static void
-floatconv(Node **np1, Node **np2)
-{
-}
-
 static Node *
 bitlogic(char op, Node *np1, Node *np2)
 {
@@ -83,7 +78,7 @@
 	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 @@
 		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 @@
 	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 @@
 			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,29 +205,13 @@
 	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);
 			break;
-		case FLOAT:
-			np1 = castcode(np1, tp2);
-			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;
--- a/types.c
+++ b/types.c
@@ -86,17 +86,20 @@
 	*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 *