# tests/hir — HIR CFG capacity / sentinel regressions (#1863).
#
# Header-only hir_program; no libmux link required.

CXX      ?= g++
CXXFLAGS ?= -std=c++17 -g -O1 -Wall -Wextra
# -MMD -MP goes in CPPFLAGS, not CXXFLAGS: CXXFLAGS is `?=`, so a caller
# overriding it would silently drop the dependency tracking (#1952).  The
# explicit hir.h prerequisite below stays -- it is what makes the FIRST
# build correct, before any .d exists.
CPPFLAGS += -I../../mux/include -MMD -MP

# Match the repo's sanitizer flags when the main tree is instrumented
# (#1522 pattern): empty on an ordinary build.
MUX_SANITIZE := $(shell grep -oE '\-fsanitize=[a-z,]+|\-fno-omit-frame-pointer' \
                  ../../mux/config.status 2>/dev/null | sort -u | tr '\n' ' ')
CXXFLAGS += $(MUX_SANITIZE)

.PHONY: all test clean

all: test_blocks test_phi

test_blocks: test_blocks.cpp ../../mux/include/hir.h
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ test_blocks.cpp

test_phi: test_phi.cpp ../../mux/include/hir.h
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ test_phi.cpp

test: test_blocks test_phi
	./test_blocks
	./test_phi

clean:
	rm -f test_blocks test_blocks.d test_phi test_phi.d

# Generated by -MMD; absent on the first build, hence the leading '-'.
-include $(wildcard *.d)
