summaryrefslogtreecommitdiff
path: root/src/cmd/dist/buildgc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/dist/buildgc.c')
-rw-r--r--src/cmd/dist/buildgc.c38
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);
}