]> Cypherpunks repositories - gostls13.git/commitdiff
start of better addressing of
authorKen Thompson <ken@golang.org>
Wed, 20 Jan 2010 03:59:57 +0000 (19:59 -0800)
committerKen Thompson <ken@golang.org>
Wed, 20 Jan 2010 03:59:57 +0000 (19:59 -0800)
arrays/slices in structures

R=rsc
CC=golang-dev
https://golang.org/cl/190077

src/cmd/6g/gsubr.c

index 142d3c245d0a8a02637c1687e188cd43f0754380..4d17bb8a24ed4966411dfcc00b811030c7c8500a 100644 (file)
@@ -1709,11 +1709,6 @@ sudoaddable(int as, Node *n, Addr *a)
                goto odot;
 
        case OINDEX:
-               cleani += 2;
-               reg = &clean[cleani-1];
-               reg1 = &clean[cleani-2];
-               reg->op = OEMPTY;
-               reg1->op = OEMPTY;
                goto oindex;
        }
        return 0;
@@ -1782,7 +1777,7 @@ oindex:
        l = n->left;
        r = n->right;
        if(l->ullman >= UINF && r->ullman >= UINF)
-               goto no;
+               return 0;
 
        // set o to type of array
        o = 0;
@@ -1799,7 +1794,7 @@ oindex:
 
        switch(w) {
        default:
-               goto no;
+               return 0;
        case 1:
        case 2:
        case 4:
@@ -1807,6 +1802,15 @@ oindex:
                break;
        }
 
+//     if(sudoaddable(as, l, a))
+//             goto oindex_sudo;
+
+       cleani += 2;
+       reg = &clean[cleani-1];
+       reg1 = &clean[cleani-2];
+       reg->op = OEMPTY;
+       reg1->op = OEMPTY;
+
        // load the array (reg)
        if(l->ullman > r->ullman) {
                regalloc(reg, types[tptr], N);
@@ -1876,12 +1880,21 @@ oindex_const:
        // can check statically and
        // can multiply by width statically
 
+       if((o & ODynam) == 0)
+       if(sudoaddable(as, l, a))
+               goto oindex_const_sudo;
+
+       cleani += 2;
+       reg = &clean[cleani-1];
+       reg1 = &clean[cleani-2];
+       reg->op = OEMPTY;
+       reg1->op = OEMPTY;
+
        regalloc(reg, types[tptr], N);
        agen(l, reg);
 
        v = mpgetfix(r->val.u.xval);
        if(o & ODynam) {
-
                if(!debug['B'] && !n->etype) {
                        n1 = *reg;
                        n1.op = OINDREG;
@@ -1918,6 +1931,17 @@ oindex_const:
        naddr(&n2, a, 1);
        goto yes;
 
+oindex_const_sudo:
+       v = mpgetfix(r->val.u.xval);
+       if(v < 0) {
+               yyerror("out of bounds on array");
+       } else
+       if(v >= l->type->bound) {
+               yyerror("out of bounds on array");
+       }
+       a->offset += v*w;
+       goto yes;
+
 yes:
        return 1;