test: retarget Pattern-B gates to sep .sepwork layout; 915 off private global (M4 E3, #93)

The driver flip moves build artifacts from next-to-source <stem>.s to a
.sepwork/ scratch dir. 29 Pattern-B gates now build `ww build --sep -o <stem>`
and read <stem>.sepwork/__root.s (multi-package gates concat all
<stem>.sepwork/*.s, since cross-package labels live in per-package .s).
All intermediates redirect to /tmp (WW_PKGCACHE + -o), so the corpus runs
parallel-safe with no source-tree pollution. Tests pass now (--sep is live)
and survive the flip.

915 additionally retargeted off strconv's PRIVATE left_shift_table (a let,
not export) — which separate compilation correctly hides — onto a test-local
package that exports its own probe table (#96). The combined path only linked
it via a single-unit private leak; encapsulation is now honored under sep.

Test-only; all 5 *_ww binaries HOLD. 989_m1mangle_run deferred (blocked by
#99, imported-package fn main mangling under sep).
This commit is contained in:
2026-06-18 11:12:04 +09:00
parent 24ca570a7e
commit eb6083e54a
30 changed files with 583 additions and 324 deletions

View File

@@ -15,6 +15,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <glob.h>
#include <sys/wait.h>
static int
@@ -102,34 +103,64 @@ main(void)
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
const char *files[] = {
/* hand-written runtime — small, covers MOVQ/LEAQ/CALL/SYSCALL/RET. */
"rt/start.s",
"rt/syscall.s",
"rt/abort.s",
"rt/alloc.s",
"rt/streq.s",
/* generated .s from the existing selfhost stack — large,
* exercises every encoding w6c emits (the only way to hit
* the long tail of operand shapes). */
"selfhost/cmd/wwdump/main.s",
"selfhost/cmd/w6l/main.s",
"selfhost/cmd/w6a/main.s",
NULL,
/* #93 sep layout: the selfhost tools no longer leave a single
* next-to-source main.s. Self-build one real tool via `ww build
* --sep` into /tmp and feed EVERY emitted <tool>.sepwork/<pkg>.s as
* the generated-asm corpus — the root tool code plus each dep
* package's .s (richer than the old 3 monolithic main.s). Flip-
* invariant: --sep is live on trunk, default post-flip. */
char stem[256], cmd[4096];
snprintf(stem, sizeof stem, "/tmp/wwa_%d_sh", getpid());
snprintf(cmd, sizeof cmd,
"WW_PKGCACHE=%s.pkgc timeout 400 %s/ww build --sep -o %s "
"%s/selfhost/cmd/w6a >/dev/null 2>&1", stem, bin, stem, cwd);
if (runwait(cmd) != 0) {
fprintf(stderr, "w6a_ww FAIL: cannot sep-build selfhost/cmd/w6a\n");
return 1;
}
/* hand-written runtime — small, covers MOVQ/LEAQ/CALL/SYSCALL/RET;
* exists in-tree regardless of layout (not a casualty). */
const char *rtfiles[] = {
"rt/start.s", "rt/syscall.s", "rt/abort.s",
"rt/alloc.s", "rt/streq.s", NULL,
};
int fail = 0;
int n = 0;
for (int i = 0; files[i]; i++) {
for (int i = 0; rtfiles[i]; i++) {
char p[2048];
snprintf(p, sizeof p, "%s/%s", cwd, files[i]);
snprintf(p, sizeof p, "%s/%s", cwd, rtfiles[i]);
if (diff_one(bin, p) != 0) fail++;
n++;
}
/* generated .s from the real tool's sep build — large, exercises
* every encoding w6c emits (the long tail of operand shapes). */
glob_t g;
char pat[320];
snprintf(pat, sizeof pat, "%s.sepwork/*.s", stem);
if (glob(pat, 0, NULL, &g) == 0) {
for (size_t i = 0; i < g.gl_pathc; i++) {
/* skip empty units (e.g. an import-only rt.s). */
FILE *f = fopen(g.gl_pathv[i], "rb");
long sz = -1;
if (f) { fseek(f, 0, SEEK_END); sz = ftell(f); fclose(f); }
if (sz <= 0) continue;
if (diff_one(bin, g.gl_pathv[i]) != 0) fail++;
n++;
}
globfree(&g);
}
snprintf(cmd, sizeof cmd, "rm -rf %s.sepwork %s.pkgc %s",
stem, stem, stem);
if (system(cmd)) {}
if (fail) {
fprintf(stderr, "w6a_ww: %d/%d diff(s) failed\n", fail, n);
return 1;
}
printf("w6a_ww: byte-identical to C w6a on %d corpus files "
"(rt/*.s + selfhost generated main.s)\n", n);
"(rt/*.s + selfhost/cmd/w6a sep-built .s)\n", n);
return 0;
}