]> Cypherpunks repositories - gostls13.git/commitdiff
5c, 6c, 8c: support 64-bit switch value
authorAnthony Martin <ality@pbrane.org>
Wed, 14 Dec 2011 22:30:40 +0000 (17:30 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 14 Dec 2011 22:30:40 +0000 (17:30 -0500)
For real this time. :-)

R=rsc, ken
CC=golang-dev
https://golang.org/cl/5486061

src/cmd/5c/gc.h
src/cmd/5c/swt.c
src/cmd/6c/gc.h
src/cmd/6c/swt.c
src/cmd/8c/gc.h
src/cmd/8c/swt.c
src/cmd/cc/pgen.c

index 8777ec6772b741382f3631766fa7d75c3914acdf..20652682b148f4749d52efd3b0ff4be7af109ae3 100644 (file)
@@ -304,6 +304,7 @@ void        gpseudo(int, Sym*, Node*);
 int    swcmp(const void*, const void*);
 void   doswit(Node*);
 void   swit1(C1*, int, int32, Node*);
+void   swit2(C1*, int, int32, Node*);
 void   newcase(void);
 void   bitload(Node*, Node*, Node*, Node*, Node*);
 void   bitstore(Node*, Node*, Node*, Node*, Node*);
index 32032532f20f6e30902cba75ac3568a78906a41a..7268f9af26726ddf5ccaaccfec69c61af0e31eca 100644 (file)
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-
 #include "gc.h"
 
 void
 swit1(C1 *q, int nc, int32 def, Node *n)
+{
+       Node nreg;
+
+       if(typev[n->type->etype]) {
+               regsalloc(&nreg, n);
+               nreg.type = types[TVLONG];
+               cgen(n, &nreg);
+               swit2(q, nc, def, &nreg);
+               return;
+       }
+
+       regalloc(&nreg, n, Z);
+       nreg.type = types[TLONG];
+       cgen(n, &nreg);
+       swit2(q, nc, def, &nreg);
+       regfree(&nreg);
+}
+
+void
+swit2(C1 *q, int nc, int32 def, Node *n)
 {
        C1 *r;
        int i;
@@ -65,12 +84,12 @@ swit1(C1 *q, int nc, int32 def, Node *n)
        sp = p;
        gopcode(OEQ, nodconst(r->val), n, Z);   /* just gen the B.EQ */
        patch(p, r->label);
-       swit1(q, i, def, n);
+       swit2(q, i, def, n);
 
        if(debug['W'])
                print("case < %.8ux\n", r->val);
        patch(sp, pc);
-       swit1(r+1, nc-i-1, def, n);
+       swit2(r+1, nc-i-1, def, n);
        return;
 
 direct:
index ed2338731f06703de8271b599a8716e920f90be3..b0081abb57c56de914a7045e9f791d6be95b6340 100644 (file)
@@ -299,6 +299,7 @@ void        gpseudo(int, Sym*, Node*);
 int    swcmp(const void*, const void*);
 void   doswit(Node*);
 void   swit1(C1*, int, int32, Node*);
+void   swit2(C1*, int, int32, Node*);
 void   newcase(void);
 void   bitload(Node*, Node*, Node*, Node*, Node*);
 void   bitstore(Node*, Node*, Node*, Node*, Node*);
index 3de86306d3b57acd1deacbade55f8052cef55c46..f16d0f78a215533410a834a55bae468648955800 100644 (file)
 
 void
 swit1(C1 *q, int nc, int32 def, Node *n)
+{
+       Node nreg;
+
+       regalloc(&nreg, n, Z);
+       if(typev[n->type->etype])
+               nreg.type = types[TVLONG];
+       else
+               nreg.type = types[TLONG];
+       cgen(n, &nreg);
+       swit2(q, nc, def, &nreg);
+       regfree(&nreg);
+}
+
+void
+swit2(C1 *q, int nc, int32 def, Node *n)
 {
        C1 *r;
        int i;
@@ -58,12 +73,12 @@ swit1(C1 *q, int nc, int32 def, Node *n)
        gbranch(OGOTO);
        p->as = AJEQ;
        patch(p, r->label);
-       swit1(q, i, def, n);
+       swit2(q, i, def, n);
 
        if(debug['W'])
                print("case < %.8llux\n", r->val);
        patch(sp, pc);
-       swit1(r+1, nc-i-1, def, n);
+       swit2(r+1, nc-i-1, def, n);
 }
 
 void
index 60ead6b034e829480db12b036818b921153aadf5..4a57f5d3cbb2a578287b150e3d124ebf2af6ba4e 100644 (file)
@@ -304,6 +304,7 @@ void        gpseudo(int, Sym*, Node*);
 int    swcmp(const void*, const void*);
 void   doswit(Node*);
 void   swit1(C1*, int, int32, Node*);
+void   swit2(C1*, int, int32, Node*);
 void   newcase(void);
 void   bitload(Node*, Node*, Node*, Node*, Node*);
 void   bitstore(Node*, Node*, Node*, Node*, Node*);
index 006bfdfe23fafab11745dce5392a4b0fb8b3e5dd..f1ca4c25fa8b59c69a278de5509f9a9985c94ac8 100644 (file)
 
 void
 swit1(C1 *q, int nc, int32 def, Node *n)
+{
+       Node nreg;
+
+       if(typev[n->type->etype]) {
+               regsalloc(&nreg, n);
+               nreg.type = types[TVLONG];
+               cgen(n, &nreg);
+               swit2(q, nc, def, &nreg);
+               return;
+       }
+
+       regalloc(&nreg, n, Z);
+       nreg.type = types[TLONG];
+       cgen(n, &nreg);
+       swit2(q, nc, def, &nreg);
+       regfree(&nreg);
+}
+
+void
+swit2(C1 *q, int nc, int32 def, Node *n)
 {
        C1 *r;
        int i;
@@ -58,12 +78,12 @@ swit1(C1 *q, int nc, int32 def, Node *n)
        gbranch(OGOTO);
        p->as = AJEQ;
        patch(p, r->label);
-       swit1(q, i, def, n);
+       swit2(q, i, def, n);
 
        if(debug['W'])
                print("case < %.8ux\n", r->val);
        patch(sp, pc);
-       swit1(r+1, nc-i-1, def, n);
+       swit2(r+1, nc-i-1, def, n);
 }
 
 void
index e652e2349d6841021702d32bc6291104ba5191e4..3a686102f37569c4cf3d808c3cd4e9115991bb65 100644 (file)
@@ -293,7 +293,7 @@ loop:
                complex(l);
                if(l->type == T)
                        break;
-               if(!typeword[l->type->etype] || l->type->etype == TIND) {
+               if(!typechlvp[l->type->etype] || l->type->etype == TIND) {
                        diag(n, "switch expression must be integer");
                        break;
                }
@@ -320,15 +320,7 @@ loop:
                }
 
                patch(sp, pc);
-               regalloc(&nod, l, Z);
-               /* always signed */
-               if(typev[l->type->etype])
-                       nod.type = types[TVLONG];
-               else
-                       nod.type = types[TLONG];
-               cgen(l, &nod);
-               doswit(&nod);
-               regfree(&nod);
+               doswit(l);
                patch(spb, pc);
 
                cases = cn;