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).
This commit is contained in:
Graeme Geldenhuys 2026-06-03 23:49:29 +01:00
parent 7142f80cfa
commit 3addd9630f
9 changed files with 23 additions and 260 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.