6c: ww-side compiler binary, dup2 syscall, test 994

selfhost/cmd/6c/main.ww is a thin packaging of the wwc cgen — slurp
a .ww file, run lex+parse+cgen, write Plan 9 amd64 asm to the path
given by -o. The cgen routines in selfhost/cmd/wwc/cgen.ww write
directly to fd 1, so we use dup2 to redirect stdout into the
output file rather than thread an fd through every emit helper.
Adds the SYS_DUP2=33 wrapper in lib/os.

Makefile wires $(BIN)/6c_ww alongside the other wwstage tools and
adds $(BIN)/test_6c_ww to the TESTS list.

test/wwc/994_6c_ww.c diffs 6c_ww byte-for-byte against
`wwdump_ww -c` on five in-source programs plus the four selfhost
main.combined.ww files: same cgen reached through two binaries, so
any divergence is a packaging bug in selfhost/cmd/6c.

We deliberately don't diff against C-side 6c here — 990 probe 5
already covers that on the subset the ww cgen handles today.
This commit is contained in:
2026-05-11 11:20:06 +09:00
parent 607cc8d330
commit 218d8469ff
4 changed files with 347 additions and 3 deletions

View File

@@ -47,8 +47,8 @@ CSTAGE_BINS = $(BIN)/ww $(BIN)/6c $(BIN)/6a $(BIN)/6l $(BIN)/wwdump
# Wwstage: ww-rewritten toolchain. Built by Cstage today; will be the
# only toolchain after Phase 10 closeout. Byte-identical to Cstage
# (tests 990-993).
WWSTAGE_BINS = $(BIN)/wwdump_ww $(BIN)/6a_ww $(BIN)/6l_ww $(BIN)/ww_ww
# (tests 990-994).
WWSTAGE_BINS = $(BIN)/wwdump_ww $(BIN)/6c_ww $(BIN)/6a_ww $(BIN)/6l_ww $(BIN)/ww_ww
BINS = $(CSTAGE_BINS) $(WWSTAGE_BINS)
LIBS = $(LIB)/libwwc.a $(LIB)/libwwrt.a
@@ -116,6 +116,21 @@ $(BIN)/wwdump_ww: selfhost/cmd/wwdump/main.ww \
$$PWD/../../selfhost/cmd/wwdump/main.ww
mv $(BIN)/main $@
# ---- ww-side 6c (compiler port, exercised by 994_6c_ww) ----------------
# Thin driver: parse + cgen, both already living in selfhost/cmd/wwc.
# Build through `ww build` like the other wwstage tools.
$(BIN)/6c_ww: selfhost/cmd/6c/main.ww \
selfhost/cmd/wwc/lex.ww selfhost/cmd/wwc/tok.ww \
selfhost/cmd/wwc/mem.ww selfhost/cmd/wwc/ast.ww \
selfhost/cmd/wwc/parse.ww selfhost/cmd/wwc/typ.ww \
selfhost/cmd/wwc/sym.ww selfhost/cmd/wwc/check.ww \
selfhost/cmd/wwc/cgen.ww \
$(BIN)/ww $(BIN)/6c $(BIN)/6a $(BIN)/6l \
$(LIB)/libwwrt.a | $(BIN)
cd $(BIN) && ./ww build -I $$PWD/../../selfhost/cmd/wwc \
$$PWD/../../selfhost/cmd/6c/main.ww
mv $(BIN)/main $@
# ---- ww-side 6a (assembler port, exercised by 991_6a_ww) ---------------
# Built like wwdump_ww. Needs -I selfhost/cmd/6a for the local types/lex/
# parse/asm/obj modules and -I selfhost/cmd/wwc to find `mem`.
@@ -172,7 +187,8 @@ $(BIN) $(LIB) $(OBJ)/wwc $(OBJ)/ww $(OBJ)/wwdump $(OBJ)/6c $(OBJ)/6a $(OBJ)/6l $
TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
$(BIN)/test_6c $(BIN)/test_6a $(BIN)/test_6l $(BIN)/test_arch \
$(BIN)/test_e2e $(BIN)/test_ffi $(BIN)/test_dyn $(BIN)/test_stdlib \
$(BIN)/test_selfhost $(BIN)/test_6a_ww $(BIN)/test_6l_ww $(BIN)/test_ww_ww
$(BIN)/test_selfhost $(BIN)/test_6a_ww $(BIN)/test_6l_ww \
$(BIN)/test_6c_ww $(BIN)/test_ww_ww
$(BIN)/test_smoke: test/wwc/000_smoke.c $(LIB)/libwwc.a | $(BIN)
$(CC) $(CFLAGS) $(INCS) -o $@ $< -L$(LIB) -lwwc
@@ -224,6 +240,9 @@ $(BIN)/test_6l_ww: test/wwc/992_6l_ww.c $(BIN)/6l $(BIN)/6l_ww \
$(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
$(BIN)/test_6c_ww: test/wwc/994_6c_ww.c $(BIN)/6c_ww $(BIN)/wwdump_ww | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
$(BIN)/test_ww_ww: test/wwc/993_ww_ww.c $(BIN)/ww $(BIN)/ww_ww \
$(BIN)/6c $(BIN)/6a $(BIN)/6l $(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
@@ -278,6 +297,7 @@ bootstrap: all
@echo
@echo "Already in selfhost/:"
@echo " - cmd/wwc/ : ww-cgen (lex/parse/check/cgen) — bootstrap fixed point"
@echo " - cmd/6c/ : ww-6c (lex/parse/cgen front-end) — matches wwdump_ww -c (test 994)"
@echo " - cmd/6a/ : ww-6a (lex/parse/asm/obj) — byte-identical to C 6a (test 991)"
@echo " - cmd/6l/ : ww-6l (linker w/ archive support) — byte-identical to C 6l (test 992)"
@echo " - cmd/ww/ : ww-driver (build/run/version) — byte-identical to C ww (test 993)"