shithub: scc

Download patch

ref: 7b78b22025c26725219a68905ab405f007c6b30e
parent: 7c1c6de3c313bcc6d9b460735e37961426c28783
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon May 9 13:41:24 EDT 2016

[cc1] Add end of switch label to end of switch op

We need the end of switch because if we convert the switch into
a switch table in some point we need to check that any of the
cases matched against the expression and  then we have to jump out
of the switch statement.

--- a/cc1/code.c
+++ b/cc1/code.c
@@ -61,7 +61,7 @@
 	[OLABEL] = "L%d\n",
 	[ODEFAULT] = "\tf\tL%d\n",
 	[OBSWITCH] = "\ts",
-	[OESWITCH] = "\tk\n",
+	[OESWITCH] = "\tk\tL%d\n",
 	[OCASE] = "\tv\tL%d",
 	[OJUMP] = "\tj\tL%d\n",
 	[OBRANCH] = "\ty\tL%d",
@@ -129,7 +129,7 @@
 	[ORET] = emittext,
 	[ODECL] = emitdcl,
 	[OBSWITCH] = emittext,
-	[OESWITCH] = emittext,
+	[OESWITCH] = emitsymid,
 	[OPAR] = emitbin,
 	[OCALL] = emitbin,
 	[OINIT] = emitinit
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -223,7 +223,7 @@
 	emit(OBSWITCH, NULL);
 	emit(OEXPR, cond);
 	stmt(lbreak, lcont, &sw);
-	emit(OESWITCH, NULL);
+	emit(OESWITCH, lbreak);
 	emit(OLABEL, lbreak);
 }
 
--- a/cc1/tests/test012.c
+++ b/cc1/tests/test012.c
@@ -12,7 +12,7 @@
 	s	A3
 	v	L5	#I0
 L5
-	k
+	k	L4
 L4
 	s	A3
 	v	L7	#I0
@@ -24,9 +24,9 @@
 	f	L11
 L11
 	h	#I1
-	k
+	k	L8
 L8
-	k
+	k	L6
 L6
 	h	#I2
 L10
@@ -34,7 +34,7 @@
 	v	L13	#I1
 L13
 	h	#I3
-	k
+	k	L12
 L12
 	s	A3
 	A3	#I2	:I
@@ -42,7 +42,7 @@
 	v	L16	#I1
 L16
 	h	#I4
-	k
+	k	L14
 L14
 	s	A3
 	v	L18	#I0
@@ -54,7 +54,7 @@
 	f	L20
 L20
 	h	#I1
-	k
+	k	L17
 L17
 }
 */
--- a/cc1/tests/test036.c
+++ b/cc1/tests/test036.c
@@ -43,7 +43,7 @@
 	y	L10	R7	#I1	:-I	#I0	>I
 	b
 L11
-	k
+	k	L8
 L8
 }
 */