diff options
Diffstat (limited to 'src/tools/genmap.c')
| -rw-r--r-- | src/tools/genmap.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/tools/genmap.c b/src/tools/genmap.c index d063d36..d515778 100644 --- a/src/tools/genmap.c +++ b/src/tools/genmap.c @@ -1,6 +1,6 @@ /* one layout for every memory size. addresses in a genome are literals, so each size is its own image. this tool writes that image's memmap.h and - the runtime (and, for a compiler build, compiler.zc) with the same const + the runtime (and, for a compiler build, the compiler parts) with the same const names as the checked-in 1,048,576-word sources. run from the repo root: @@ -58,6 +58,33 @@ static char *slurp(const char *path) return b; } +/* the compiler source is the files listed in src/compiler/parts, one per line, + joined in that order */ +static char *slurp_compiler(void) +{ + char *list = slurp("src/compiler/parts"), *out = malloc(1), *line, *next; + size_t n = 0; + if (!out) die("oom"); + out[0] = 0; + for (line = list; *line; line = next) { + char path[512], *part, *e = line + strcspn(line, "\n"); + size_t k; + next = *e ? e + 1 : e; + while (e > line && (e[-1] == '\r' || e[-1] == ' ' || e[-1] == '\t')) e--; + if (e == line) continue; + snprintf(path, sizeof path, "src/compiler/%.*s", (int)(e - line), line); + part = slurp(path); + k = strlen(part); + out = realloc(out, n + k + 1); + if (!out) die("oom"); + memcpy(out + n, part, k + 1); + n += k; + free(part); + } + free(list); + return out; +} + static void emit_file(const char *path, const char *s) { FILE *f = fopen(path, "wb"); @@ -613,7 +640,7 @@ static void check_sources(const Map *m) default map's header is generated into build/core and never kept in the tree */ FILE *mf = fopen("memmap.h", "rb"); const char *mm_path = mf ? (fclose(mf), "memmap.h") : 0; - char *rt = slurp("src/runtime/rt.zc"), *cc = slurp("src/compiler/compiler.zc"), *mm = mm_path ? slurp(mm_path) : 0; + char *rt = slurp("src/runtime/rt.zc"), *cc = slurp_compiler(), *mm = mm_path ? slurp(mm_path) : 0; char *rtb = between(rt, "// @map-rt", "// @end-map"); char *ccb = between(cc, "// @map-cc", "// @end-map"); static const char *rt_names[] = { @@ -644,13 +671,13 @@ static void check_sources(const Map *m) if (!rtb || !ccb) die("map markers missing from the checked-in sources"); snprintf(lfa_old, sizeof lfa_old, "ld %d", DEFAULT_ZFP); if (!strstr(rt, lfa_old)) die("src/runtime/rt.zc no longer has the default lfa immediate"); - if (!strstr(cc, "ZFP - 16384")) die("src/compiler/compiler.zc lost its initial type-area formula"); + if (!strstr(cc, "ZFP - 16384")) die("src/compiler lost its initial type-area formula"); for (i = 0; rt_names[i]; i++) expect_hex(rtb, "src/runtime/rt.zc", rt_names[i], rt_vals[i]); for (i = 0; mm && rt_names[i]; i++) { if (!strcmp(rt_names[i], "MAGIC") || !strcmp(rt_names[i], "HEAP_GROW")) continue; expect_hex(mm, mm_path, !strcmp(rt_names[i], "MW") ? "PW" : rt_names[i], rt_vals[i]); } - if (m->R_ASM) for (i = 0; cc_names[i]; i++) expect_hex(ccb, "src/compiler/compiler.zc", cc_names[i], cc_vals[i]); + if (m->R_ASM) for (i = 0; cc_names[i]; i++) expect_hex(ccb, "src/compiler", cc_names[i], cc_vals[i]); free(rt); free(cc); free(mm); free(rtb); free(ccb); } @@ -668,7 +695,7 @@ static void write_sources(const char *dir, const Spec *s, const Map *m) free(rt); free(block); free(spliced); free(done); if (!s->compiler) return; { - char *cc = slurp("src/compiler/compiler.zc"); + char *cc = slurp_compiler(); block = cc_block(m); spliced = splice(cc, "// @map-cc", "// @end-map", block); if (s->type_formula) { |
