mirror of
https://github.com/golang/go
synced 2024-10-05 18:31:28 -06:00
[dev.power64] cmd/9a: use new flag parser
Copy main from 6a. Fixes various things, but the main thing is the use of the new flag parser. The go command expects to be able to use -trimpath and not have it be interpreted as -t rimpath. LGTM=minux R=minux CC=golang-codereviews https://golang.org/cl/126100043
This commit is contained in:
parent
27627fd8ed
commit
53b78c84bc
113
src/cmd/9a/lex.c
113
src/cmd/9a/lex.c
@ -50,30 +50,54 @@ systemtype(int sys)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
pathchar(void)
|
||||||
|
{
|
||||||
|
return '/';
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Lconv(Fmt *fp)
|
Lconv(Fmt *fp)
|
||||||
{
|
{
|
||||||
return linklinefmt(ctxt, fp);
|
return linklinefmt(ctxt, fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
pathchar(void)
|
dodef(char *p)
|
||||||
{
|
{
|
||||||
return '/';
|
if(nDlist%8 == 0)
|
||||||
|
Dlist = allocn(Dlist, nDlist*sizeof(char *),
|
||||||
|
8*sizeof(char *));
|
||||||
|
Dlist[nDlist++] = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkArch* thelinkarch = &linkpower64;
|
||||||
|
|
||||||
|
void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
print("usage: %ca [options] file.c...\n", thechar);
|
||||||
|
flagprint(1);
|
||||||
|
errorexit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
int c;
|
|
||||||
|
|
||||||
thechar = '9';
|
thechar = '9';
|
||||||
thestring = getgoarch();
|
thestring = "power64";
|
||||||
if(strcmp(thestring, "power64le") == 0)
|
|
||||||
ctxt = linknew(&linkpower64le);
|
// Allow GOARCH=thestring or GOARCH=thestringsuffix,
|
||||||
else
|
// but not other values.
|
||||||
ctxt = linknew(&linkpower64);
|
p = getgoarch();
|
||||||
|
if(strncmp(p, thestring, strlen(thestring)) != 0)
|
||||||
|
sysfatal("cannot use %cc with GOARCH=%s", thechar, p);
|
||||||
|
if(strcmp(p, "power64le") == 0)
|
||||||
|
thelinkarch = &linkpower64le;
|
||||||
|
|
||||||
|
ctxt = linknew(thelinkarch);
|
||||||
ctxt->diag = yyerror;
|
ctxt->diag = yyerror;
|
||||||
ctxt->bso = &bstdout;
|
ctxt->bso = &bstdout;
|
||||||
Binit(&bstdout, 1, OWRITE);
|
Binit(&bstdout, 1, OWRITE);
|
||||||
@ -85,79 +109,57 @@ main(int argc, char *argv[])
|
|||||||
cinit();
|
cinit();
|
||||||
outfile = 0;
|
outfile = 0;
|
||||||
setinclude(".");
|
setinclude(".");
|
||||||
ARGBEGIN {
|
|
||||||
default:
|
|
||||||
c = ARGC();
|
|
||||||
if(c >= 0 && c < sizeof(debug))
|
|
||||||
debug[c] = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'o':
|
flagfn1("D", "name[=value]: add #define", dodef);
|
||||||
outfile = ARGF();
|
flagfn1("I", "dir: add dir to include path", setinclude);
|
||||||
break;
|
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);
|
||||||
|
|
||||||
case 'D':
|
flagparse(&argc, &argv, usage);
|
||||||
p = ARGF();
|
ctxt->debugasm = debug['S'];
|
||||||
if(p) {
|
|
||||||
if (nDlist%8 == 0)
|
|
||||||
Dlist = allocn(Dlist, nDlist*sizeof(char *),
|
|
||||||
8*sizeof(char *));
|
|
||||||
Dlist[nDlist++] = p;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'I':
|
if(argc < 1)
|
||||||
p = ARGF();
|
usage();
|
||||||
setinclude(p);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'S':
|
|
||||||
ctxt->debugasm++;
|
|
||||||
break;
|
|
||||||
} ARGEND
|
|
||||||
if(*argv == 0) {
|
|
||||||
print("usage: %ca [-options] file.s\n", thechar);
|
|
||||||
errorexit();
|
|
||||||
}
|
|
||||||
if(argc > 1){
|
if(argc > 1){
|
||||||
print("can't assemble multiple files\n");
|
print("can't assemble multiple files\n");
|
||||||
errorexit();
|
errorexit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(assemble(argv[0]))
|
if(assemble(argv[0]))
|
||||||
errorexit();
|
errorexit();
|
||||||
|
Bflush(&bstdout);
|
||||||
exits(0);
|
exits(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
assemble(char *file)
|
assemble(char *file)
|
||||||
{
|
{
|
||||||
char ofile[100], incfile[20], *p;
|
char *ofile, *p;
|
||||||
int i, of;
|
int i, of;
|
||||||
|
|
||||||
|
ofile = alloc(strlen(file)+3); // +3 for .x\0 (x=thechar)
|
||||||
strcpy(ofile, file);
|
strcpy(ofile, file);
|
||||||
if(p = strrchr(ofile, pathchar())) {
|
p = utfrrune(ofile, pathchar());
|
||||||
|
if(p) {
|
||||||
include[0] = ofile;
|
include[0] = ofile;
|
||||||
*p++ = 0;
|
*p++ = 0;
|
||||||
} else
|
} else
|
||||||
p = ofile;
|
p = ofile;
|
||||||
if(outfile == 0) {
|
if(outfile == 0) {
|
||||||
outfile = p;
|
outfile = p;
|
||||||
if(p = strrchr(outfile, '.'))
|
if(outfile){
|
||||||
|
p = utfrrune(outfile, '.');
|
||||||
|
if(p)
|
||||||
if(p[1] == 's' && p[2] == 0)
|
if(p[1] == 's' && p[2] == 0)
|
||||||
p[0] = 0;
|
p[0] = 0;
|
||||||
p = strrchr(outfile, 0);
|
p = utfrune(outfile, 0);
|
||||||
p[0] = '.';
|
p[0] = '.';
|
||||||
p[1] = thechar;
|
p[1] = thechar;
|
||||||
p[2] = 0;
|
p[2] = 0;
|
||||||
}
|
} else
|
||||||
p = getenv("INCLUDE");
|
outfile = "/dev/null";
|
||||||
if(p) {
|
|
||||||
setinclude(p);
|
|
||||||
} else {
|
|
||||||
if(systemtype(Plan9)) {
|
|
||||||
sprint(incfile,"/%s/include", thestring);
|
|
||||||
setinclude(strdup(incfile));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
of = create(outfile, OWRITE, 0664);
|
of = create(outfile, OWRITE, 0664);
|
||||||
@ -166,10 +168,9 @@ assemble(char *file)
|
|||||||
errorexit();
|
errorexit();
|
||||||
}
|
}
|
||||||
Binit(&obuf, of, OWRITE);
|
Binit(&obuf, of, OWRITE);
|
||||||
Bprint(&obuf, "go object %s %s %s\n", getgoos(), thestring, getgoversion());
|
Bprint(&obuf, "go object %s %s %s\n", getgoos(), getgoarch(), getgoversion());
|
||||||
Bprint(&obuf, "\n!\n");
|
Bprint(&obuf, "!\n");
|
||||||
|
|
||||||
pass = 1;
|
|
||||||
for(pass = 1; pass <= 2; pass++) {
|
for(pass = 1; pass <= 2; pass++) {
|
||||||
nosched = 0;
|
nosched = 0;
|
||||||
pinit(file);
|
pinit(file);
|
||||||
|
Loading…
Reference in New Issue
Block a user