- Remove more ? : expressions.
- Use uint32 **hash instead of uint32 *hash[] in function argument.
- Change array.c API to use int, not int32, to match Go's slices.
- Rename strlit to newstrlit, to avoid case-insensitive collision with Strlit.
- Fix a few incorrect printf formats.
- Rename a few variables from 'len' to n or length.
- Eliminate direct string editing building up names like convI2T.
Change-Id: I754cf553402ccdd4963e51b7039f589286219c29
Reviewed-on: https://go-review.googlesource.com/3278
Reviewed-by: Rob Pike <r@golang.org>
};
Array*
-arraynew(int32 capacity, int32 size)
+arraynew(int capacity, int32 size)
{
Array *result;
free(array);
}
-int32
+int
arraylength(Array *array)
{
return array->length;
}
void*
-arrayget(Array *array, int32 index)
+arrayget(Array *array, int index)
{
if(array == nil)
fatal("arrayget: array is nil\n");
}
void
-arrayset(Array *array, int32 index, void *element)
+arrayset(Array *array, int index, void *element)
{
if(array == nil)
fatal("arrayset: array is nil\n");
}
static void
-ensurecapacity(Array *array, int32 capacity)
+ensurecapacity(Array *array, int capacity)
{
int32 newcapacity;
char *newdata;
spkg = basetype->sym->pkg;
if(spkg == nil) {
if(gopkg == nil)
- gopkg = mkpkg(strlit("go"));
+ gopkg = mkpkg(newstrlit("go"));
spkg = gopkg;
}
sym = pkglookup(p, spkg);
}
if(spkg == nil) {
if(toppkg == nil)
- toppkg = mkpkg(strlit("go"));
+ toppkg = mkpkg(newstrlit("go"));
spkg = toppkg;
}
s = pkglookup(p, spkg);
for(f=pa->method; f!=T; f=f->down) {
d = f;
if(f->etype != TFIELD)
- fatal("addmethod: not TFIELD: %N", f);
+ fatal("addmethod: not TFIELD: %lT", f);
if(strcmp(sf->name, f->sym->name) != 0)
continue;
if(!eqtype(t, f->type))
return tags[mask];
snprint(buf, sizeof buf, "esc:0x%x", mask);
- s = strlit(buf);
+ s = newstrlit(buf);
if(mask < nelem(tags))
tags[mask] = s;
return s;
void smagic(Magic *m);
Type* sortinter(Type *t);
uint32 stringhash(char *p);
-Strlit* strlit(char *s);
+Strlit* newstrlit(char *s);
int structcount(Type *t);
Type* structfirst(Iter *s, Type **nn);
Type* structnext(Iter *s);
void
doversion(void)
{
- char *p;
+ char *p, *sep;
p = expstring();
if(strcmp(p, "X:none") == 0)
p = "";
- print("%cg version %s%s%s\n", arch.thechar, getgoversion(), *p ? " " : "", p);
+ sep = "";
+ if(*p)
+ sep = " ";
+ print("%cg version %s%s%s\n", arch.thechar, getgoversion(), sep, p);
exits(0);
}
ctxt->bso = &bstdout;
Binit(&bstdout, 1, OWRITE);
- localpkg = mkpkg(strlit(""));
+ localpkg = mkpkg(newstrlit(""));
localpkg->prefix = "\"\"";
// pseudo-package, for scoping
- builtinpkg = mkpkg(strlit("go.builtin"));
+ builtinpkg = mkpkg(newstrlit("go.builtin"));
// pseudo-package, accessed by import "unsafe"
- unsafepkg = mkpkg(strlit("unsafe"));
+ unsafepkg = mkpkg(newstrlit("unsafe"));
unsafepkg->name = "unsafe";
// real package, referred to by generated runtime calls
- runtimepkg = mkpkg(strlit("runtime"));
+ runtimepkg = mkpkg(newstrlit("runtime"));
runtimepkg->name = "runtime";
// pseudo-packages used in symbol tables
- gostringpkg = mkpkg(strlit("go.string"));
+ gostringpkg = mkpkg(newstrlit("go.string"));
gostringpkg->name = "go.string";
gostringpkg->prefix = "go.string"; // not go%2estring
- itabpkg = mkpkg(strlit("go.itab"));
+ itabpkg = mkpkg(newstrlit("go.itab"));
itabpkg->name = "go.itab";
itabpkg->prefix = "go.itab"; // not go%2eitab
- weaktypepkg = mkpkg(strlit("go.weak.type"));
+ weaktypepkg = mkpkg(newstrlit("go.weak.type"));
weaktypepkg->name = "go.weak.type";
weaktypepkg->prefix = "go.weak.type"; // not go%2eweak%2etype
- typelinkpkg = mkpkg(strlit("go.typelink"));
+ typelinkpkg = mkpkg(newstrlit("go.typelink"));
typelinkpkg->name = "go.typelink";
typelinkpkg->prefix = "go.typelink"; // not go%2etypelink
- trackpkg = mkpkg(strlit("go.track"));
+ trackpkg = mkpkg(newstrlit("go.track"));
trackpkg->name = "go.track";
trackpkg->prefix = "go.track"; // not go%2etrack
- typepkg = mkpkg(strlit("type"));
+ typepkg = mkpkg(newstrlit("type"));
typepkg->name = "type";
goroot = getgoroot();
usage();
if(flag_race) {
- racepkg = mkpkg(strlit("runtime/race"));
+ racepkg = mkpkg(newstrlit("runtime/race"));
racepkg->name = "race";
}
static void
fakeimport(void)
{
- importpkg = mkpkg(strlit("fake"));
+ importpkg = mkpkg(newstrlit("fake"));
cannedimports("fake.6", "$$\n");
}
strcat(cleanbuf, "/");
strcat(cleanbuf, path->s);
cleanname(cleanbuf);
- path = strlit(cleanbuf);
+ path = newstrlit(cleanbuf);
if(isbadimport(path)) {
fakeimport();
{
int ap, bp;
- if (a->class != b->class)
- return (a->class == PAUTO) ? +1 : -1;
+ if (a->class != b->class) {
+ if(a->class == PAUTO)
+ return +1;
+ return -1;
+ }
if (a->class != PAUTO) {
if (a->xoffset < b->xoffset)
return -1;
BasicBlock *bb0;
Prog *p;
int32 i;
- int32 len;
+ int32 n;
- len = arraylength(cfg);
- if(len > 0) {
+ n = arraylength(cfg);
+ if(n > 0) {
bb0 = *(BasicBlock**)arrayget(cfg, 0);
for(p = bb0->first; p != P; p = p->link) {
p->opt = nil;
}
- for(i = 0; i < len; i++) {
+ for(i = 0; i < n; i++) {
bb = *(BasicBlock**)arrayget(cfg, i);
freeblock(bb);
}
static uint32
hashbitmap(uint32 h, Bvec *bv)
{
- uchar *p, *ep;
+ int i, n;
+ uint32 w;
- p = (uchar*)bv->b;
- ep = p + 4*((bv->n+31)/32);
- while(p < ep)
- h = (h*Hp) ^ *p++;
+ n = (bv->n+31)/32;
+ for(i=0; i<n; i++) {
+ w = bv->b[i];
+ h = (h*Hp) ^ (w&0xff);
+ h = (h*Hp) ^ ((w>>8)&0xff);
+ h = (h*Hp) ^ ((w>>16)&0xff);
+ h = (h*Hp) ^ ((w>>24)&0xff);
+ }
return h;
}
static int
callinstr(Node **np, NodeList **init, int wr, int skip)
{
+ char *name;
Node *f, *b, *n;
Type *t;
int class, hascalls;
n = treecopy(n);
makeaddable(n);
if(t->etype == TSTRUCT || isfixedarray(t)) {
- f = mkcall(wr ? "racewriterange" : "racereadrange", T, init, uintptraddr(n),
- nodintconst(t->width));
- } else
- f = mkcall(wr ? "racewrite" : "raceread", T, init, uintptraddr(n));
+ name = "racereadrange";
+ if(wr)
+ name = "racewriterange";
+ f = mkcall(name, T, init, uintptraddr(n), nodintconst(t->width));
+ } else {
+ name = "raceread";
+ if(wr)
+ name = "racewrite";
+ f = mkcall(name, T, init, uintptraddr(n));
+ }
*init = list(*init, f);
return 1;
}
return;
if(gopkg == nil) {
- gopkg = mkpkg(strlit("go"));
+ gopkg = mkpkg(newstrlit("go"));
gopkg->name = "go";
}
nam = smprint("importpath.%s.", p->prefix);
static Sym *ns;
if(ns == nil)
- ns = pkglookup("importpath.\"\".", mkpkg(strlit("go")));
+ ns = pkglookup("importpath.\"\".", mkpkg(newstrlit("go")));
return arch.dsymptr(s, ot, ns, 0);
}
dimportpath(runtimepkg);
if(flag_race)
dimportpath(racepkg);
- dimportpath(mkpkg(strlit("main")));
+ dimportpath(mkpkg(newstrlit("main")));
}
}
// Unfold the mask for the GC bitmap format:
// 4 bits per word, 2 high bits encode pointer info.
- pos = (uint8*)gcmask;
+ pos = gcmask;
nptr = (t->width+widthptr-1)/widthptr;
half = 0;
// If number of words is odd, repeat the mask.
case OLE: return OGT;
case OGE: return OLT;
}
- fatal("brcom: no com for %A\n", a);
+ fatal("brcom: no com for %O\n", a);
return a;
}
case OLE: return OGE;
case OGE: return OLE;
}
- fatal("brcom: no rev for %A\n", a);
+ fatal("brcom: no rev for %O\n", a);
return a;
}
// so no space cost to use them here.
l = nil;
v.ctype = CTSTR;
- v.u.sval = strlit(rcvr->type->sym->pkg->name); // package name
+ v.u.sval = newstrlit(rcvr->type->sym->pkg->name); // package name
l = list(l, nodlit(v));
- v.u.sval = strlit(rcvr->type->sym->name); // type name
+ v.u.sval = newstrlit(rcvr->type->sym->name); // type name
l = list(l, nodlit(v));
- v.u.sval = strlit(method->sym->name);
+ v.u.sval = newstrlit(method->sym->name);
l = list(l, nodlit(v)); // method name
call = nod(OCALL, syslook("panicwrap", 0), N);
call->list = l;
}
Strlit*
-strlit(char *s)
+newstrlit(char *s)
{
Strlit *t;
*/
static void
-fielddup(Node *n, Node *hash[], ulong nhash)
+fielddup(Node *n, Node **hash, ulong nhash)
{
uint h;
char *s;
}
static void
-keydup(Node *n, Node *hash[], ulong nhash)
+keydup(Node *n, Node **hash, ulong nhash)
{
uint h;
ulong b;
}
static void
-indexdup(Node *n, Node *hash[], ulong nhash)
+indexdup(Node *n, Node **hash, ulong nhash)
{
uint h;
Node *a;
typecheckcomplit(Node **np)
{
int bad, i, nerr;
- int64 len;
+ int64 length;
Node *l, *n, *norig, *r, **hash;
NodeList *ll;
Type *t, *f;
case TARRAY:
nhash = inithash(n, &hash, autohash, nelem(autohash));
- len = 0;
+ length = 0;
i = 0;
for(ll=n->list; ll; ll=ll->next) {
l = ll->n;
if(i >= 0)
indexdup(l->left, hash, nhash);
i++;
- if(i > len) {
- len = i;
- if(t->bound >= 0 && len > t->bound) {
+ if(i > length) {
+ length = i;
+ if(t->bound >= 0 && length > t->bound) {
setlineno(l);
- yyerror("array index %lld out of bounds [0:%lld]", len-1, t->bound);
+ yyerror("array index %lld out of bounds [0:%lld]", length-1, t->bound);
t->bound = -1; // no more errors
}
}
l->right = assignconv(r, t->type, "array element");
}
if(t->bound == -100)
- t->bound = len;
+ t->bound = length;
if(t->bound < 0)
- n->right = nodintconst(len);
+ n->right = nodintconst(length);
n->op = OARRAYLIT;
break;
int32 lno;
Node *n, *fn, *n1, *n2;
Sym *sym;
- char buf[100], *p;
+ char buf[100], *p, *from, *to;
n = *np;
n1 = nod(OADDR, n->left, N);
r = n->right; // i.(T)
- strcpy(buf, "assertI2T");
+ from = "I";
+ to = "T";
if(isnilinter(r->left->type))
- buf[6] = 'E';
+ from = "E";
if(isnilinter(r->type))
- buf[8] = 'E';
+ to = "E";
else if(isinter(r->type))
- buf[8] = 'I';
+ to = "I";
+ snprint(buf, sizeof buf, "assert%s2%s", from, to);
+
fn = syslook(buf, 1);
argtype(fn, r->left->type);
argtype(fn, r->type);
n1 = nod(OADDR, n->list->n, N);
n1->etype = 1; // addr does not escape
- strcpy(buf, "assertI2T2");
+ from = "I";
+ to = "T";
if(isnilinter(r->left->type))
- buf[6] = 'E';
+ from = "E";
if(isnilinter(r->type))
- buf[8] = 'E';
+ to = "E";
else if(isinter(r->type))
- buf[8] = 'I';
+ to = "I";
+ snprint(buf, sizeof buf, "assert%s2%s2", from, to);
fn = syslook(buf, 1);
argtype(fn, r->left->type);
// Build name of function: convI2E etc.
// Not all names are possible
// (e.g., we'll never generate convE2E or convE2I).
- strcpy(buf, "conv");
- p = buf+strlen(buf);
+ from = "T";
+ to = "I";
if(isnilinter(n->left->type))
- *p++ = 'E';
+ from = "E";
else if(isinter(n->left->type))
- *p++ = 'I';
- else
- *p++ = 'T';
- *p++ = '2';
+ from = "I";
if(isnilinter(n->type))
- *p++ = 'E';
- else
- *p++ = 'I';
- *p = '\0';
+ to = "E";
+ snprint(buf, sizeof buf, "conv%s2%s", from, to);
fn = syslook(buf, 1);
ll = nil;