[hackers] [scc] [cc1] Add end of switch label to end of switch op || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 10 May 2016 19:34:45 +0200 (CEST)

commit 98effae319f860ea2684b5a0709d2da923145f38
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Mon May 9 17:41:24 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Mon May 9 17:44:38 2016 +0200

    [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.

diff --git a/cc1/code.c b/cc1/code.c
index 5e54a4b..fa50a7f 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -61,7 +61,7 @@ char *optxt[] = {
         [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",
_AT_@ -129,7 +129,7 @@ void (*opcode[])(unsigned, void *) = {
         [ORET] = emittext,
         [ODECL] = emitdcl,
         [OBSWITCH] = emittext,
- [OESWITCH] = emittext,
+ [OESWITCH] = emitsymid,
         [OPAR] = emitbin,
         [OCALL] = emitbin,
         [OINIT] = emitinit
diff --git a/cc1/stmt.c b/cc1/stmt.c
index 71f11bb..7a1b710 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
_AT_@ -223,7 +223,7 @@ Swtch(Symbol *obr, Symbol *lcont, Switch *osw)
         emit(OBSWITCH, NULL);
         emit(OEXPR, cond);
         stmt(lbreak, lcont, &sw);
- emit(OESWITCH, NULL);
+ emit(OESWITCH, lbreak);
         emit(OLABEL, lbreak);
 }
 
diff --git a/cc1/tests/test012.c b/cc1/tests/test012.c
index 3108c85..f8a622f 100644
--- a/cc1/tests/test012.c
+++ b/cc1/tests/test012.c
_AT_@ -12,7 +12,7 @@ A3 I "x
         s A3
         v L5 #I0
 L5
- k
+ k L4
 L4
         s A3
         v L7 #I0
_AT_@ -24,9 +24,9 @@ L9
         f L11
 L11
         h #I1
- k
+ k L8
 L8
- k
+ k L6
 L6
         h #I2
 L10
_AT_@ -34,7 +34,7 @@ L10
         v L13 #I1
 L13
         h #I3
- k
+ k L12
 L12
         s A3
         A3 #I2 :I
_AT_@ -42,7 +42,7 @@ L15
         v L16 #I1
 L16
         h #I4
- k
+ k L14
 L14
         s A3
         v L18 #I0
_AT_@ -54,7 +54,7 @@ L19
         f L20
 L20
         h #I1
- k
+ k L17
 L17
 }
 */
diff --git a/cc1/tests/test036.c b/cc1/tests/test036.c
index 712de61..dfe8268 100644
--- a/cc1/tests/test036.c
+++ b/cc1/tests/test036.c
_AT_@ -43,7 +43,7 @@ L18
         y L10 R7 #I1 :-I #I0 >I
         b
 L11
- k
+ k L8
 L8
 }
 */
Received on Tue May 10 2016 - 19:34:45 CEST

This archive was generated by hypermail 2.3.0 : Tue May 10 2016 - 19:36:13 CEST