summaryrefslogtreecommitdiff
path: root/utils/vc/swt.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/vc/swt.c')
-rw-r--r--utils/vc/swt.c138
1 files changed, 12 insertions, 126 deletions
diff --git a/utils/vc/swt.c b/utils/vc/swt.c
index d5c72dc1..cdc58e1b 100644
--- a/utils/vc/swt.c
+++ b/utils/vc/swt.c
@@ -1,62 +1,17 @@
#include "gc.h"
-int
-swcmp(const void *a1, const void *a2)
-{
- C1 *p1, *p2;
-
- p1 = (C1*)a1;
- p2 = (C1*)a2;
- if(p1->val < p2->val)
- return -1;
- return p1->val > p2->val;
-}
-
void
-doswit(Node *n)
+swit1(C1 *q, int nc, long def, Node *n)
{
- Case *c;
- C1 *q, *iq;
- long def, nc, i;
Node tn;
-
- def = 0;
- nc = 0;
- for(c = cases; c->link != C; c = c->link) {
- if(c->def) {
- if(def)
- diag(n, "more than one default in switch");
- def = c->label;
- continue;
- }
- nc++;
- }
-
- iq = alloc(nc*sizeof(C1));
- q = iq;
- for(c = cases; c->link != C; c = c->link) {
- if(c->def)
- continue;
- q->label = c->label;
- q->val = c->val;
- q++;
- }
- qsort(iq, nc, sizeof(C1), swcmp);
- if(debug['W'])
- for(i=0; i<nc; i++)
- print("case %2ld: = %.8lux\n", i, iq[i].val);
- if(def == 0)
- def = breakpc;
- for(i=0; i<nc-1; i++)
- if(iq[i].val == iq[i+1].val)
- diag(n, "duplicate cases in switch %ld", iq[i].val);
+
regalloc(&tn, &regnode, Z);
- swit1(iq, nc, def, n, &tn);
+ swit2(q, nc, def, n, &tn);
regfree(&tn);
}
void
-swit1(C1 *q, int nc, long def, Node *n, Node *tn)
+swit2(C1 *q, int nc, long def, Node *n, Node *tn)
{
C1 *r;
int i;
@@ -84,22 +39,12 @@ swit1(C1 *q, int nc, long def, Node *n, Node *tn)
sp = p;
gopcode(OEQ, n, tn, Z);
patch(p, r->label);
- swit1(q, i, def, n, tn);
+ swit2(q, i, def, n, tn);
if(debug['W'])
print("case < %.8lux\n", r->val);
patch(sp, pc);
- swit1(r+1, nc-i-1, def, n, tn);
-}
-
-void
-casf(void)
-{
- Case *c;
-
- c = alloc(sizeof(*c));
- c->link = cases;
- cases = c;
+ swit2(r+1, nc-i-1, def, n, tn);
}
void
@@ -197,31 +142,6 @@ outstring(char *s, long n)
return r;
}
-long
-outlstring(ushort *s, long n)
-{
- char buf[2];
- int c;
- long r;
-
- while(nstring & 1)
- outstring("", 1);
- r = nstring;
- while(n > 0) {
- c = *s++;
- if(align(0, types[TCHAR], Aarg1)) {
- buf[0] = c>>8;
- buf[1] = c;
- } else {
- buf[0] = c;
- buf[1] = c>>8;
- }
- outstring(buf, 2);
- n -= sizeof(ushort);
- }
- return r;
-}
-
int
mulcon(Node *n, Node *nn)
{
@@ -314,16 +234,6 @@ loop:
}
void
-nullwarn(Node *l, Node *r)
-{
- warn(Z, "result of operation not used");
- if(l != Z)
- cgen(l, Z);
- if(r != Z)
- cgen(r, Z);
-}
-
-void
sextern(Sym *s, Node *a, long o, long w)
{
long e, lw;
@@ -615,35 +525,6 @@ zaddr(char *bp, Adr *a, int s)
return bp;
}
-void
-ieeedtod(Ieee *ieee, double native)
-{
- double fr, ho, f;
- int exp;
-
- if(native < 0) {
- ieeedtod(ieee, -native);
- ieee->h |= 0x80000000L;
- return;
- }
- if(native == 0) {
- ieee->l = 0;
- ieee->h = 0;
- return;
- }
- fr = frexp(native, &exp);
- f = 2097152L; /* shouldnt use fp constants here */
- fr = modf(fr*f, &ho);
- ieee->h = ho;
- ieee->h &= 0xfffffL;
- ieee->h |= (exp+1022L) << 20;
- f = 65536L;
- fr = modf(fr*f, &ho);
- ieee->l = ho;
- ieee->l <<= 16;
- ieee->l |= (long)(fr*f);
-}
-
long
align(long i, Type *t, int op)
{
@@ -660,6 +541,8 @@ align(long i, Type *t, int op)
case Asu2: /* padding at end of a struct */
w = SZ_LONG;
+ if(packflg)
+ w = packflg;
break;
case Ael1: /* initial allign of struct element */
@@ -668,6 +551,8 @@ align(long i, Type *t, int op)
w = ewidth[v->etype];
if(w <= 0 || w >= SZ_LONG)
w = SZ_LONG;
+ if(packflg)
+ w = packflg;
break;
case Ael2: /* width of a struct element */
@@ -687,7 +572,8 @@ align(long i, Type *t, int op)
w = SZ_LONG;
break;
}
- o += SZ_LONG - w; /* big endian adjustment */
+ if(thechar == 'v')
+ o += SZ_LONG - w; /* big endian adjustment */
w = 1;
break;