selfhost: migrate tool sources to directory packages

Build w6a and w6l from package-main directories and expose the wcc backend through a narrow package API so w6c and wwdump no longer import implementation files. Retarget the remaining load-bearing fixtures and example sources to directory packages; retain the one intentional flat compiler collision as an explicitly composed raw unit.
This commit is contained in:
2026-08-12 17:12:03 +09:00
parent 90f9d60291
commit c7d9dc92de
38 changed files with 197 additions and 252 deletions

View File

@@ -6,9 +6,7 @@ import os;
import rt;
import strings;
import syntax;
import check;
import cgen;
import wwi;
import wcc;
fn cstreq(a: *u8, lit: str) bool = {
let n: u64 = lit.len: u64;
@@ -178,36 +176,9 @@ export fn main(argc: i32, argv: **u8) i32 = {
// cgen and emits junk asm with a zero exit (silent miscompile).
if (l.errs > 0 || ps.errs > 0) { return 1; };
// #50: run check before cgen so AST mutations from #42 (size/align/
// offset fold) and the audit §1.8 node.type_ population land before
// cgen walks the file. Mirrors cmd/w6c/main.c:73-75. Five precondition
// fixes for fixture cleanliness: #51 cross-module type refs, #52
// enum↔int reinterpret, #53 N_BLOCK scoping, #55 nominal-first variant
// compare, #56 bare-leaf same-module preference.
let tc: tctx;
typesinit(&tc);
let ck: checker;
checkinit(&ck, &tc);
ck.istest = testmode;
if (testsupport != nil) { ck.testmodule = pathstr(testsupport); };
ck.sepmode = sepmode;
checkfile(&ck, f);
if (ck.errs > 0) { return 1; };
// M2 export-data: write the `.wwi` after a clean check, before cgen.
// Dead on the live path (no existing invocation passes -I); the
// producer's check_exported_type may reject a dangling export.
if (wwiout != nil) {
if (wwiemit(&ck, f, pathstr(wwiout)) != 0) { return 1; };
};
let cg: cgen;
cgeninit(&cg);
cg.sepmode = sepmode;
// #99: wwiout != nil <=> this is a sep DEP unit (the producer passes
// -I to deps only; the root's .wwi is stripped per #69). Gates the
// bare-`main` carve-out so only the root/link-entry main stays bare.
if (wwiout != nil) { cg.sepisdep = 1i32; };
cgfile(&cg, f);
return 0;
let testmodule: str;
if (testsupport != nil) { testmodule = pathstr(testsupport); };
let interfaceout: str;
if (wwiout != nil) { interfaceout = pathstr(wwiout); };
return wcc.compilefile(f, testmode, testmodule, sepmode, interfaceout);
};