interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tests / compiler / legacy_a64_callers.sh

74 lines · 3673 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# OSC-2 item 4: the legacy AArch64 writer (src/aarch64_encoder.c) takes no new callers.
18# OSC-2 slice; not a general Omega compiler; no self-hosting.
19# Lists every C source/header in the tree (tracked plus untracked, not ignored) that
20# includes aarch64_encoder.h or names an aarch64_emit_* function and compares the set
21# with tests/compiler/legacy_a64_allowlist.txt. Exit 1 with
22# A64_LEGACY_NEW_CALLER <file> a file not on the frozen list uses the writer
23# A64_LEGACY_ALLOWLIST_STALE <file> a listed file no longer uses it (drop the line)
24# Usage: legacy_a64_callers.sh [--selftest]
25# --selftest first proves both refusals fire on a synthetic tree (a new includer, a
26# new direct caller, a stale list line), then checks the real tree.
27# Last line on success: OSC2_LEGACY_CALLERS_PASS callers=<n> [selftest=3/3]
28set -eu
29ROOT=$(cd "$(dirname "$0")/../.." && pwd -P)
30cd "$ROOT"
31LIST=tests/compiler/legacy_a64_allowlist.txt
32T=$(mktemp -d)
33trap 'rm -rf "$T"' EXIT
34PAT='aarch64_encoder\.h|aarch64_emit_[a-z0-9_]+'
35
36# compare <file-list> <allowlist> <out>: writes the refusal lines to <out>, returns 1 if any
37compare() {
38 : >"$T/found"
39 while IFS= read -r f; do
40 [ -f "$f" ] || continue
41 if grep -qE "$PAT" "$f"; then echo "$f" >>"$T/found"; fi
42 done <"$1"
43 LC_ALL=C sort -u "$T/found" >"$T/found.s"
44 grep -v '^#' "$2" | grep -v '^[[:space:]]*$' | LC_ALL=C sort -u >"$T/allow.s"
45 LC_ALL=C comm -23 "$T/found.s" "$T/allow.s" | sed 's/^/A64_LEGACY_NEW_CALLER /' >"$3"
46 LC_ALL=C comm -13 "$T/found.s" "$T/allow.s" | sed 's/^/A64_LEGACY_ALLOWLIST_STALE /' >>"$3"
47 [ ! -s "$3" ]
48}
49
50ST=
51if [ "${1:-}" = --selftest ]; then
52 mkdir -p "$T/s"
53 printf '#include "aarch64_encoder.h"\n' >"$T/s/new_include.c"
54 printf 'int f(void) { return aarch64_emit_ret(0, 0, 0); }\n' >"$T/s/new_call.c"
55 printf 'int g(void) { return 0; }\n' >"$T/s/clean.c"
56 printf '%s\n' "$T/s/new_include.c" "$T/s/new_call.c" "$T/s/clean.c" >"$T/s/files"
57 printf '# test list\n%s\n' "$T/s/clean.c" >"$T/s/allow"
58 ok=0
59 if compare "$T/s/files" "$T/s/allow" "$T/s/out"; then :; fi
60 grep -qx "A64_LEGACY_NEW_CALLER $T/s/new_include.c" "$T/s/out" && ok=$((ok + 1))
61 grep -qx "A64_LEGACY_NEW_CALLER $T/s/new_call.c" "$T/s/out" && ok=$((ok + 1))
62 grep -qx "A64_LEGACY_ALLOWLIST_STALE $T/s/clean.c" "$T/s/out" && ok=$((ok + 1))
63 [ "$(wc -l <"$T/s/out" | tr -d ' ')" = 3 ] || ok=0
64 if [ "$ok" != 3 ]; then cat "$T/s/out"; echo "selftest: refusals did not fire ($ok/3)"; echo "OSC2_LEGACY_CALLERS_FAIL"; exit 1; fi
65 ST=" selftest=3/3"
66fi
67
68if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
69 git ls-files --cached --others --exclude-standard -- '*.c' '*.h' >"$T/files"
70else
71 find . -path ./build -prune -o -type f \( -name '*.c' -o -name '*.h' \) -print | sed 's|^\./||' >"$T/files"
72fi
73if ! compare "$T/files" "$LIST" "$T/out"; then cat "$T/out"; echo "OSC2_LEGACY_CALLERS_FAIL"; exit 1; fi
74echo "OSC2_LEGACY_CALLERS_PASS callers=$(wc -l <"$T/found.s" | tr -d ' ')$ST"