diff --git a/src/cmd/5c/gc.h b/src/cmd/5c/gc.h index 8777ec6772..20652682b1 100644 --- a/src/cmd/5c/gc.h +++ b/src/cmd/5c/gc.h @@ -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*); diff --git a/src/cmd/5c/swt.c b/src/cmd/5c/swt.c index 32032532f2..7268f9af26 100644 --- a/src/cmd/5c/swt.c +++ b/src/cmd/5c/swt.c @@ -28,11 +28,30 @@ // 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: diff --git a/src/cmd/6c/gc.h b/src/cmd/6c/gc.h index ed2338731f..b0081abb57 100644 --- a/src/cmd/6c/gc.h +++ b/src/cmd/6c/gc.h @@ -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*); diff --git a/src/cmd/6c/swt.c b/src/cmd/6c/swt.c index 3de86306d3..f16d0f78a2 100644 --- a/src/cmd/6c/swt.c +++ b/src/cmd/6c/swt.c @@ -32,6 +32,21 @@ 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 diff --git a/src/cmd/8c/gc.h b/src/cmd/8c/gc.h index 60ead6b034..4a57f5d3cb 100644 --- a/src/cmd/8c/gc.h +++ b/src/cmd/8c/gc.h @@ -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*); diff --git a/src/cmd/8c/swt.c b/src/cmd/8c/swt.c index 006bfdfe23..f1ca4c25fa 100644 --- a/src/cmd/8c/swt.c +++ b/src/cmd/8c/swt.c @@ -32,6 +32,26 @@ 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 diff --git a/src/cmd/cc/pgen.c b/src/cmd/cc/pgen.c index e652e2349d..3a686102f3 100644 --- a/src/cmd/cc/pgen.c +++ b/src/cmd/cc/pgen.c @@ -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;