diff options
Diffstat (limited to 'src/cmd/dist')
-rw-r--r-- | src/cmd/dist/build.c | 7 | ||||
-rw-r--r-- | src/cmd/dist/buildgc.c | 87 | ||||
-rw-r--r-- | src/cmd/dist/buildruntime.c | 60 |
3 files changed, 87 insertions, 67 deletions
diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c index e4f307bee..bfb3d15b8 100644 --- a/src/cmd/dist/build.c +++ b/src/cmd/dist/build.c @@ -615,8 +615,6 @@ static struct { {"anames9.c", mkanames}, {"zdefaultcc.go", mkzdefaultcc}, {"zsys_", mkzsys}, - {"zgoarch_", mkzgoarch}, - {"zgoos_", mkzgoos}, {"zversion.go", mkzversion}, {"zaexperiment.h", mkzexperiment}, @@ -1419,12 +1417,13 @@ clean(void) xremove(bpathf(&b, "%s/%s", bstr(&path), cleantab[i]+4)); } - // remove src/runtime/z* unconditionally + // remove src/runtime/z* unconditionally, + // except leave zgoos and zgoarch, now maintained with go generate. vreset(&dir); bpathf(&path, "%s/src/runtime", goroot); xreaddir(&dir, bstr(&path)); for(j=0; j<dir.len; j++) { - if(hasprefix(dir.p[j], "z")) + if(hasprefix(dir.p[j], "z") && !hasprefix(dir.p[j], "zg")) xremove(bpathf(&b, "%s/%s", bstr(&path), dir.p[j])); } diff --git a/src/cmd/dist/buildgc.c b/src/cmd/dist/buildgc.c index 1c3329758..64434d51e 100644 --- a/src/cmd/dist/buildgc.c +++ b/src/cmd/dist/buildgc.c @@ -63,22 +63,36 @@ gcopnames(char *dir, char *file) vfree(&fields); } +static int +xatoi(char *s, char **end) +{ + int val = 0; + for(; *s && *s >= '0' && *s <= '9'; ++s) + val = val * 10 + (*s - '0'); + *end = s; + return val; +} + // mkanames reads [5689].out.h and writes anames[5689].c // The format is much the same as the Go opcodes above. -// it also writes out cnames array for C_* constants. +// It also writes out cnames array for C_* constants and the dnames +// array for D_* constants. void mkanames(char *dir, char *file) { - int i, j, ch; + int i, j, ch, n, unknown; Buf in, b, out, out2; Vec lines; - char *p; + char *p, *p2; + Vec dnames[128]; binit(&b); binit(&in); binit(&out); binit(&out2); vinit(&lines); + for(i=0; i<nelem(dnames); i++) + vinit(&dnames[i]); ch = file[xstrlen(file)-3]; bprintf(&b, "%s/../cmd/%cl/%c.out.h", dir, ch, ch); @@ -87,10 +101,12 @@ mkanames(char *dir, char *file) // Include link.h so that the extern declaration there is // checked against the non-extern declaration we are generating. + bwritestr(&out, bprintf(&b, "// auto generated by go tool dist\n")); bwritestr(&out, bprintf(&b, "#include <u.h>\n")); bwritestr(&out, bprintf(&b, "#include <libc.h>\n")); bwritestr(&out, bprintf(&b, "#include <bio.h>\n")); bwritestr(&out, bprintf(&b, "#include <link.h>\n")); + bwritestr(&out, bprintf(&b, "#include \"../cmd/%cl/%c.out.h\"\n", ch, ch)); bwritestr(&out, bprintf(&b, "\n")); bwritestr(&out, bprintf(&b, "char* anames%c[] = {\n", ch)); @@ -127,6 +143,69 @@ mkanames(char *dir, char *file) if(j>0) bwriteb(&out, &out2); + j=unknown=0; + n=-1; + for(i=0; i<lines.len; i++) { + if(hasprefix(lines.p[i], "\tD_")) { + p = xstrstr(lines.p[i], ","); + if(p) + *p = '\0'; + p = xstrstr(lines.p[i], "\n"); + if(p) + *p = '\0'; + + // Parse explicit value, if any + p = xstrstr(lines.p[i], "="); + if(p) { + // Skip space after '=' + p2 = p + 1; + while(*p2 == ' ' || *p2 == '\t') + p2++; + n = xatoi(p2, &p2); + // We can't do anything about + // non-numeric values or anything that + // follows + while(*p2 == ' ' || *p2 == '\t') + p2++; + if(*p2 != 0) { + unknown = 1; + continue; + } + // Truncate space before '=' + while(*(p-1) == ' ' || *(p-1) == '\t') + p--; + *p = '\0'; + unknown = 0; + } else { + n++; + } + + if(unknown || n >= nelem(dnames)) + continue; + + p = lines.p[i] + 3; + if(xstrcmp(p, "LAST") == 0) + continue; + vadd(&dnames[n], p); + j++; + } + } + if(j>0){ + bwritestr(&out, bprintf(&b, "char* dnames%c[D_LAST] = {\n", ch)); + for(i=0; i<nelem(dnames); i++) { + if(dnames[i].len == 0) + continue; + bwritestr(&out, bprintf(&b, "\t[D_%s] = \"", dnames[i].p[0])); + for(j=0; j<dnames[i].len; j++) { + if(j != 0) + bwritestr(&out, "/"); + bwritestr(&out, dnames[i].p[j]); + } + bwritestr(&out, "\",\n"); + } + bwritestr(&out, "};\n"); + } + writefile(&out, file, 0); bfree(&b); @@ -134,4 +213,6 @@ mkanames(char *dir, char *file) bfree(&out); bfree(&out2); vfree(&lines); + for(i=0; i<nelem(dnames); i++) + vfree(&dnames[i]); } diff --git a/src/cmd/dist/buildruntime.c b/src/cmd/dist/buildruntime.c index e561937fb..38e99e116 100644 --- a/src/cmd/dist/buildruntime.c +++ b/src/cmd/dist/buildruntime.c @@ -67,66 +67,6 @@ mkzexperiment(char *dir, char *file) bfree(&exp); } -// mkzgoarch writes zgoarch_$GOARCH.go: -// -// package runtime -// const theGoarch = <goarch> -// -void -mkzgoarch(char *dir, char *file) -{ - Buf b, out; - - USED(dir); - - binit(&b); - binit(&out); - - bwritestr(&out, bprintf(&b, - "// auto generated by go tool dist\n" - "\n" - "package runtime\n" - "\n" - "const theGoarch = `%s`\n", goarch)); - - writefile(&out, file, 0); - - bfree(&b); - bfree(&out); -} - -// mkzgoos writes zgoos_$GOOS.go: -// -// package runtime -// const theGoos = <goos> -// -void -mkzgoos(char *dir, char *file) -{ - Buf b, out; - - USED(dir); - - binit(&b); - binit(&out); - - bwritestr(&out, "// auto generated by go tool dist\n\n"); - - if(streq(goos, "linux")) { - bwritestr(&out, "// +build !android\n\n"); - } - - bwritestr(&out, bprintf(&b, - "package runtime\n" - "\n" - "const theGoos = `%s`\n", goos)); - - writefile(&out, file, 0); - - bfree(&b); - bfree(&out); -} - #define MAXWINCB 2000 /* maximum number of windows callbacks allowed */ // mkzsys writes zsys_$GOOS_$GOARCH.s, |