]> Cypherpunks repositories - gostls13.git/commitdiff
gc: introduce temp = nod+tempname
authorRuss Cox <rsc@golang.org>
Fri, 2 Sep 2011 19:35:16 +0000 (15:35 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 2 Sep 2011 19:35:16 +0000 (15:35 -0400)
R=ken2
CC=golang-dev
https://golang.org/cl/4967052

src/cmd/gc/gen.c
src/cmd/gc/go.h
src/cmd/gc/range.c
src/cmd/gc/select.c
src/cmd/gc/sinit.c
src/cmd/gc/subr.c
src/cmd/gc/swt.c
src/cmd/gc/walk.c

index d585c451a282726f189e159080e956f1f0f799f0..fa084235030296cdc16ca052bcf91b58e157bcb0 100644 (file)
@@ -877,3 +877,13 @@ tempname(Node *nn, Type *t)
 
        *nn = *n;
 }
+
+Node*
+temp(Type *t)
+{
+       Node *n;
+       
+       n = nod(OXXX, N, N);
+       tempname(n, t);
+       return n;
+}
index 42f2140255b558ba587517c9b984fc37c6089f63..19c3b578418e813cc74acd38c308fa1f24df8654 100644 (file)
@@ -991,6 +991,7 @@ void        gen(Node *n);
 void   genlist(NodeList *l);
 Node*  sysfunc(char *name);
 void   tempname(Node *n, Type *t);
