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
omega-mv / tests / checker2 / blast_native.sh
| 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 | # Bit-blaster semantics against the producer's compiled code (omega#446, finding 4 of the PR #448 |
| 18 | # review). Writes one tiny OSC program per blastable operation and type, compiles each with oscc |
| 19 | # (run as a black box: IR bytes, AArch64 code and entry table), adds the LRAT gate programs, and |
| 20 | # runs test_c2_blast_native, which compares checker2's CNF with the code input by input (see that |
| 21 | # file for the method and the negative controls). |
| 22 | # op_<op>_<T> fn f(a: T, b: T, c: T) -> T ensures result != c { return a <op> b; } |
| 23 | # add sub mul and or xor shl (all 8 integer types), shr (unsigned only) |
| 24 | # op_<cmp>_<T> fn f(a: T, b: T, c: bool) -> bool ensures result != c { return a <cmp> b; } |
| 25 | # op_neg_<T> (signed), op_bnot_<T>, op_lnot_bool, op_land_bool, op_lor_bool, op_beq_bool |
| 26 | # op_cast_<S>_<T> every ordered pair of distinct integer types |
| 27 | # Any program oscc refuses, or that checker2 does not blast, fails the run. |
| 28 | # Usage: blast_native.sh <oscc> <test_c2_blast_native> <work-dir> |
| 29 | set -u |
| 30 | OSCC=$1 H=$2 W=$3 |
| 31 | D=$(dirname "$0")/lrat |
| 32 | rm -rf "$W" && mkdir -p "$W/src" || exit 2 |
| 33 | types="u8 u16 u32 u64 i8 i16 i32 i64" |
| 34 | fail=0 |
| 35 | gen() { # gen <name> <params> <ret> <expr> |
| 36 | printf 'fn f(%s) -> %s ensures result != c {\n return %s;\n}\n' "$2" "$3" "$4" >"$W/src/$1.osc" |
| 37 | } |
| 38 | for t in $types; do |
| 39 | for op in add:+ sub:- mul:'*' and:'&' or:'|' xor:'^' shl:'<<' shr:'>>'; do |
| 40 | n=${op%%:*} s=${op#*:} |
| 41 | case "$n:$t" in shr:i*) continue ;; esac |
| 42 | gen "op_${n}_$t" "a: $t, b: $t, c: $t" "$t" "a $s b" |
| 43 | done |
| 44 | for op in eq:== ne:!= lt:'<' le:'<=' gt:'>' ge:'>='; do |
| 45 | gen "op_${op%%:*}_$t" "a: $t, b: $t, c: bool" bool "a ${op#*:} b" |
| 46 | done |
| 47 | case $t in i*) gen "op_neg_$t" "a: $t, c: $t" "$t" "-a" ;; esac |
| 48 | gen "op_bnot_$t" "a: $t, c: $t" "$t" "~a" |
| 49 | for t2 in $types; do |
| 50 | [ "$t" = "$t2" ] || gen "op_cast_${t}_$t2" "a: $t, c: $t2" "$t2" "a as $t2" |
| 51 | done |
| 52 | done |
| 53 | gen op_lnot_bool "a: bool, c: bool" bool "!a" |
| 54 | gen op_land_bool "a: bool, b: bool, c: bool" bool "a && b" |
| 55 | gen op_lor_bool "a: bool, b: bool, c: bool" bool "a || b" |
| 56 | gen op_beq_bool "a: bool, b: bool, c: bool" bool "a == b" |
| 57 | cp "$D"/*.osc "$W/src/" |
| 58 | for src in "$W"/src/*.osc; do |
| 59 | b=$(basename "$src" .osc) |
| 60 | "$OSCC" "$src" "$W/$b" >"$W/src/$b.log" 2>&1 || { echo "blast_native: FAIL oscc refused $b: $(head -c 300 "$W/src/$b.log")"; fail=$((fail + 1)); } |
| 61 | done |
| 62 | # negative controls: CNF of the first program against the code of the second (same signature) |
| 63 | cat >"$W/controls" <<'CTL' |
| 64 | op_add_u8 op_sub_u8 |
| 65 | op_and_u16 op_or_u16 |
| 66 | op_shl_u8 op_shr_u8 |
| 67 | op_lt_i8 op_le_i8 |
| 68 | op_mul_i64 op_add_i64 |
| 69 | op_neg_i32 op_bnot_i32 |
| 70 | op_eq_u64 op_ne_u64 |
| 71 | op_cast_i8_u16 op_cast_i8_i16 |
| 72 | CTL |
| 73 | echo "blast_native: $(ls "$W"/src/*.osc | wc -l) programs written, $fail refused by oscc" |
| 74 | "$H" "$W" || fail=$((fail + 1)) |
| 75 | [ "$fail" -eq 0 ] || { echo "blast_native: FAIL"; exit 1; } |
| 76 | echo "blast_native: PASS" |