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
@@ -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",
@@ -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
@@ -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
@@ -12,7 +12,7 @@ A3    I       "x
        s       A3
        v       L5      #I0
 L5
-       k
+       k       L4
 L4
        s       A3
        v       L7      #I0
@@ -24,9 +24,9 @@ L9
        f       L11
 L11
        h       #I1
-       k
+       k       L8
 L8
-       k
+       k       L6
 L6
        h       #I2
 L10
@@ -34,7 +34,7 @@ L10
        v       L13     #I1
 L13
        h       #I3
-       k
+       k       L12
 L12
        s       A3
        A3      #I2     :I
@@ -42,7 +42,7 @@ L15
        v       L16     #I1
 L16
        h       #I4
-       k
+       k       L14
 L14
        s       A3
        v       L18     #I0
@@ -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
@@ -43,7 +43,7 @@ L18
        y       L10     R7      #I1     :-I     #I0     >I
        b
 L11
-       k
+       k       L8
 L8
 }
 */

Reply via email to