+Node*  temp(Type*);
 
 /*
  *     init.c
index bb22d234c5d2e2bcec9058980bc1eb5661f8ad80..5cbafd895acbea383d20ed6f12800640cd9e4bac 100644 (file)
@@ -123,8 +123,7 @@ walkrange(Node *n)
                // no need to make a potentially expensive copy.
                ha = a;
        } else {
-               ha = nod(OXXX, N, N);
-               tempname(ha, a->type);
+               ha = temp(a->type);
                init = list(init, nod(OAS, ha, a));
        }
 
@@ -133,17 +132,14 @@ walkrange(Node *n)
                fatal("walkrange");
 
        case TARRAY:
-               hv1 = nod(OXXX, N, n);
-               tempname(hv1, types[TINT]);
-               hn = nod(OXXX, N, N);
-               tempname(hn, types[TINT]);
+               hv1 = temp(types[TINT]);
+               hn = temp(types[TINT]);
                hp = nil;
 
                init = list(init, nod(OAS, hv1, N));
                init = list(init, nod(OAS, hn, nod(OLEN, ha, N)));
                if(v2) {
-                       hp = nod(OXXX, N, N);
-                       tempname(hp, ptrto(n->type->type));
+                       hp = temp(ptrto(n->type->type));
                        tmp = nod(OINDEX, ha, nodintconst(0));
                        tmp->etype = 1; // no bounds check
                        init = list(init, nod(OAS, hp, nod(OADDR, tmp, N)));
@@ -168,8 +164,7 @@ walkrange(Node *n)
                th = typ(TARRAY);
                th->type = ptrto(types[TUINT8]);
                th->bound = (sizeof(struct Hiter) + widthptr - 1) / widthptr;
-               hit = nod(OXXX, N, N);
-               tempname(hit, th);
+               hit = temp(th);
 
                fn = syslook("mapiterinit", 1);
                argtype(fn, t->down);
@@ -200,10 +195,8 @@ walkrange(Node *n)
                break;
 
        case TCHAN:
-               hv1 = nod(OXXX, N, n);
-               tempname(hv1, t->type);
-               hb = nod(OXXX, N, N);
-               tempname(hb, types[TBOOL]);
+               hv1 = temp(t->type);
+               hb = temp(types[TBOOL]);
 
                n->ntest = nod(ONE, hb, nodbool(0));
                a = nod(OAS2RECV, N, N);
@@ -215,18 +208,15 @@ walkrange(Node *n)
                break;
 
        case TSTRING:
-               ohv1 = nod(OXXX, N, N);
-               tempname(ohv1, types[TINT]);
+               ohv1 = temp(types[TINT]);
 
-               hv1 = nod(OXXX, N, N);
-               tempname(hv1, types[TINT]);
+               hv1 = temp(types[TINT]);
                init = list(init, nod(OAS, hv1, N));
 
                if(v2 == N)
                        a = nod(OAS, hv1, mkcall("stringiter", types[TINT], nil, ha, hv1));
                else {
-                       hv2 = nod(OXXX, N, N);
-                       tempname(hv2, types[TINT]);
+                       hv2 = temp(types[TINT]);
                        a = nod(OAS2, N, N);
                        a->list = list(list1(hv1), hv2);
                        fn = syslook("stringiter2", 0);
index cd6741ec8b3c78bec5478cbdf32289291347b314..8ace1d4ee547f9dfd05cd082a577718d828ccf0e 100644 (file)
@@ -194,8 +194,7 @@ walkselect(Node *sel)
                                        n->ntest->etype = 1;  // pointer does not escape
                                        typecheck(&n->ntest, Erv);
                                } else {
-                                       tmp = nod(OXXX, N, N);
-                                       tempname(tmp, types[TBOOL]);
+                                       tmp = temp(types[TBOOL]);
                                        a = nod(OADDR, tmp, N);
                                        a->etype = 1;  // pointer does not escape
                                        typecheck(&a, Erv);
@@ -215,8 +214,7 @@ walkselect(Node *sel)
                                n->left->etype = 1;  // pointer does not escape
                                typecheck(&n->left, Erv);
                        } else {
-                               tmp = nod(OXXX, N, N);
-                               tempname(tmp, ch->type->type);
+                               tmp = temp(ch->type->type);
                                a = nod(OADDR, tmp, N);
                                a->etype = 1;  // pointer does not escape
                                typecheck(&a, Erv);
@@ -287,8 +285,7 @@ walkselect(Node *sel)
 
        // generate sel-struct
        setlineno(sel);
-       var = nod(OXXX, N, N);
-       tempname(var, ptrto(types[TUINT8]));
+       var = temp(ptrto(types[TUINT8]));
        r = nod(OAS, var, mkcall("newselect", var->type, nil, nodintconst(sel->xoffset)));
        typecheck(&r, Etop);
        init = list(init, r);
index d98f4fef29af411d368a3f605761fe2a03b34410..18856cd3ac8458837adcf9d934f43e93904e5a29 100644 (file)
@@ -689,13 +689,11 @@ slicelit(int ctxt, Node *n, Node *var, NodeList **init)
        }
 
        // make new auto *array (3 declare)
-       vauto = nod(OXXX, N, N);
-       tempname(vauto, ptrto(t));
+       vauto = temp(ptrto(t));
 
        // set auto to point at new temp or heap (3 assign)
        if(n->esc == EscNone) {
-               a = nod(OXXX, N, N);
-               tempname(a, t);
+               a = temp(t);
                *init = list(*init, nod(OAS, a, N));  // zero new temp
                a = nod(OADDR, a, N);
        } else {
@@ -859,8 +857,7 @@ ctxt = 0;
                // for i = 0; i < len(vstat); i++ {
                //      map[vstat[i].a] = vstat[i].b
                // }
-               index = nod(OXXX, N, N);
-               tempname(index, types[TINT]);
+               index = temp(types[TINT]);
 
                a = nod(OINDEX, vstat, index);
                a->etype = 1;   // no bounds checking
index 5ebb150212e32e614e5df819fdd7cb24f7a7401d..a33dd2d114564793e08abe221e0f45979f4198bb 100644 (file)
@@ -2788,8 +2788,7 @@ copyexpr(Node *n, Type *t, NodeList **init)
 {
        Node *a, *l;
        
-       l = nod(OXXX, N, N);
-       tempname(l, t);
+       l = temp(t);
        a = nod(OAS, l, n);
        typecheck(&a, Etop);
        walkexpr(&a, init);
index 163cdb84e262b96dcc09227f03645ce4628ef088..0381132d03a0767f267d0e9a01e8587263ad32c3 100644 (file)
@@ -515,8 +515,7 @@ exprswitch(Node *sw)
        exprname = N;
        cas = nil;
        if(arg != Strue && arg != Sfalse) {
-               exprname = nod(OXXX, N, N);
-               tempname(exprname, sw->ntest->type);
+               exprname = temp(sw->ntest->type);
                cas = list1(nod(OAS, exprname, sw->ntest));
                typechecklist(cas, Etop);
        }
@@ -673,20 +672,17 @@ typeswitch(Node *sw)
         * predeclare temporary variables
         * and the boolean var
         */
-       facename = nod(OXXX, N, N);
-       tempname(facename, sw->ntest->right->type);
+       facename = temp(sw->ntest->right->type);
        a = nod(OAS, facename, sw->ntest->right);
        typecheck(&a, Etop);
        cas = list(cas, a);
 
        casebody(sw, facename);
 
-       boolname = nod(OXXX, N, N);
-       tempname(boolname, types[TBOOL]);
+       boolname = temp(types[TBOOL]);
        typecheck(&boolname, Erv);
 
-       hashname = nod(OXXX, N, N);
-       tempname(hashname, types[TUINT32]);
+       hashname = temp(types[TUINT32]);
        typecheck(&hashname, Erv);
 
        t = sw->ntest->right->type;
