Skip to content

Commit

Permalink
composit literal under
Browse files Browse the repository at this point in the history
init function context.
also moved composit literal
code from walk.c to sinit.c

R=rsc
OCL=34503
CL=34503
  • Loading branch information
ken committed Sep 10, 2009
1 parent aa6e81d commit 0631d65
Show file tree
Hide file tree
Showing 5 changed files with 573 additions and 485 deletions.
31 changes: 31 additions & 0 deletions src/cmd/6g/ggen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,9 @@ gen_as_init(Node *n)
default:
goto no;

case OCONVSLICE:
goto slice;

case OLITERAL:
break;
}
Expand Down Expand Up @@ -1143,6 +1146,34 @@ gen_as_init(Node *n)
yes:
return 1;

slice:
p = gins(ANOP, N, N); // in case the data is the dest of a goto
nr = n->right->left;
if(nr == N || nr->op != OADDR)
goto no;
nr = nr->left;
if(nr == N || nr->op != ONAME)
goto no;

// nr is the array being converted to a slice
if(nr->type == T || nr->type->etype != TARRAY || nr->type->bound < 0)
goto no;

nam.xoffset += Array_array;
p = gins(ADATA, &nam, n->right->left);
p->from.scale = types[tptr]->width;

nam.xoffset += Array_nel-Array_array;
nodconst(&nod1, types[TINT32], nr->type->bound);
p = gins(ADATA, &nam, &nod1);
p->from.scale = types[TINT32]->width;

nam.xoffset += Array_cap-Array_nel;
p = gins(ADATA, &nam, &nod1);
p->from.scale = types[TINT32]->width;

goto yes;

no:
if(n->dodata == 2) {
dump("\ngen_as_init", n);
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/gc/align.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ dowidth(Type *t)
w = sizeof_Array;
else
fatal("dowidth %T", t); // probably [...]T
if(w == 0)
w = maxround;
break;

case TSTRUCT:
Expand Down
1 change: 1 addition & 0 deletions src/cmd/gc/go.h
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ void colasdefn(NodeList*, Node*);
NodeList* reorder1(NodeList*);
NodeList* reorder3(NodeList*);
NodeList* reorder4(NodeList*);
int vmatch1(Node*, Node*);
void anylit(Node*, Node*, NodeList**);
int oaslit(Node*, NodeList**);
void heapmoves(void);
Expand Down
Loading

0 comments on commit 0631d65

Please sign in to comment.