]> Cypherpunks repositories - gostls13.git/commitdiff
issue 682
authorKen Thompson <ken@golang.org>
Sun, 21 Mar 2010 01:50:01 +0000 (18:50 -0700)
committerKen Thompson <ken@golang.org>
Sun, 21 Mar 2010 01:50:01 +0000 (18:50 -0700)
complex DATA statement fo
initialization of complex variables.

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

src/cmd/5g/gobj.c
src/cmd/6g/gobj.c
src/cmd/8g/gobj.c
src/cmd/gc/cplx.c
src/cmd/gc/go.h
src/cmd/gc/sinit.c

index fffba011d012e1cfb4a27039f44cd008a522f902..0e8220007563dec2eba016cd9025a65e2efa4de9 100644 (file)
@@ -488,6 +488,27 @@ gdata(Node *nam, Node *nr, int wid)
        p->reg = wid;
 }
 
+void
+gdatacomplex(Node *nam, Mpcplx *cval)
+{
+       Prog *p;
+       int w;
+
+       w = cplxsubtype(nam->type->etype);
+       w = types[w]->width;
+
+       p = gins(ADATA, nam, N);
+       p->from.scale = w;
+       p->to.type = D_FCONST;
+       p->to.dval = mpgetflt(&cval->real);
+
+       p = gins(ADATA, nam, N);
+       p->from.scale = w;
+       p->from.offset += w;
+       p->to.type = D_FCONST;
+       p->to.dval = mpgetflt(&cval->imag);
+}
+
 void
 gdatastring(Node *nam, Strlit *sval)
 {
index 0d97c610db05f260a876948dd22080c1125f4878..e2db8c315fbf9eac4e3dbc24be48f2e3431ccfa7 100644 (file)
@@ -487,6 +487,27 @@ gdata(Node *nam, Node *nr, int wid)
        p->from.scale = wid;
 }
 
+void
+gdatacomplex(Node *nam, Mpcplx *cval)
+{
+       Prog *p;
+       int w;
+
+       w = cplxsubtype(nam->type->etype);
+       w = types[w]->width;
+
+       p = gins(ADATA, nam, N);
+       p->from.scale = w;
+       p->to.type = D_FCONST;
+       p->to.dval = mpgetflt(&cval->real);
+
+       p = gins(ADATA, nam, N);
+       p->from.scale = w;
+       p->from.offset += w;
+       p->to.type = D_FCONST;
+       p->to.dval = mpgetflt(&cval->imag);
+}
+
 void
 gdatastring(Node *nam, Strlit *sval)
 {
@@ -506,7 +527,6 @@ gdatastring(Node *nam, Strlit *sval)
        p->from.offset += types[tptr]->width;
 }
 
-
 int
 dstringptr(Sym *s, int off, char *str)
 {
index 68ebd3d1600995b39db2868d9bf848ec3bfde309..e48d2e196535465ebdb010a8e59e2d24029dc38b 100644 (file)
@@ -495,6 +495,27 @@ gdata(Node *nam, Node *nr, int wid)
        p->from.scale = wid;
 }
 
+void
+gdatacomplex(Node *nam, Mpcplx *cval)
+{
+       Prog *p;
+       int w;
+
+       w = cplxsubtype(nam->type->etype);
+       w = types[w]->width;
+
+       p = gins(ADATA, nam, N);
+       p->from.scale = w;
+       p->to.type = D_FCONST;
+       p->to.dval = mpgetflt(&cval->real);
+
+       p = gins(ADATA, nam, N);
+       p->from.scale = w;
+       p->from.offset += w;
+       p->to.type = D_FCONST;
+       p->to.dval = mpgetflt(&cval->imag);
+}
+
 void
 gdatastring(Node *nam, Strlit *sval)
 {
index d7f29d837012ab0906aa1f3e6eaa9973065705db..a98cf49d8d8b2572170ef4caed67d485ae2ac5c1 100644 (file)
@@ -5,7 +5,6 @@
 #include "gg.h"
 
 static void    subnode(Node *nr, Node *ni, Node *nc);
-static void    zero(Node *n);
 static void    minus(Node *nl, Node *res);
        void    complexminus(Node*, Node*);
        void    complexadd(int op, Node*, Node*, Node*);
@@ -340,26 +339,6 @@ subnode(Node *nr, Node *ni, Node *nc)
        ni->xoffset += t->width;
 }
 
-// generate code to zero addable dest nr
-static void
-zero(Node *nr)
-{
-       Node nc;
-       Mpflt fval;
-
-       memset(&nc, 0, sizeof(nc));
-       nc.op = OLITERAL;
-       nc.addable = 1;
-       ullmancalc(&nc);
-       nc.val.u.fval = &fval;
-       nc.val.ctype = CTFLT;
-       nc.type = nr->type;
-
-       mpmovecflt(nc.val.u.fval, 0.0);
-
-       cgen(&nc, nr);
-}
-
 // generate code res = -nl
 static void
 minus(Node *nl, Node *res)
index a301a756c8311d3b8a66aeab2c53f868684dd0cf..46be44d5ee6946382bde9354590cc6791c538c10 100644 (file)
@@ -1218,6 +1218,7 @@ void      cgen(Node*, Node*);
 void   gused(Node*);
 void   gdata(Node*, Node*, int);
 void   gdatastring(Node*, Strlit*);
+void   gdatacomplex(Node*, Mpcplx*);
 void   dumptypestructs(void);
 void   dumpfuncs(void);
 void   dumpdata(void);
index fd73dc0ad17de9103fdde4c0f95739dfff160e41..6f0772b63eb7cb18e282b27ae6dee039f1a50710 100644 (file)
@@ -826,6 +826,13 @@ gen_as_init(Node *n)
                gdata(&nam, nr, nr->type->width);
                break;
 
+       case TCOMPLEX64:
+       case TCOMPLEX128:
+       case TCOMPLEX:
+               gused(N); // in case the data is the dest of a goto
+               gdatacomplex(&nam, nr->val.u.cval);
+               break;
+
        case TSTRING:
                gused(N); // in case the data is the dest of a goto
                gdatastring(&nam, nr->val.u.sval);