mirror of
https://github.com/golang/go
synced 2024-11-22 03:14:41 -07:00
loader fix
static init redo R=rsc CC=golang-dev https://golang.org/cl/2254041
This commit is contained in:
parent
d4c8a54579
commit
103d756663
@ -1023,7 +1023,7 @@ void walkselect(Node *sel);
|
|||||||
/*
|
/*
|
||||||
* sinit.c
|
* sinit.c
|
||||||
*/
|
*/
|
||||||
void anylit(Node *n, Node *var, NodeList **init);
|
void anylit(int, Node *n, Node *var, NodeList **init);
|
||||||
int gen_as_init(Node *n);
|
int gen_as_init(Node *n);
|
||||||
NodeList* initfix(NodeList *l);
|
NodeList* initfix(NodeList *l);
|
||||||
int oaslit(Node *n, NodeList **init);
|
int oaslit(Node *n, NodeList **init);
|
||||||
@ -1116,7 +1116,6 @@ Type* shallow(Type *t);
|
|||||||
int simsimtype(Type *t);
|
int simsimtype(Type *t);
|
||||||
void smagic(Magic *m);
|
void smagic(Magic *m);
|
||||||
Type* sortinter(Type *t);
|
Type* sortinter(Type *t);
|
||||||
Node* staticname(Type *t);
|
|
||||||
uint32 stringhash(char *p);
|
uint32 stringhash(char *p);
|
||||||
Strlit* strlit(char *s);
|
Strlit* strlit(char *s);
|
||||||
int structcount(Type *t);
|
int structcount(Type *t);
|
||||||
|
@ -179,19 +179,20 @@ initfix(NodeList *l)
|
|||||||
* part of the composit literal.
|
* part of the composit literal.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void structlit(int pass, Node *n, Node *var, NodeList **init);
|
static void structlit(int ctxt, int pass, Node *n, Node *var, NodeList **init);
|
||||||
static void arraylit(int pass, Node *n, Node *var, NodeList **init);
|
static void arraylit(int ctxt, int pass, Node *n, Node *var, NodeList **init);
|
||||||
static void slicelit(Node *n, Node *var, NodeList **init);
|
static void slicelit(int ctxt, Node *n, Node *var, NodeList **init);
|
||||||
static void maplit(Node *n, Node *var, NodeList **init);
|
static void maplit(int ctxt, Node *n, Node *var, NodeList **init);
|
||||||
|
|
||||||
Node*
|
static Node*
|
||||||
staticname(Type *t)
|
staticname(Type *t, int ctxt)
|
||||||
{
|
{
|
||||||
Node *n;
|
Node *n;
|
||||||
|
|
||||||
snprint(namebuf, sizeof(namebuf), "statictmp_%.4d", statuniqgen);
|
snprint(namebuf, sizeof(namebuf), "statictmp_%.4d", statuniqgen);
|
||||||
statuniqgen++;
|
statuniqgen++;
|
||||||
n = newname(lookup(namebuf));
|
n = newname(lookup(namebuf));
|
||||||
|
if(!ctxt)
|
||||||
n->readonly = 1;
|
n->readonly = 1;
|
||||||
addvar(n, t, PEXTERN);
|
addvar(n, t, PEXTERN);
|
||||||
return n;
|
return n;
|
||||||
@ -270,7 +271,7 @@ getdyn(Node *n, int top)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
structlit(int pass, Node *n, Node *var, NodeList **init)
|
structlit(int ctxt, int pass, Node *n, Node *var, NodeList **init)
|
||||||
{
|
{
|
||||||
Node *r, *a;
|
Node *r, *a;
|
||||||
NodeList *nl;
|
NodeList *nl;
|
||||||
@ -286,21 +287,25 @@ structlit(int pass, Node *n, Node *var, NodeList **init)
|
|||||||
switch(value->op) {
|
switch(value->op) {
|
||||||
case OARRAYLIT:
|
case OARRAYLIT:
|
||||||
if(value->type->bound < 0) {
|
if(value->type->bound < 0) {
|
||||||
if(pass == 2) {
|
if(pass == 1 && ctxt != 0) {
|
||||||
a = nod(ODOT, var, newname(index->sym));
|
a = nod(ODOT, var, newname(index->sym));
|
||||||
slicelit(value, a, init);
|
slicelit(ctxt, value, a, init);
|
||||||
|
} else
|
||||||
|
if(pass == 2 && ctxt == 0) {
|
||||||
|
a = nod(ODOT, var, newname(index->sym));
|
||||||
|
slicelit(ctxt, value, a, init);
|
||||||
} else
|
} else
|
||||||
if(pass == 3)
|
if(pass == 3)
|
||||||
break;
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
a = nod(ODOT, var, newname(index->sym));
|
a = nod(ODOT, var, newname(index->sym));
|
||||||
arraylit(pass, value, a, init);
|
arraylit(ctxt, pass, value, a, init);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case OSTRUCTLIT:
|
case OSTRUCTLIT:
|
||||||
a = nod(ODOT, var, newname(index->sym));
|
a = nod(ODOT, var, newname(index->sym));
|
||||||
structlit(pass, value, a, init);
|
structlit(ctxt, pass, value, a, init);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +331,7 @@ structlit(int pass, Node *n, Node *var, NodeList **init)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
arraylit(int pass, Node *n, Node *var, NodeList **init)
|
arraylit(int ctxt, int pass, Node *n, Node *var, NodeList **init)
|
||||||
{
|
{
|
||||||
Node *r, *a;
|
Node *r, *a;
|
||||||
NodeList *l;
|
NodeList *l;
|
||||||
@ -342,21 +347,25 @@ arraylit(int pass, Node *n, Node *var, NodeList **init)
|
|||||||
switch(value->op) {
|
switch(value->op) {
|
||||||
case OARRAYLIT:
|
case OARRAYLIT:
|
||||||
if(value->type->bound < 0) {
|
if(value->type->bound < 0) {
|
||||||
if(pass == 2) {
|
if(pass == 1 && ctxt != 0) {
|
||||||
a = nod(OINDEX, var, index);
|
a = nod(OINDEX, var, index);
|
||||||
slicelit(value, a, init);
|
slicelit(ctxt, value, a, init);
|
||||||
|
} else
|
||||||
|
if(pass == 2 && ctxt == 0) {
|
||||||
|
a = nod(OINDEX, var, index);
|
||||||
|
slicelit(ctxt, value, a, init);
|
||||||
} else
|
} else
|
||||||
if(pass == 3)
|
if(pass == 3)
|
||||||
break;
|
break;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
a = nod(OINDEX, var, index);
|
a = nod(OINDEX, var, index);
|
||||||
arraylit(pass, value, a, init);
|
arraylit(ctxt, pass, value, a, init);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case OSTRUCTLIT:
|
case OSTRUCTLIT:
|
||||||
a = nod(OINDEX, var, index);
|
a = nod(OINDEX, var, index);
|
||||||
structlit(pass, value, a, init);
|
structlit(ctxt, pass, value, a, init);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,7 +391,7 @@ arraylit(int pass, Node *n, Node *var, NodeList **init)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
slicelit(Node *n, Node *var, NodeList **init)
|
slicelit(int ctxt, Node *n, Node *var, NodeList **init)
|
||||||
{
|
{
|
||||||
Node *r, *a;
|
Node *r, *a;
|
||||||
NodeList *l;
|
NodeList *l;
|
||||||
@ -398,6 +407,22 @@ slicelit(Node *n, Node *var, NodeList **init)
|
|||||||
t->sym = nil;
|
t->sym = nil;
|
||||||
dowidth(t);
|
dowidth(t);
|
||||||
|
|
||||||
|
if(ctxt != 0) {
|
||||||
|
|
||||||
|
// put everything into static array
|
||||||
|
vstat = staticname(t, ctxt);
|
||||||
|
arraylit(ctxt, 1, n, vstat, init);
|
||||||
|
arraylit(ctxt, 2, n, vstat, init);
|
||||||
|
|
||||||
|
// copy static to slice
|
||||||
|
a = nod(OSLICE, vstat, nod(OKEY, N, N));
|
||||||
|
a = nod(OAS, var, a);
|
||||||
|
typecheck(&a, Etop);
|
||||||
|
a->dodata = 2;
|
||||||
|
*init = list(*init, a);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// recipe for var = []t{...}
|
// recipe for var = []t{...}
|
||||||
// 1. make a static array
|
// 1. make a static array
|
||||||
// var vstat [...]t
|
// var vstat [...]t
|
||||||
@ -422,8 +447,8 @@ slicelit(Node *n, Node *var, NodeList **init)
|
|||||||
vstat = N;
|
vstat = N;
|
||||||
mode = getdyn(n, 1);
|
mode = getdyn(n, 1);
|
||||||
if(mode & MODECONST) {
|
if(mode & MODECONST) {
|
||||||
vstat = staticname(t);
|
vstat = staticname(t, ctxt);
|
||||||
arraylit(1, n, vstat, init);
|
arraylit(ctxt, 1, n, vstat, init);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make new auto *array (3 declare)
|
// make new auto *array (3 declare)
|
||||||
@ -468,11 +493,11 @@ slicelit(Node *n, Node *var, NodeList **init)
|
|||||||
case OARRAYLIT:
|
case OARRAYLIT:
|
||||||
if(value->type->bound < 0)
|
if(value->type->bound < 0)
|
||||||
break;
|
break;
|
||||||
arraylit(2, value, a, init);
|
arraylit(ctxt, 2, value, a, init);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case OSTRUCTLIT:
|
case OSTRUCTLIT:
|
||||||
structlit(2, value, a, init);
|
structlit(ctxt, 2, value, a, init);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,7 +513,7 @@ slicelit(Node *n, Node *var, NodeList **init)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
maplit(Node *n, Node *var, NodeList **init)
|
maplit(int ctxt, Node *n, Node *var, NodeList **init)
|
||||||
{
|
{
|
||||||
Node *r, *a;
|
Node *r, *a;
|
||||||
NodeList *l;
|
NodeList *l;
|
||||||
@ -497,6 +522,8 @@ maplit(Node *n, Node *var, NodeList **init)
|
|||||||
Node *vstat, *index, *value;
|
Node *vstat, *index, *value;
|
||||||
Sym *syma, *symb;
|
Sym *syma, *symb;
|
||||||
|
|
||||||
|
ctxt = 0;
|
||||||
|
|
||||||
// make the map var
|
// make the map var
|
||||||
nerr = nerrors;
|
nerr = nerrors;
|
||||||
|
|
||||||
@ -549,7 +576,7 @@ maplit(Node *n, Node *var, NodeList **init)
|
|||||||
dowidth(t);
|
dowidth(t);
|
||||||
|
|
||||||
// make and initialize static array
|
// make and initialize static array
|
||||||
vstat = staticname(t);
|
vstat = staticname(t, ctxt);
|
||||||
b = 0;
|
b = 0;
|
||||||
for(l=n->list; l; l=l->next) {
|
for(l=n->list; l; l=l->next) {
|
||||||
r = l->n;
|
r = l->n;
|
||||||
@ -640,7 +667,7 @@ maplit(Node *n, Node *var, NodeList **init)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
anylit(Node *n, Node *var, NodeList **init)
|
anylit(int ctxt, Node *n, Node *var, NodeList **init)
|
||||||
{
|
{
|
||||||
Type *t;
|
Type *t;
|
||||||
Node *a, *vstat;
|
Node *a, *vstat;
|
||||||
@ -655,9 +682,11 @@ anylit(Node *n, Node *var, NodeList **init)
|
|||||||
fatal("anylit: not struct");
|
fatal("anylit: not struct");
|
||||||
|
|
||||||
if(simplename(var)) {
|
if(simplename(var)) {
|
||||||
|
|
||||||
|
if(ctxt == 0) {
|
||||||
// lay out static data
|
// lay out static data
|
||||||
vstat = staticname(t);
|
vstat = staticname(t, ctxt);
|
||||||
structlit(1, n, vstat, init);
|
structlit(1, 1, n, vstat, init);
|
||||||
|
|
||||||
// copy static to var
|
// copy static to var
|
||||||
a = nod(OAS, var, vstat);
|
a = nod(OAS, var, vstat);
|
||||||
@ -666,7 +695,11 @@ anylit(Node *n, Node *var, NodeList **init)
|
|||||||
*init = list(*init, a);
|
*init = list(*init, a);
|
||||||
|
|
||||||
// add expressions to automatic
|
// add expressions to automatic
|
||||||
structlit(2, n, var, init);
|
structlit(ctxt, 2, n, var, init);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
structlit(ctxt, 1, n, var, init);
|
||||||
|
structlit(ctxt, 2, n, var, init);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,21 +710,23 @@ anylit(Node *n, Node *var, NodeList **init)
|
|||||||
walkexpr(&a, init);
|
walkexpr(&a, init);
|
||||||
*init = list(*init, a);
|
*init = list(*init, a);
|
||||||
}
|
}
|
||||||
structlit(3, n, var, init);
|
structlit(ctxt, 3, n, var, init);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OARRAYLIT:
|
case OARRAYLIT:
|
||||||
if(t->etype != TARRAY)
|
if(t->etype != TARRAY)
|
||||||
fatal("anylit: not array");
|
fatal("anylit: not array");
|
||||||
if(t->bound < 0) {
|
if(t->bound < 0) {
|
||||||
slicelit(n, var, init);
|
slicelit(ctxt, n, var, init);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(simplename(var)) {
|
if(simplename(var)) {
|
||||||
|
|
||||||
|
if(ctxt == 0) {
|
||||||
// lay out static data
|
// lay out static data
|
||||||
vstat = staticname(t);
|
vstat = staticname(t, ctxt);
|
||||||
arraylit(1, n, vstat, init);
|
arraylit(1, 1, n, vstat, init);
|
||||||
|
|
||||||
// copy static to automatic
|
// copy static to automatic
|
||||||
a = nod(OAS, var, vstat);
|
a = nod(OAS, var, vstat);
|
||||||
@ -700,7 +735,11 @@ anylit(Node *n, Node *var, NodeList **init)
|
|||||||
*init = list(*init, a);
|
*init = list(*init, a);
|
||||||
|
|
||||||
// add expressions to automatic
|
// add expressions to automatic
|
||||||
arraylit(2, n, var, init);
|
arraylit(ctxt, 2, n, var, init);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
arraylit(ctxt, 1, n, var, init);
|
||||||
|
arraylit(ctxt, 2, n, var, init);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,13 +750,13 @@ anylit(Node *n, Node *var, NodeList **init)
|
|||||||
walkexpr(&a, init);
|
walkexpr(&a, init);
|
||||||
*init = list(*init, a);
|
*init = list(*init, a);
|
||||||
}
|
}
|
||||||
arraylit(3, n, var, init);
|
arraylit(ctxt, 3, n, var, init);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OMAPLIT:
|
case OMAPLIT:
|
||||||
if(t->etype != TMAP)
|
if(t->etype != TMAP)
|
||||||
fatal("anylit: not map");
|
fatal("anylit: not map");
|
||||||
maplit(n, var, init);
|
maplit(ctxt, n, var, init);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -725,6 +764,8 @@ anylit(Node *n, Node *var, NodeList **init)
|
|||||||
int
|
int
|
||||||
oaslit(Node *n, NodeList **init)
|
oaslit(Node *n, NodeList **init)
|
||||||
{
|
{
|
||||||
|
int ctxt;
|
||||||
|
|
||||||
if(n->left == N || n->right == N)
|
if(n->left == N || n->right == N)
|
||||||
goto no;
|
goto no;
|
||||||
if(n->left->type == T || n->right->type == T)
|
if(n->left->type == T || n->right->type == T)
|
||||||
@ -737,6 +778,9 @@ oaslit(Node *n, NodeList **init)
|
|||||||
// context is init() function.
|
// context is init() function.
|
||||||
// implies generated data executed
|
// implies generated data executed
|
||||||
// exactly once and not subject to races.
|
// exactly once and not subject to races.
|
||||||
|
ctxt = 0;
|
||||||
|
// if(n->dodata == 1)
|
||||||
|
// ctxt = 1;
|
||||||
|
|
||||||
switch(n->right->op) {
|
switch(n->right->op) {
|
||||||
default:
|
default:
|
||||||
@ -747,7 +791,7 @@ oaslit(Node *n, NodeList **init)
|
|||||||
case OMAPLIT:
|
case OMAPLIT:
|
||||||
if(vmatch1(n->left, n->right))
|
if(vmatch1(n->left, n->right))
|
||||||
goto no;
|
goto no;
|
||||||
anylit(n->right, n->left, init);
|
anylit(ctxt, n->right, n->left, init);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
n->op = OEMPTY;
|
n->op = OEMPTY;
|
||||||
|
@ -1159,7 +1159,7 @@ walkexpr(Node **np, NodeList **init)
|
|||||||
case OMAPLIT:
|
case OMAPLIT:
|
||||||
case OSTRUCTLIT:
|
case OSTRUCTLIT:
|
||||||
nvar = makenewvar(n->type, init, &nstar);
|
nvar = makenewvar(n->type, init, &nstar);
|
||||||
anylit(n->left, nstar, init);
|
anylit(0, n->left, nstar, init);
|
||||||
n = nvar;
|
n = nvar;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
@ -1341,7 +1341,7 @@ walkexpr(Node **np, NodeList **init)
|
|||||||
case OSTRUCTLIT:
|
case OSTRUCTLIT:
|
||||||
nvar = nod(OXXX, N, N);
|
nvar = nod(OXXX, N, N);
|
||||||
tempname(nvar, n->type);
|
tempname(nvar, n->type);
|
||||||
anylit(n, nvar, init);
|
anylit(0, n, nvar, init);
|
||||||
n = nvar;
|
n = nvar;
|
||||||
goto ret;
|
goto ret;
|
||||||
|
|
||||||
|
@ -1030,7 +1030,7 @@ dwarfaddmachoheaders(void)
|
|||||||
// have to be page aligned in the file.
|
// have to be page aligned in the file.
|
||||||
fakestart = abbrevo & ~0xfff;
|
fakestart = abbrevo & ~0xfff;
|
||||||
|
|
||||||
ms = newMachoSeg("__DWARF", 3);
|
ms = newMachoSeg("__DWARF", 4);
|
||||||
ms->fileoffset = fakestart;
|
ms->fileoffset = fakestart;
|
||||||
ms->filesize = abbrevo-fakestart + abbrevsize+linesize+framesize+infosize;
|
ms->filesize = abbrevo-fakestart + abbrevsize+linesize+framesize+infosize;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user