index 7ca7257179b40c5c400e4edc502e34e50f5a6b11..8a84956a67cddb1206a47c8eaed5738c0614c3ba 100644 (file)
@@ -562,8 +562,7 @@ walkexpr(Node **np, NodeList **init)
                // and map index has an implicit one.
                lpost = nil;
                if(l->op == OINDEXMAP) {
-                       var = nod(OXXX, N, N);
-                       tempname(var, l->type);
+                       var = temp(l->type);
                        n->list->n = var;
                        a = nod(OAS, l, var);
                        typecheck(&a, Etop);
@@ -571,8 +570,7 @@ walkexpr(Node **np, NodeList **init)
                }
                l = n->list->next->n;
                if(l->op == OINDEXMAP) {
-                       var = nod(OXXX, N, N);
-                       tempname(var, l->type);
+                       var = temp(l->type);
                        n->list->next->n = var;
                        a = nod(OAS, l, var);
                        typecheck(&a, Etop);
@@ -975,8 +973,7 @@ walkexpr(Node **np, NodeList **init)
 
        case ONEW:
                if(n->esc == EscNone && n->type->type->width < (1<<16)) {
-                       r = nod(OXXX, N, N);
-                       tempname(r, n->type->type);
+                       r = temp(n->type->type);
                        *init = list(*init, nod(OAS, r, N));  // zero temp
                        r = nod(OADDR, r, N);
                        typecheck(&r, Erv);
@@ -1164,8 +1161,7 @@ walkexpr(Node **np, NodeList **init)
        case OARRAYLIT:
        case OMAPLIT:
        case OSTRUCTLIT:
-               nvar = nod(OXXX, N, N);
-               tempname(nvar, n->type);
+               nvar = temp(n->type);
                anylit(0, n, nvar, init);
                n = nvar;
                goto ret;
@@ -1194,8 +1190,7 @@ makenewvar(Type *t, NodeList **init, Node **nstar)
 {
        Node *nvar, *nas;
 
-       nvar = nod(OXXX, N, N);
-       tempname(nvar, t);
+       nvar = temp(t);
        nas = nod(OAS, nvar, callnew(t->type));
        typecheck(&nas, Etop);
        walkexpr(&nas, init);
@@ -1291,8 +1286,7 @@ ascompatet(int op, NodeList *nl, Type **nr, int fp, NodeList **init)
                // deferred until all the return arguments
                // have been pulled from the output arguments
                if(fncall(l, r->type)) {
-                       tmp = nod(OXXX, N, N);
-                       tempname(tmp, r->type);
+                       tmp = temp(r->type);
                        typecheck(&tmp, Erv);
                        a = nod(OAS, l, tmp);
                        a = convas(a, init);
@@ -1434,8 +1428,7 @@ ascompatte(int op, Node *call, int isddd, Type **nl, NodeList *lr, int fp, NodeL
                // copy into temporaries.
                alist = nil;
                for(l=structfirst(&savel, &r->type); l; l=structnext(&savel)) {
-                       a = nod(OXXX, N, N);
-                       tempname(a, l->type);
+                       a = temp(l->type);
                        alist = list(alist, a);
                }
                a = nod(OAS2, N, N);
@@ -1778,8 +1771,7 @@ reorder1(NodeList *all)
                }
 
                // make assignment of fncall to tempname
-               a = nod(OXXX, N, N);
-               tempname(a, n->right->type);
+               a = temp(n->right->type);
                a = nod(OAS, a, n->right);
                g = list(g, a);
 
@@ -1882,8 +1874,7 @@ reorder3(NodeList *all)
                        if(c2 > c1) {
                                if(vmatch1(n1->left, n2->right)) {
                                        // delay assignment to n1->left
-                                       q = nod(OXXX, N, N);
-                                       tempname(q, n1->right->type);
+                                       q = temp(n1->right->type);
                                        q = nod(OAS, n1->left, q);
                                        n1->left = q->right;
                                        r = list(r, q);
@@ -2146,8 +2137,7 @@ append(Node *n, NodeList **init)
 
        l = nil;
 
-       ns = nod(OXXX, N, N);             // var s
-       tempname(ns, nsrc->type);
+       ns = temp(nsrc->type);
        l = list(l, nod(OAS, ns, nsrc));  // s = src
 
        na = nodintconst(argc);         // const argc
@@ -2164,8 +2154,7 @@ append(Node *n, NodeList **init)
                                               conv(na, types[TINT64]))));
        l = list(l, nx);
 
-       nn = nod(OXXX, N, N);                            // var n
-       tempname(nn, types[TINT]);
+       nn = temp(types[TINT]);
        l = list(l, nod(OAS, nn, nod(OLEN, ns, N)));     // n = len(s)
 
        nx = nod(OSLICE, ns, nod(OKEY, N, nod(OADD, nn, na)));   // ...s[:n+argc]