shithub: scc

Download patch

ref: 71fbf8ad9e06c29514a12e8840e59d3f50e33b4c
parent: d0a90a5aa668cfab6cc1a3e2ad02a0d61d349898
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Mar 9 04:15:28 EST 2017

[cc2-qbe] Remove int opeartions in float operands

Bitwise operations and modulo operations are defined only for
integers, and define them for floats is an error.

--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -73,10 +73,7 @@
 	ASADDS,
 	ASSUBS,
 	ASMULS,
-	ASMODS,
 	ASDIVS,
-	ASSHLS,
-	ASSHRS,
 	ASLTS,
 	ASGTS,
 	ASLES,
@@ -83,18 +80,11 @@
 	ASGES,
 	ASEQS,
 	ASNES,
-	ASBANDS,
-	ASBORS,
-	ASBXORS,
-	ASCPLS,
 
 	ASADDD,
 	ASSUBD,
 	ASMULD,
-	ASMODD,
 	ASDIVD,
-	ASSHLD,
-	ASSHRD,
 	ASLTD,
 	ASGTD,
 	ASLED,
@@ -101,10 +91,6 @@
 	ASGED,
 	ASEQD,
 	ASNED,
-	ASBANDD,
-	ASBORD,
-	ASBXORD,
-	ASCPLD,
 
 	ASEXTBW,
 	ASUEXTBW,
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -58,10 +58,7 @@
 	[OADD] = ASADDS,
 	[OSUB] = ASSUBS,
 	[OMUL] = ASMULS,
-	[OMOD] = ASMODS,
 	[ODIV] = ASDIVS,
-	[OSHL] = ASSHLS,
-	[OSHR] = ASSHRS,
 	[OLT] = ASLTS,
 	[OGT] = ASGTS,
 	[OLE] = ASLES,
@@ -68,19 +65,12 @@
 	[OGE] = ASGES,
 	[OEQ] = ASEQS,
 	[ONE] = ASNES,
-	[OBAND] = ASBANDS,
-	[OBOR] = ASBORS,
-	[OBXOR] = ASBXORS,
-	[OCPL] = ASCPLS
 };
 static char opasmd[] = {
 	[OADD] = ASADDD,
 	[OSUB] = ASSUBD,
 	[OMUL] = ASMULD,
-	[OMOD] = ASMODD,
 	[ODIV] = ASDIVD,
-	[OSHL] = ASSHLD,
-	[OSHR] = ASSHRD,
 	[OLT] = ASLTD,
 	[OGT] = ASGTD,
 	[OLE] = ASLED,
@@ -87,10 +77,6 @@
 	[OGE] = ASGED,
 	[OEQ] = ASEQD,
 	[ONE] = ASNED,
-	[OBAND] = ASBANDD,
-	[OBOR] = ASBORD,
-	[OBXOR] = ASBXORD,
-	[OCPL] = ASCPLD
 };
 
 extern Type int32type, uint32type, ptrtype;
@@ -515,8 +501,9 @@
 
 		setlabel(phi->u.sym);
 		return ret;
-        case OSHR:
         case OMOD:
+        case OSHR:
+		assert(tp->flags & INTF);
         case ODIV:
         case OLT:
         case OGT:
@@ -528,13 +515,14 @@
                  */
                 off = (tp->flags & SIGNF) == 0;
                 goto binary;
-        case OADD:
-        case OSUB:
-        case OMUL:
         case OSHL:
         case OBAND:
         case OBOR:
         case OBXOR:
+		assert(tp->flags & INTF);
+        case OADD:
+        case OSUB:
+        case OMUL:
         case OEQ:
         case ONE:
                 off = 0;
@@ -708,6 +696,7 @@
 		np->address = 11;
 		break;
 	case OCPL:
+		assert(np->type.flags & INTF);
 		np->op = OBXOR;
 		rp = constnode(NULL, ~(TUINT) 0, &np->type);
 		goto binary;