From 3addd9630f9e8b520d1b33cb501d62d3b055913d Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Wed, 3 Jun 2026 23:49:29 +0100 Subject: [PATCH] chore(runtime): switch RTL build to unit-as-top-level; drop build-driver shims Now that the compiler supports `blaise --source Unit.pas --output Unit.o` directly, the build-driver pattern (a thin program wrapper + IR sed strip) is no longer needed. Replace every multi-step rule with a single invocation and delete the eight *_build_driver.pas files. This commit must follow the merge of blaise_clean_split in git history so that the rolling-bootstrap script can build the merge commit using the previous binary (which still uses the old Makefile), then build this commit using the freshly-merged binary (which understands unit-as-top-level). --- runtime/Makefile | 131 +++--------------- .../main/pascal/blaise_arc_build_driver.pas | 17 --- .../main/pascal/blaise_exc_build_driver.pas | 17 --- .../main/pascal/blaise_float_build_driver.pas | 20 --- .../main/pascal/blaise_mem_build_driver.pas | 18 --- .../main/pascal/blaise_str_build_driver.pas | 20 --- .../pascal/blaise_thread_build_driver.pas | 20 --- .../main/pascal/blaise_weak_build_driver.pas | 20 --- .../rtl.platform.posix_build_driver.pas | 20 --- 9 files changed, 23 insertions(+), 260 deletions(-) delete mode 100644 runtime/src/main/pascal/blaise_arc_build_driver.pas delete mode 100644 runtime/src/main/pascal/blaise_exc_build_driver.pas delete mode 100644 runtime/src/main/pascal/blaise_float_build_driver.pas delete mode 100644 runtime/src/main/pascal/blaise_mem_build_driver.pas delete mode 100644 runtime/src/main/pascal/blaise_str_build_driver.pas delete mode 100644 runtime/src/main/pascal/blaise_thread_build_driver.pas delete mode 100644 runtime/src/main/pascal/blaise_weak_build_driver.pas delete mode 100644 runtime/src/main/pascal/rtl.platform.posix_build_driver.pas diff --git a/runtime/Makefile b/runtime/Makefile index 16108e7..b78a3f5 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -5,12 +5,12 @@ # Licensed under the Apache License v2.0 with Runtime Library Exception. # See LICENSE file in the project root for full license terms. # -# Use bash with pipefail so that compiler errors in a `... | sed ...` -# pipeline propagate, instead of being masked by sed's exit code. -# Without this, a failing $(BLAISE) invocation produces an empty .ssa -# file and the build silently archives an empty .o (see bugs.txt BUG-004). +# Each Pascal unit is compiled directly via Blaise's unit-as-top-level +# mode (project_unit_as_toplevel, 2026-05-24): a single +# `blaise --source X.pas --output X.o` invocation runs qbe + cc -c +# + objcopy-embed in one step. No build-driver shims, no IR-strip +# sed pipelines, no intermediate .ssa/.s files needed. SHELL = /bin/bash -.SHELLFLAGS = -o pipefail -c CC = gcc CFLAGS = -O2 -Wall -Wextra -std=c11 @@ -25,14 +25,11 @@ LIB = $(OBJ_DIR)/blaise_rtl.a # driver finds it automatically next to itself. COMPILER_BIN = ../compiler/target BLAISE = $(COMPILER_BIN)/blaise -QBE = ../vendor/qbe/qbe # Assembly sources — platform-specific, no C compiler needed. ASM_OBJS = $(OBJ_DIR)/blaise_setjmp_x86_64.o # Pascal RTL units compiled via the Blaise compiler. -# Each unit is compiled by a thin driver program; the program section is -# stripped from the IR so only the unit's exported functions are archived. PAS_OBJS = $(OBJ_DIR)/blaise_mem.o \ $(OBJ_DIR)/blaise_str.o \ $(OBJ_DIR)/blaise_arc.o \ @@ -56,121 +53,39 @@ $(OBJ_DIR)/%.o: $(ASM_DIR)/%.s @mkdir -p $(OBJ_DIR) $(CC) -c -o $@ $< -# --- Pascal unit rules --- -# Compile via a build driver, strip everything from '# Generated by Blaise' -# onward (the program section), assemble the unit-only IR, then compile to .o. -$(OBJ_DIR)/blaise_mem.ssa: $(PAS_SRC_DIR)/blaise_mem.pas \ - $(PAS_SRC_DIR)/blaise_mem_build_driver.pas +# --- Pascal unit rules (unit-as-top-level) --- +$(OBJ_DIR)/blaise_mem.o: $(PAS_SRC_DIR)/blaise_mem.pas @mkdir -p $(OBJ_DIR) - $(BLAISE) --source $(PAS_SRC_DIR)/blaise_mem_build_driver.pas \ - --unit-path $(PAS_SRC_DIR) \ - --emit-ir \ - | sed '/^# Generated by Blaise/,$$d' > $@ + $(BLAISE) --source $< --unit-path $(PAS_SRC_DIR) --output $@ -$(OBJ_DIR)/blaise_mem.s: $(OBJ_DIR)/blaise_mem.ssa - $(QBE) -o $@ $< - -$(OBJ_DIR)/blaise_mem.o: $(OBJ_DIR)/blaise_mem.s - $(CC) -c -o $@ $< - -$(OBJ_DIR)/blaise_str.ssa: $(PAS_SRC_DIR)/blaise_str.pas \ - $(PAS_SRC_DIR)/blaise_str_build_driver.pas +$(OBJ_DIR)/blaise_str.o: $(PAS_SRC_DIR)/blaise_str.pas @mkdir -p $(OBJ_DIR) - $(BLAISE) --source $(PAS_SRC_DIR)/blaise_str_build_driver.pas \ - --unit-path $(PAS_SRC_DIR) \ - --emit-ir \ - | sed '/^# Generated by Blaise/,$$d' > $@ + $(BLAISE) --source $< --unit-path $(PAS_SRC_DIR) --output $@ -$(OBJ_DIR)/blaise_str.s: $(OBJ_DIR)/blaise_str.ssa - $(QBE) -o $@ $< - -$(OBJ_DIR)/blaise_str.o: $(OBJ_DIR)/blaise_str.s - $(CC) -c -o $@ $< - -$(OBJ_DIR)/blaise_arc.ssa: $(PAS_SRC_DIR)/blaise_arc.pas \ - $(PAS_SRC_DIR)/blaise_arc_build_driver.pas +$(OBJ_DIR)/blaise_arc.o: $(PAS_SRC_DIR)/blaise_arc.pas @mkdir -p $(OBJ_DIR) - $(BLAISE) --source $(PAS_SRC_DIR)/blaise_arc_build_driver.pas \ - --unit-path $(PAS_SRC_DIR) \ - --emit-ir \ - | sed '/^# Generated by Blaise/,$$d' > $@ + $(BLAISE) --source $< --unit-path $(PAS_SRC_DIR) --output $@ -$(OBJ_DIR)/blaise_arc.s: $(OBJ_DIR)/blaise_arc.ssa - $(QBE) -o $@ $< - -$(OBJ_DIR)/blaise_arc.o: $(OBJ_DIR)/blaise_arc.s - $(CC) -c -o $@ $< - -$(OBJ_DIR)/rtl_platform_posix.ssa: $(PAS_SRC_DIR)/rtl.platform.pas \ - $(PAS_SRC_DIR)/rtl.platform.posix.pas \ - $(PAS_SRC_DIR)/rtl.platform.posix_build_driver.pas +$(OBJ_DIR)/blaise_weak.o: $(PAS_SRC_DIR)/blaise_weak.pas @mkdir -p $(OBJ_DIR) - $(BLAISE) --source $(PAS_SRC_DIR)/rtl.platform.posix_build_driver.pas \ - --unit-path $(PAS_SRC_DIR) \ - --emit-ir \ - | sed '/^# Generated by Blaise/d; /^# Source:/d; /^export function w $$main/,/^}$$/d' > $@ + $(BLAISE) --source $< --unit-path $(PAS_SRC_DIR) --output $@ -$(OBJ_DIR)/rtl_platform_posix.s: $(OBJ_DIR)/rtl_platform_posix.ssa - $(QBE) -o $@ $< - -$(OBJ_DIR)/rtl_platform_posix.o: $(OBJ_DIR)/rtl_platform_posix.s - $(CC) -c -o $@ $< - -$(OBJ_DIR)/blaise_weak.ssa: $(PAS_SRC_DIR)/blaise_weak.pas \ - $(PAS_SRC_DIR)/blaise_weak_build_driver.pas +$(OBJ_DIR)/blaise_float.o: $(PAS_SRC_DIR)/blaise_float.pas @mkdir -p $(OBJ_DIR) - $(BLAISE) --source $(PAS_SRC_DIR)/blaise_weak_build_driver.pas \ - --unit-path $(PAS_SRC_DIR) \ - --emit-ir \ - | sed '/^# Generated by Blaise/,$$d' > $@ + $(BLAISE) --source $< --unit-path $(PAS_SRC_DIR) --output $@ -$(OBJ_DIR)/blaise_weak.s: $(OBJ_DIR)/blaise_weak.ssa - $(QBE) -o $@ $< - -$(OBJ_DIR)/blaise_weak.o: $(OBJ_DIR)/blaise_weak.s - $(CC) -c -o $@ $< - -$(OBJ_DIR)/blaise_float.ssa: $(PAS_SRC_DIR)/blaise_float.pas \ - $(PAS_SRC_DIR)/blaise_float_build_driver.pas +$(OBJ_DIR)/blaise_thread.o: $(PAS_SRC_DIR)/blaise_thread.pas @mkdir -p $(OBJ_DIR) - $(BLAISE) --source $(PAS_SRC_DIR)/blaise_float_build_driver.pas \ - --unit-path $(PAS_SRC_DIR) \ - --emit-ir \ - | sed '/^# Generated by Blaise/,$$d' > $@ + $(BLAISE) --source $< --unit-path $(PAS_SRC_DIR) --output $@ -$(OBJ_DIR)/blaise_float.s: $(OBJ_DIR)/blaise_float.ssa - $(QBE) -o $@ $< - -$(OBJ_DIR)/blaise_float.o: $(OBJ_DIR)/blaise_float.s - $(CC) -c -o $@ $< - -$(OBJ_DIR)/blaise_thread.ssa: $(PAS_SRC_DIR)/blaise_thread.pas \ - $(PAS_SRC_DIR)/blaise_thread_build_driver.pas +$(OBJ_DIR)/blaise_exc.o: $(PAS_SRC_DIR)/blaise_exc.pas @mkdir -p $(OBJ_DIR) - $(BLAISE) --source $(PAS_SRC_DIR)/blaise_thread_build_driver.pas \ - --unit-path $(PAS_SRC_DIR) \ - --emit-ir \ - | sed '/^# Generated by Blaise/,$$d' > $@ + $(BLAISE) --source $< --unit-path $(PAS_SRC_DIR) --output $@ -$(OBJ_DIR)/blaise_thread.s: $(OBJ_DIR)/blaise_thread.ssa - $(QBE) -o $@ $< - -$(OBJ_DIR)/blaise_thread.o: $(OBJ_DIR)/blaise_thread.s - $(CC) -c -o $@ $< - -$(OBJ_DIR)/blaise_exc.ssa: $(PAS_SRC_DIR)/blaise_exc.pas \ - $(PAS_SRC_DIR)/blaise_exc_build_driver.pas +$(OBJ_DIR)/rtl_platform_posix.o: $(PAS_SRC_DIR)/rtl.platform.posix.pas \ + $(PAS_SRC_DIR)/rtl.platform.pas @mkdir -p $(OBJ_DIR) - $(BLAISE) --source $(PAS_SRC_DIR)/blaise_exc_build_driver.pas \ - --unit-path $(PAS_SRC_DIR) \ - --emit-ir \ - | sed '/^# Generated by Blaise/,$$d' > $@ - -$(OBJ_DIR)/blaise_exc.s: $(OBJ_DIR)/blaise_exc.ssa - $(QBE) -o $@ $< - -$(OBJ_DIR)/blaise_exc.o: $(OBJ_DIR)/blaise_exc.s - $(CC) -c -o $@ $< + $(BLAISE) --source $< --unit-path $(PAS_SRC_DIR) --output $@ install: $(LIB) @mkdir -p $(COMPILER_BIN) diff --git a/runtime/src/main/pascal/blaise_arc_build_driver.pas b/runtime/src/main/pascal/blaise_arc_build_driver.pas deleted file mode 100644 index 740336d..0000000 --- a/runtime/src/main/pascal/blaise_arc_build_driver.pas +++ /dev/null @@ -1,17 +0,0 @@ -{ - Blaise - An Object Pascal Compiler - Copyright (c) 2026 Graeme Geldenhuys - SPDX-License-Identifier: Apache-2.0 WITH Swift-exception - Licensed under the Apache License v2.0 with Runtime Library Exception. - See LICENSE file in the project root for full license terms. -} - -{ Build driver for blaise_arc.pas — used only by the RTL Makefile. } - -program blaise_arc_build_driver; - -uses - blaise_arc; - -begin -end. diff --git a/runtime/src/main/pascal/blaise_exc_build_driver.pas b/runtime/src/main/pascal/blaise_exc_build_driver.pas deleted file mode 100644 index a7367bb..0000000 --- a/runtime/src/main/pascal/blaise_exc_build_driver.pas +++ /dev/null @@ -1,17 +0,0 @@ -{ - Blaise - An Object Pascal Compiler - Copyright (c) 2026 Graeme Geldenhuys - SPDX-License-Identifier: Apache-2.0 WITH Swift-exception - Licensed under the Apache License v2.0 with Runtime Library Exception. - See LICENSE file in the project root for full license terms. -} - -{ Build driver for blaise_exc.pas — used only by the RTL Makefile. } - -program blaise_exc_build_driver; - -uses - blaise_exc; - -begin -end. diff --git a/runtime/src/main/pascal/blaise_float_build_driver.pas b/runtime/src/main/pascal/blaise_float_build_driver.pas deleted file mode 100644 index b68ba6d..0000000 --- a/runtime/src/main/pascal/blaise_float_build_driver.pas +++ /dev/null @@ -1,20 +0,0 @@ -{ - Blaise - An Object Pascal Compiler - Copyright (c) 2026 Graeme Geldenhuys - SPDX-License-Identifier: Apache-2.0 WITH Swift-exception - Licensed under the Apache License v2.0 with Runtime Library Exception. - See LICENSE file in the project root for full license terms. -} - -{ Build driver for blaise_float.pas — used only by the RTL Makefile to compile - the unit into an object file for inclusion in blaise_rtl.a. The program - body is stripped from the IR before assembly; only the unit functions are - archived. } - -program blaise_float_build_driver; - -uses - blaise_float; - -begin -end. diff --git a/runtime/src/main/pascal/blaise_mem_build_driver.pas b/runtime/src/main/pascal/blaise_mem_build_driver.pas deleted file mode 100644 index eb197a1..0000000 --- a/runtime/src/main/pascal/blaise_mem_build_driver.pas +++ /dev/null @@ -1,18 +0,0 @@ -{ - Blaise - An Object Pascal Compiler - Copyright (c) 2026 Graeme Geldenhuys - SPDX-License-Identifier: Apache-2.0 WITH Swift-exception - Licensed under the Apache License v2.0 with Runtime Library Exception. - See LICENSE file in the project root for full license terms. -} - -{ Build driver for blaise_mem.pas — used only by the RTL Makefile to compile - the unit into an object file for inclusion in blaise_rtl.a. } - -program blaise_mem_build_driver; - -uses - blaise_mem; - -begin -end. diff --git a/runtime/src/main/pascal/blaise_str_build_driver.pas b/runtime/src/main/pascal/blaise_str_build_driver.pas deleted file mode 100644 index 99f66ec..0000000 --- a/runtime/src/main/pascal/blaise_str_build_driver.pas +++ /dev/null @@ -1,20 +0,0 @@ -{ - Blaise - An Object Pascal Compiler - Copyright (c) 2026 Graeme Geldenhuys - SPDX-License-Identifier: Apache-2.0 WITH Swift-exception - Licensed under the Apache License v2.0 with Runtime Library Exception. - See LICENSE file in the project root for full license terms. -} - -{ Build driver for blaise_str.pas — used only by the RTL Makefile to compile - the unit into an object file for inclusion in blaise_rtl.a. The program - body is stripped from the IR before assembly; only the unit functions are - archived. } - -program blaise_str_build_driver; - -uses - blaise_str; - -begin -end. diff --git a/runtime/src/main/pascal/blaise_thread_build_driver.pas b/runtime/src/main/pascal/blaise_thread_build_driver.pas deleted file mode 100644 index 1f7404c..0000000 --- a/runtime/src/main/pascal/blaise_thread_build_driver.pas +++ /dev/null @@ -1,20 +0,0 @@ -{ - Blaise - An Object Pascal Compiler - Copyright (c) 2026 Graeme Geldenhuys - SPDX-License-Identifier: Apache-2.0 WITH Swift-exception - Licensed under the Apache License v2.0 with Runtime Library Exception. - See LICENSE file in the project root for full license terms. -} - -{ Build driver for blaise_thread.pas — used only by the RTL Makefile to compile - the unit into an object file for inclusion in blaise_rtl.a. The program - body is stripped from the IR before assembly; only the unit functions are - archived. } - -program blaise_thread_build_driver; - -uses - blaise_thread; - -begin -end. diff --git a/runtime/src/main/pascal/blaise_weak_build_driver.pas b/runtime/src/main/pascal/blaise_weak_build_driver.pas deleted file mode 100644 index b970e6a..0000000 --- a/runtime/src/main/pascal/blaise_weak_build_driver.pas +++ /dev/null @@ -1,20 +0,0 @@ -{ - Blaise - An Object Pascal Compiler - Copyright (c) 2026 Graeme Geldenhuys - SPDX-License-Identifier: Apache-2.0 WITH Swift-exception - Licensed under the Apache License v2.0 with Runtime Library Exception. - See LICENSE file in the project root for full license terms. -} - -{ Build driver for blaise_weak.pas — used only by the RTL Makefile to compile - the unit into an object file for inclusion in blaise_rtl.a. The program - body is stripped from the IR before assembly; only the unit functions are - archived. } - -program blaise_weak_build_driver; - -uses - blaise_weak; - -begin -end. diff --git a/runtime/src/main/pascal/rtl.platform.posix_build_driver.pas b/runtime/src/main/pascal/rtl.platform.posix_build_driver.pas deleted file mode 100644 index 734690a..0000000 --- a/runtime/src/main/pascal/rtl.platform.posix_build_driver.pas +++ /dev/null @@ -1,20 +0,0 @@ -{ - Blaise - An Object Pascal Compiler - Copyright (c) 2026 Graeme Geldenhuys - SPDX-License-Identifier: Apache-2.0 WITH Swift-exception - Licensed under the Apache License v2.0 with Runtime Library Exception. - See LICENSE file in the project root for full license terms. -} - -{ Build driver for rtl.platform.posix.pas — used only by the RTL Makefile - to compile the unit into an object file for inclusion in blaise_rtl.a. - The program body is stripped from the IR before assembly; only the unit - functions are archived. } - -program rtl_platform_posix_build_driver; - -uses - rtl.platform.posix; - -begin -end.