Commit 80212961 authored by Ken Thompson's avatar Ken Thompson

issue 682

complex DATA statement fo
initialization of complex variables.

R=rsc
CC=golang-dev
https://golang.org/cl/634045
parent 6c8fdbe8
......@@ -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)
{
......
......@@ -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)
{
......
......@@ -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)
{
......
......@@ -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)
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment