diff options
author | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
---|---|---|
committer | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
commit | f154da9e12608589e8d5f0508f908a0c3e88a1bb (patch) | |
tree | f8255d51e10c6f1e0ed69702200b966c9556a431 /src/cmd/dist/buildgc.c | |
parent | 8d8329ed5dfb9622c82a9fbec6fd99a580f9c9f6 (diff) | |
download | golang-upstream/1.4.tar.gz |
Imported Upstream version 1.4upstream/1.4
Diffstat (limited to 'src/cmd/dist/buildgc.c')
-rw-r--r-- | src/cmd/dist/buildgc.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/cmd/dist/buildgc.c b/src/cmd/dist/buildgc.c index 1f0625daa..66adf6857 100644 --- a/src/cmd/dist/buildgc.c +++ b/src/cmd/dist/buildgc.c @@ -65,24 +65,35 @@ gcopnames(char *dir, char *file) // mkanames reads [568].out.h and writes anames[568].c // The format is much the same as the Go opcodes above. +// it also writes out cnames array for C_* constants. void mkanames(char *dir, char *file) { - int i, ch; - Buf in, b, out; + int i, j, ch; + Buf in, b, out, out2; Vec lines; char *p; binit(&b); binit(&in); binit(&out); + binit(&out2); vinit(&lines); ch = file[xstrlen(file)-3]; bprintf(&b, "%s/../cmd/%cl/%c.out.h", dir, ch, ch); readfile(&in, bstr(&b)); splitlines(&lines, bstr(&in)); - bprintf(&out, "char* anames%c[] = {\n", ch); + + // Include link.h so that the extern declaration there is + // checked against the non-extern declaration we are generating. + 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, "\n")); + + bwritestr(&out, bprintf(&b, "char* anames%c[] = {\n", ch)); for(i=0; i<lines.len; i++) { if(hasprefix(lines.p[i], "\tA")) { p = xstrstr(lines.p[i], ","); @@ -96,10 +107,31 @@ mkanames(char *dir, char *file) } } bwritestr(&out, "};\n"); + + j=0; + bprintf(&out2, "char* cnames%c[] = {\n", ch); + for(i=0; i<lines.len; i++) { + if(hasprefix(lines.p[i], "\tC_")) { + p = xstrstr(lines.p[i], ","); + if(p) + *p = '\0'; + p = xstrstr(lines.p[i], "\n"); + if(p) + *p = '\0'; + p = lines.p[i] + 3; + bwritestr(&out2, bprintf(&b, "\t\"%s\",\n", p)); + j++; + } + } + bwritestr(&out2, "};\n"); + if(j>0) + bwriteb(&out, &out2); + writefile(&out, file, 0); bfree(&b); bfree(&in); bfree(&out); + bfree(&out2); vfree(&lines); } |