diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:23:02 +0200 |
---|---|---|
committer | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:23:02 +0200 |
commit | 8fcc691d6fa80c9ddf38bf0d34b803bab0e421d5 (patch) | |
tree | ba71646a10b518372d110532d86fcf0b98edc14f /src/cmd/8a/lex.c | |
parent | 3bb719bbf3cdb97b3901f3baaa2da9d02a5c3cdb (diff) | |
parent | 8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (diff) | |
download | golang-8fcc691d6fa80c9ddf38bf0d34b803bab0e421d5.tar.gz |
Merge tag 'upstream/1.3' into debian-sid
Upstream version 1.3
Diffstat (limited to 'src/cmd/8a/lex.c')
-rw-r--r-- | src/cmd/8a/lex.c | 380 |
1 files changed, 85 insertions, 295 deletions
diff --git a/src/cmd/8a/lex.c b/src/cmd/8a/lex.c index f2ccc3361..32c099b75 100644 --- a/src/cmd/8a/lex.c +++ b/src/cmd/8a/lex.c @@ -57,56 +57,75 @@ pathchar(void) return '/'; } +int +Lconv(Fmt *fp) +{ + return linklinefmt(ctxt, fp); +} + +void +dodef(char *p) +{ + if(nDlist%8 == 0) + Dlist = allocn(Dlist, nDlist*sizeof(char *), + 8*sizeof(char *)); + Dlist[nDlist++] = p; +} + +void +usage(void) +{ + print("usage: %ca [options] file.c...\n", thechar); + flagprint(1); + errorexit(); +} void main(int argc, char *argv[]) { char *p; - int c; thechar = '8'; thestring = "386"; + ctxt = linknew(&link386); + ctxt->diag = yyerror; + ctxt->bso = &bstdout; + Binit(&bstdout, 1, OWRITE); + listinit8(); + fmtinstall('L', Lconv); + + // Allow GOARCH=thestring or GOARCH=thestringsuffix, + // but not other values. + p = getgoarch(); + if(strncmp(p, thestring, strlen(thestring)) != 0) + sysfatal("cannot use %cc with GOARCH=%s", thechar, p); + ensuresymb(NSYMB); memset(debug, 0, sizeof(debug)); cinit(); outfile = 0; setinclude("."); - ARGBEGIN { - default: - c = ARGC(); - if(c >= 0 && c < sizeof(debug)) - debug[c] = 1; - break; - - case 'o': - outfile = ARGF(); - break; - - case 'D': - p = ARGF(); - if(p) { - if (nDlist%8 == 0) - Dlist = allocn(Dlist, nDlist*sizeof(char *), - 8*sizeof(char *)); - Dlist[nDlist++] = p; - } - break; - - case 'I': - p = ARGF(); - setinclude(p); - break; - } ARGEND - if(*argv == 0) { - print("usage: %ca [-options] file.s\n", thechar); - errorexit(); - } + + flagfn1("D", "name[=value]: add #define", dodef); + flagfn1("I", "dir: add dir to include path", setinclude); + flagcount("S", "print assembly and machine code", &debug['S']); + flagcount("m", "debug preprocessor macros", &debug['m']); + flagstr("o", "file: set output file", &outfile); + flagstr("trimpath", "prefix: remove prefix from recorded source file paths", &ctxt->trimpath); + + flagparse(&argc, &argv, usage); + ctxt->debugasm = debug['S']; + + if(argc < 1) + usage(); if(argc > 1){ print("can't assemble multiple files\n"); errorexit(); } + if(assemble(argv[0])) errorexit(); + Bflush(&bstdout); exits(0); } @@ -145,30 +164,22 @@ assemble(char *file) errorexit(); } Binit(&obuf, of, OWRITE); - - pass = 1; - pinit(file); - - Bprint(&obuf, "go object %s %s %s\n", getgoos(), thestring, getgoversion()); - - for(i=0; i<nDlist; i++) - dodefine(Dlist[i]); - yyparse(); - if(nerrors) { + Bprint(&obuf, "go object %s %s %s\n", getgoos(), getgoarch(), getgoversion()); + Bprint(&obuf, "!\n"); + + for(pass = 1; pass <= 2; pass++) { + pinit(file); + for(i=0; i<nDlist; i++) + dodefine(Dlist[i]); + yyparse(); cclean(); - return nerrors; + if(nerrors) + return nerrors; } - Bprint(&obuf, "\n!\n"); - - pass = 2; - outhist(); - pinit(file); - for(i=0; i<nDlist; i++) - dodefine(Dlist[i]); - yyparse(); - cclean(); - return nerrors; + writeobj(ctxt, &obuf); + Bflush(&obuf); + return 0; } struct @@ -225,6 +236,7 @@ struct "ES", LSREG, D_ES, "FS", LSREG, D_FS, "GS", LSREG, D_GS, + "TLS", LSREG, D_TLS, "GDTR", LBREG, D_GDTR, "IDTR", LBREG, D_IDTR, @@ -778,6 +790,7 @@ struct "PSUBW", LTYPE3, APSUBW, "PUNPCKHQDQ", LTYPE3, APUNPCKHQDQ, "PUNPCKLQDQ", LTYPE3, APUNPCKLQDQ, + "PXOR", LTYPE3, APXOR, "RCPPS", LTYPE3, ARCPPS, "RCPSS", LTYPE3, ARCPSS, "RSQRTPS", LTYPE3, ARSQRTPS, @@ -810,15 +823,8 @@ cinit(void) Sym *s; int i; - nullgen.sym = S; - nullgen.offset = 0; - if(FPCHIP) - nullgen.dval = 0; - for(i=0; i<sizeof(nullgen.sval); i++) - nullgen.sval[i] = 0; nullgen.type = D_NONE; nullgen.index = D_NONE; - nullgen.scale = 0; nerrors = 0; iostack = I; @@ -834,13 +840,6 @@ cinit(void) s->type = itab[i].type; s->value = itab[i].value; } - - pathname = allocn(pathname, 0, 100); - if(getwd(pathname, 99) == 0) { - pathname = allocn(pathname, 100, 900); - if(getwd(pathname, 999) == 0) - strcpy(pathname, "/???"); - } } void @@ -868,252 +867,43 @@ syminit(Sym *s) void cclean(void) { - Gen2 g2; + Addr2 g2; g2.from = nullgen; g2.to = nullgen; outcode(AEND, &g2); - Bflush(&obuf); } -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); -} +static Prog *lastpc; void -zaddr(Gen *a, int s) +outcode(int a, Addr2 *g2) { - 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 -outcode(int a, Gen2 *g2) -{ - int sf, st, t; - Sym *s; - + Prog *p; + Plist *pl; + if(pass == 1) goto out; -jackpot: - sf = 0; - s = g2->from.sym; - while(s != S) { - sf = s->sym; - if(sf < 0 || sf >= NSYM) - sf = 0; - t = g2->from.type; - if(t == D_ADDR) - t = g2->from.index; - if(h[sf].type == t) - if(h[sf].sym == s) - break; - zname(s->name, t, sym); - s->sym = sym; - h[sym].sym = s; - h[sym].type = t; - sf = sym; - sym++; - if(sym >= NSYM) - sym = 1; - break; - } - st = 0; - s = g2->to.sym; - while(s != S) { - st = s->sym; - if(st < 0 || st >= NSYM) - st = 0; - t = g2->to.type; - if(t == D_ADDR) - t = g2->to.index; - if(h[st].type == t) - if(h[st].sym == s) - break; - zname(s->name, t, sym); - s->sym = sym; - h[sym].sym = s; - h[sym].type = t; - st = sym; - sym++; - if(sym >= NSYM) - sym = 1; - if(st == sf) - goto jackpot; - break; - } - BPUTLE2(&obuf, a); - BPUTLE4(&obuf, stmtline); - zaddr(&g2->from, sf); - zaddr(&g2->to, st); + p = malloc(sizeof *p); + memset(p, 0, sizeof *p); + p->as = a; + p->lineno = stmtline; + p->from = g2->from; + p->to = g2->to; + p->pc = pc; + + if(lastpc == nil) { + pl = linknewplist(ctxt); + pl->firstpc = p; + } else + lastpc->link = p; + lastpc = p; out: if(a != AGLOBL && a != ADATA) pc++; } -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; - } - } -} - #include "../cc/lexbody" #include "../cc/macbody" |