From 05a0e6e71bdd577c02a035c684c9afdc2c2f97ac Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 15:59:40 +0330 Subject: make: build zy with the llvm backend when an llvm with headers is found; NOLLVM=1 turns it off --- Makefile | 27 +++++++++++++++++++++++++-- README.md | 2 +- TODO.md | 10 +++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 8779cc3..8182b19 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ # (src/tools/xref.sh): build/xref/report.txt and report.json; # make xref XREF_ARGS=--check compares with tests/xref.baseline # make genome build/core/genome.bin from src/, with the fixpoint check +# make NOLLVM=1 leave the llvm backend out of zy (it is in by default when an +# llvm-config with headers is on PATH, or LLVM_CONFIG names one) # make build/bin/zyi the interpreter alone (zy has a jit on arm64 and on x86-64 linux) # make lsp build/bin/zclsp, the language server # make web build/web/: the page, its script and zc.wasm @@ -95,9 +97,30 @@ $(B)/core/genome.bin: $(ZC_DEPS) $(BIN)/zc0$(EXE) $(BIN)/mkgenome$(EXE) src/core cp $(B)/s1/genome.bin $@ @echo "fixpoint: $$(( $$(wc -c < $@) / 8 )) words, $@ updated" -# the vm core with the compiler genome inside: a jit on arm64 and x86-64 linux, else the interpreter +# the llvm backend (-DZYLLVM) goes into zy whenever an llvm with headers is found: +# LLVM_CONFIG when given, else llvm-config, else llvm-config-19 on PATH. llvm-config can +# exist without the headers (a runtime-only install), so the gate is llvm-c/Core.h. +# NOLLVM=1 leaves it out. zy does not record which way it was built: after changing +# NOLLVM or the llvm, rebuild it (rm build/bin/zy, or make clean). +ifneq ($(NOLLVM),1) + ifeq ($(origin LLVM_CONFIG),undefined) + LLVM_CONFIG := $(firstword $(shell command -v llvm-config llvm-config-19 2>/dev/null)) + endif + ifneq ($(LLVM_CONFIG),) + ifneq ($(wildcard $(shell $(LLVM_CONFIG) --includedir 2>/dev/null)/llvm-c/Core.h),) + LLVM_CFLAGS := -DZYLLVM $(shell $(LLVM_CONFIG) --cflags) + LLVM_LIBS := $(shell $(LLVM_CONFIG) --ldflags --libs) + endif + endif + ifeq ($(LLVM_CFLAGS),) + $(info note: no llvm-config with headers found, building zy without the llvm backend (NOLLVM=1 silences this)) + endif +endif + +# the vm core with the compiler genome inside: a jit on arm64 and x86-64 linux, else the +# interpreter; plus the llvm backend when found (above) $(BIN)/zy$(EXE): src/core/core.c $(IO) $(B)/core/genome.bin $(CORE_H) | $(BIN) - $(CC) $(CFLAGS) -DJTYPE=int src/core/core.c $(IO) $(COREINC) -o $@ + $(CC) $(CFLAGS) -DJTYPE=int $(LLVM_CFLAGS) src/core/core.c $(IO) $(COREINC) -o $@ $(LLVM_LIBS) # the interpreter alone, even on a host with a jit: make build/bin/zyi, to compare against zy $(BIN)/zyi$(EXE): src/core/core.c $(IO) $(B)/core/genome.bin $(CORE_H) | $(BIN) $(CC) $(CFLAGS) -DZYINTERP -DJTYPE=int src/core/core.c $(IO) $(COREINC) -o $@ diff --git a/README.md b/README.md index 35e94b6..c89ff50 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ windows needs clang or gcc and powershell for the tests. the batch file is the s ### native backends -on arm64, `src/core/core.c` uses its arm64 jit by default, and on x86-64 linux its x86-64 jit. other hosts use the interpreter. `-DZYINTERP` forces interpretation (`make build/bin/zyi` builds that core beside `zy`); `-DZYLLVM` enables the llvm backend when its headers and libraries are available. direct builds from the root are: +on arm64, `src/core/core.c` uses its arm64 jit by default, and on x86-64 linux its x86-64 jit. other hosts use the interpreter. `-DZYINTERP` forces interpretation (`make build/bin/zyi` builds that core beside `zy`); `-DZYLLVM` enables the llvm backend when its headers and libraries are available. `make` builds `zy` with it whenever it finds an llvm with headers (`LLVM_CONFIG` if given, else `llvm-config`, else `llvm-config-19` on `PATH`; the gate is `llvm-c/Core.h`), prints a one-line note and builds without it otherwise, and `make NOLLVM=1` leaves it out. since `-DZYLLVM` replaces the x86-64 jit, use `NOLLVM=1` to keep that jit in `zy` on x86-64 linux. rebuild `zy` after changing either setting (`rm build/bin/zy` or `make clean`). direct builds from the root are: ```sh make genome diff --git a/TODO.md b/TODO.md index bba2ff7..e76b7c3 100644 --- a/TODO.md +++ b/TODO.md @@ -241,9 +241,13 @@ the reasoning behind the open items survives the session. translation validation of each compile over proving the compiler whole. - native code: the hand-written jit exists for arm64 and (phase 1, no o3 regions or inlined enhancements yet) x86-64 linux; the llvm backend - (`-DZYLLVM`) is the portable native tier but the default build leaves it - out. cheap win: build the llvm core by default whenever `llvm-config` is - found. the x86-64 port of the hand-written jit is worth it for compile + (`-DZYLLVM`) is the portable native tier, and `make` now puts it in `zy` + whenever `llvm-config` or `llvm-config-19` with headers is found + (`NOLLVM=1` turns it off; without llvm the build prints a note and goes on). + checked on x86-64 with llvm 19: the fixpoint with llvm, without llvm on + `PATH`, and with `NOLLVM=1`, and `tests/test.sh --section llvm` (149 ok). + open: `-DZYLLVM` replaces the x86-64 jit, so the default x86-64 `zy` now + uses llvm rather than the hand-written jit; decide whether that is wanted. the x86-64 port of the hand-written jit is worth it for compile latency (microseconds per block against milliseconds for llvm), which matters for short programs and the language server. -- cgit v1.2.3