void zname(Biobuf *b, Sym *s, int t) { BPUTLE2(b, ANAME); /* as */ BPUTC(b, t); /* type */ BPUTC(b, s->sym); /* sym */ Bputname(b, s); }
void zfile(Biobuf *b, char *p, int n) { BPUTLE2(b, ANAME); BPUTC(b, D_FILE); BPUTC(b, 1); BPUTC(b, '<'); Bwrite(b, p, n); BPUTC(b, 0); }
void showmsg(int m, int rflag) { long addr, len; int n, f, c, nl; uchar *ip; char *sp, *cp; if(m <= 0 || m > ncnotes){ Bad: fprint(2, "no footnote %d\n", m); return; } ip = &findex[8*(m-1)]; addr = LONG(ip); len = SHORT(ip+4); if(len == 0) goto Bad; Read(msg, addr, len); if(m > nfnotes && rflag){ cp = sp = malloc(len); memcpy(cp, msg, len); n = strtol(cp, &cp, 10); while(--n >= 0){ f = strtol(cp, &cp, 10); if(f > 0) showmsg(f, 0); } free(sp); return; } Bprint(out, "%d\t", m); ip = msg; nl = 0; while(ip<&msg[len]){ switch(c = *ip++){ case 0: case '\r': break; case '\n': BPUTC(out, c); ++nl; break; default: if(nl){ BPUTC(out, '\t'); nl = 0; } BPUTC(out, c); break; } } for(; nl<2; nl++) BPUTC(out, '\n'); }
void zname(char *n, int t, int s) { BPUTLE2(&obuf, ANAME); /* as(2) */ BPUTC(&obuf, t); /* type */ BPUTC(&obuf, s); /* sym */ while(*n) { BPUTC(&obuf, *n); n++; } BPUTC(&obuf, 0); }
void zhist(Biobuf *b, int line, vlong offset) { Addr a; BPUTC(b, AHISTORY); BPUTC(b, C_SCOND_NONE); BPUTC(b, NREG); BPUTLE4(b, line); zaddr(b, &zprog.from, 0, 0); a = zprog.to; if(offset != 0) { a.offset = offset; a.type = D_CONST; } zaddr(b, &a, 0, 0); }
void zaddr(Gen *a, int s) { int32 l; int i, t; char *n; Ieee e; t = 0; if(a->index != D_NONE || a->scale != 0) t |= T_INDEX; if(a->offset != 0) { t |= T_OFFSET; l = a->offset; if((vlong)l != a->offset) t |= T_64; } if(s != 0) t |= T_SYM; switch(a->type) { default: t |= T_TYPE; break; case D_FCONST: t |= T_FCONST; break; case D_SCONST: t |= T_SCONST; break; case D_NONE: break; } BPUTC(&obuf, t); if(t & T_INDEX) { /* implies index, scale */ BPUTC(&obuf, a->index); BPUTC(&obuf, a->scale); } if(t & T_OFFSET) { /* implies offset */ l = a->offset; BPUTLE4(&obuf, l); if(t & T_64) { l = a->offset>>32; BPUTLE4(&obuf, l); }
void zname(Biobuf *b, Sym *s, int t) { char *n; uint32 sig; if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){ sig = sign(s); BPUTLE2(b, ASIGNAME); BPUTLE4(b, sig); s->sig = SIGDONE; } else{ BPUTLE2(b, ANAME); /* as */ } BPUTC(b, t); /* type */ BPUTC(b, s->sym); /* sym */ n = s->name; while(*n) { BPUTC(b, *n); n++; } BPUTC(b, 0); }
void zaddr(Gen *a, int s) { int32 l; int i, t; char *n; Ieee e; t = 0; if(a->index != D_NONE || a->scale != 0) t |= T_INDEX; if(a->offset != 0) t |= T_OFFSET; if(s != 0) t |= T_SYM; switch(a->type) { default: t |= T_TYPE; break; case D_FCONST: t |= T_FCONST; break; case D_CONST2: t |= T_OFFSET|T_OFFSET2; break; case D_SCONST: t |= T_SCONST; break; case D_NONE: break; } BPUTC(&obuf, t); if(t & T_INDEX) { /* implies index, scale */ BPUTC(&obuf, a->index); BPUTC(&obuf, a->scale); } if(t & T_OFFSET) { /* implies offset */ l = a->offset; BPUTLE4(&obuf, l); } if(t & T_OFFSET2) { l = a->offset2; BPUTLE4(&obuf, l); } if(t & T_SYM) /* implies sym */ BPUTC(&obuf, s); if(t & T_FCONST) { ieeedtod(&e, a->dval); BPUTLE4(&obuf, e.l); BPUTLE4(&obuf, e.h); return; } if(t & T_SCONST) { n = a->sval; for(i=0; i<NSNAME; i++) { BPUTC(&obuf, *n); n++; } return; } if(t & T_TYPE) BPUTC(&obuf, a->type); }
void outhist(void) { Gen g; Hist *h; char *p, *q, *op, c; int n; char *tofree; static int first = 1; static char *goroot, *goroot_final; if(first) { // Decide whether we need to rewrite paths from $GOROOT to $GOROOT_FINAL. first = 0; goroot = getenv("GOROOT"); goroot_final = getenv("GOROOT_FINAL"); if(goroot == nil) goroot = ""; if(goroot_final == nil) goroot_final = goroot; if(strcmp(goroot, goroot_final) == 0) { goroot = nil; goroot_final = nil; } } tofree = nil; g = nullgen; c = pathchar(); for(h = hist; h != H; h = h->link) { p = h->name; if(p != nil && goroot != nil) { n = strlen(goroot); if(strncmp(p, goroot, strlen(goroot)) == 0 && p[n] == '/') { tofree = smprint("%s%s", goroot_final, p+n); p = tofree; } } op = 0; if(systemtype(Windows) && p && p[1] == ':'){ c = p[2]; } else if(p && p[0] != c && h->offset == 0 && pathname){ if(systemtype(Windows) && pathname[1] == ':') { op = p; p = pathname; c = p[2]; } else if(pathname[0] == c){ op = p; p = pathname; } } while(p) { q = strchr(p, c); if(q) { n = q-p; if(n == 0){ n = 1; /* leading "/" */ *p = '/'; /* don't emit "\" on windows */ } q++; } else { n = strlen(p); q = 0; } if(n) { BPUTLE2(&obuf, ANAME); BPUTC(&obuf, D_FILE); /* type */ BPUTC(&obuf, 1); /* sym */ BPUTC(&obuf, '<'); Bwrite(&obuf, p, n); BPUTC(&obuf, 0); } p = q; if(p == 0 && op) { p = op; op = 0; } } g.offset = h->offset; BPUTLE2(&obuf, AHISTORY); BPUTLE4(&obuf, h->line); zaddr(&nullgen, 0); zaddr(&g, 0); if(tofree) { free(tofree); tofree = nil; } } }
void zaddr(Biobuf *b, Addr *a, int s, int gotype) { int32 l; uint64 e; int i, t; char *n; t = 0; if(a->index != D_NONE || a->scale != 0) t |= T_INDEX; if(s != 0) t |= T_SYM; if(gotype != 0) t |= T_GOTYPE; switch(a->type) { case D_BRANCH: if(a->u.branch == nil) fatal("unpatched branch"); a->offset = a->u.branch->loc; default: t |= T_TYPE; case D_NONE: if(a->offset != 0) t |= T_OFFSET; if(a->offset2 != 0) t |= T_OFFSET2; break; case D_FCONST: t |= T_FCONST; break; case D_SCONST: t |= T_SCONST; break; } BPUTC(b, t); if(t & T_INDEX) { /* implies index, scale */ BPUTC(b, a->index); BPUTC(b, a->scale); } if(t & T_OFFSET) { /* implies offset */ l = a->offset; BPUTLE4(b, l); } if(t & T_OFFSET2) { /* implies offset */ l = a->offset2; BPUTLE4(b, l); } if(t & T_SYM) /* implies sym */ BPUTC(b, s); if(t & T_FCONST) { ieeedtod(&e, a->u.dval); BPUTLE4(b, e); BPUTLE4(b, e >> 32); return; }
void zaddr(Biobuf *b, Addr *a, int s, int gotype) { int32 l; uint64 e; int i; char *n; switch(a->type) { case D_STATIC: case D_AUTO: case D_EXTERN: case D_PARAM: // TODO(kaib): remove once everything seems to work fatal("We should no longer generate these as types"); default: BPUTC(b, a->type); BPUTC(b, a->reg); BPUTC(b, s); BPUTC(b, a->name); BPUTC(b, gotype); } switch(a->type) { default: print("unknown type %d in zaddr\n", a->type); case D_NONE: case D_REG: case D_FREG: case D_PSR: break; case D_CONST2: l = a->offset2; BPUTLE4(b, l); // fall through case D_OREG: case D_CONST: case D_SHIFT: case D_STATIC: case D_AUTO: case D_EXTERN: case D_PARAM: l = a->offset; BPUTLE4(b, l); break; case D_BRANCH: if(a->u.branch == nil) fatal("unpatched branch"); a->offset = a->u.branch->loc; l = a->offset; BPUTLE4(b, l); break; case D_SCONST: n = a->u.sval; for(i=0; i<NSNAME; i++) { BPUTC(b, *n); n++; } break; case D_REGREG: case D_REGREG2: BPUTC(b, a->offset); break; case D_FCONST: ieeedtod(&e, a->u.dval); BPUTLE4(b, e); BPUTLE4(b, e >> 32); break; } }
static void zaddr(char *pn, Biobuf *f, Adr *a, Sym *h[]) { int i, c; int32 l; Sym *s; Auto *u; a->type = BGETC(f); a->reg = BGETC(f); c = BGETC(f); if(c < 0 || c > NSYM){ print("sym out of range: %d\n", c); BPUTC(f, ALAST+1); return; } a->sym = h[c]; a->name = BGETC(f); adrgotype = zsym(pn, f, h); if((schar)a->reg < 0 || a->reg > NREG) { print("register out of range %d\n", a->reg); BPUTC(f, ALAST+1); return; /* force real diagnostic */ } if(a->type == D_CONST || a->type == D_OCONST) { if(a->name == D_EXTERN || a->name == D_STATIC) { s = a->sym; if(s != S && (s->type == STEXT || s->type == SCONST || s->type == SXREF)) { if(0 && !s->fnptr && s->name[0] != '.') print("%s used as function pointer\n", s->name); s->fnptr = 1; // over the top cos of SXREF } } } switch(a->type) { default: print("unknown type %d\n", a->type); BPUTC(f, ALAST+1); return; /* force real diagnostic */ case D_NONE: case D_REG: case D_FREG: case D_PSR: case D_FPCR: break; case D_REGREG: case D_REGREG2: a->offset = BGETC(f); break; case D_CONST2: a->offset2 = BGETLE4(f); // fall through case D_BRANCH: case D_OREG: case D_CONST: case D_OCONST: case D_SHIFT: a->offset = BGETLE4(f); break; case D_SCONST: a->sval = mal(NSNAME); Bread(f, a->sval, NSNAME); break; case D_FCONST: a->ieee.l = BGETLE4(f); a->ieee.h = BGETLE4(f); break; } s = a->sym; if(s == S) return; i = a->name; if(i != D_AUTO && i != D_PARAM) { if(s && adrgotype) s->gotype = adrgotype; return; } l = a->offset; for(u=curauto; u; u=u->link) if(u->asym == s) if(u->type == i) { if(u->aoffset > l) u->aoffset = l; if(adrgotype) u->gotype = adrgotype; return; } u = mal(sizeof(Auto)); u->link = curauto; curauto = u; u->asym = s; u->aoffset = l; u->type = i; u->gotype = adrgotype; }
void outhist(Biobuf *b) { Hist *h; char *p, *q, *op, c; Prog pg; int n; char *tofree; static int first = 1; static char *goroot, *goroot_final; if(first) { // Decide whether we need to rewrite paths from $GOROOT to $GOROOT_FINAL. first = 0; goroot = getenv("GOROOT"); goroot_final = getenv("GOROOT_FINAL"); if(goroot == nil) goroot = ""; if(goroot_final == nil) goroot_final = goroot; if(strcmp(goroot, goroot_final) == 0) { goroot = nil; goroot_final = nil; } } tofree = nil; pg = zprog; pg.as = AHISTORY; c = pathchar(); for(h = hist; h != H; h = h->link) { p = h->name; if(p != nil && goroot != nil) { n = strlen(goroot); if(strncmp(p, goroot, strlen(goroot)) == 0 && p[n] == '/') { tofree = smprint("%s%s", goroot_final, p+n); p = tofree; } } op = 0; if(systemtype(Windows) && p && p[1] == ':'){ c = p[2]; } else if(p && p[0] != c && h->offset == 0 && pathname){ if(systemtype(Windows) && pathname[1] == ':') { op = p; p = pathname; c = p[2]; } else if(pathname[0] == c){ op = p; p = pathname; } } while(p) { q = utfrune(p, c); if(q) { n = q-p; if(n == 0){ n = 1; /* leading "/" */ *p = '/'; /* don't emit "\" on windows */ } q++; } else { n = strlen(p); q = 0; } if(n) { BPUTLE2(b, ANAME); BPUTC(b, D_FILE); BPUTC(b, 1); BPUTC(b, '<'); Bwrite(b, p, n); BPUTC(b, 0); } p = q; if(p == 0 && op) { p = op; op = 0; } } pg.lineno = h->line; pg.to.type = zprog.to.type; pg.to.offset = h->offset; if(h->offset) pg.to.type = D_CONST; BPUTLE2(b, pg.as); BPUTLE4(b, pg.lineno); zaddr(b, &pg.from, 0); zaddr(b, &pg.to, 0); if(tofree) { free(tofree); tofree = nil; } } }