Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/wasm/gate-irwasm.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / wasm / gate-irwasm.sh` 219 lines ยท 10046 bytes Raw Blame History 1 #!/bin/sh 2 # Host-only verification. Node is a read-only wasm oracle, never a generator. 3 set -eu 4 cd "$(dirname "$0")/../.." 5 B=build/seed/wasm 6 mkdir -p "$B" 7 fail() { printf 'FAIL %s\n' "$*"; exit 1; } 8 [ "$(uname -m)" = aarch64 ] || { echo 'NOT_RUN requires AArch64 Linux'; exit 3; } 9 command -v node >/dev/null || { echo 'NOT_RUN requires Node WebAssembly oracle'; exit 3; } 10 OMC=seed/out/omc 11 pin=`26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991` 12 [ "$(sha256sum "$OMC" | cut -d ' ' -f 1)" = "$pin" ] || fail 'compiler pin differs' 13 printf 'SOURCE %s\n' "$(git rev-parse HEAD)" 14 printf 'COMPILER %s\n' "$pin" 15 node --version 16 uname -sm 17 nice -n 19 "$OMC" < seed/wasm/irwasm.om > "$B/irwasm" 2> "$B/compile.err" 18 [ ! -s "$B/compile.err" ] || fail 'translator compiler stderr' 19 chmod +x "$B/irwasm" 20 for source in tests/one_layer/omegese/dev/*.omegese seed/wasm/*.unit.om; do 21 id=$(basename "$source" .omegese) 22 id=${id%.unit.om} 23 { printf 'ir\n'; cat "$source"; } > "$B/$id.input" 24 nice -n 19 "$OMC" < "$B/$id.input" > "$B/$id.ir" 25 nice -n 19 "$B/irwasm" < "$B/$id.ir" > "$B/$id.wasm" 26 nice -n 19 "$B/irwasm" < "$B/$id.ir" > "$B/$id.again.wasm" 27 cmp "$B/$id.wasm" "$B/$id.again.wasm" || fail "$id nondeterministic" 28 printf '%s\n' "$source" > "$B/$id.source" 29 echo "PASS $id deterministic" 30 done 31 # Each table row gets a real native program calling the same function and inputs. 32 # The dumper preserves every result bit, rather than comparing process-status bytes. 33 i=0 34 tab=$(printf '\t') 35 while IFS="$tab" read -r unit function result typed status; do 36 case "$unit" in ''|'#'*) continue ;; esac 37 i=$((i+1)) 38 source=$(cat "$B/$unit.source") 39 cat "$source" > "$B/case-$i.om" 40 cat >> "$B/case-$i.om" <<'DUMP' 41 global dumpbuf uchar 8 42 fn ir_dump x ulong to void 43 for j ulong 8 44 put dumpbuf j uchar and shr x mul j 8 255 45 end 46 p = ulong 0 47 while lt p 8 bound 8 48 k = write 1 dumpbuf p sub ulong 8 p 49 if le k 0 50 exit 90 51 end 52 p = add p ulong k 53 end 54 end 55 fn main to int 56 DUMP 57 actual= 58 if [ "$typed" != - ]; then 59 for arg in $(printf '%s' "$typed" | tr ',' ' '); do 60 type=${arg%%:*}; value=${arg#*:} 61 if [ "$type" = bool ]; then actual="$actual $value" 62 else actual="$actual $type $value"; fi 63 done 64 fi 65 case "$result" in 66 bool) printf 'if %s %s\nir_dump ulong 1\nelse\nir_dump ulong 0\nend\n' "$function" "$actual" ;; 67 void) printf '%s %s\nir_dump ulong 0\n' "$function" "$actual" ;; 68 byte|short|int|long) printf 'ir_dump bitcast ulong long %s %s\n' "$function" "$actual" ;; 69 uchar|ushort|uint|ulong) printf 'ir_dump ulong %s %s\n' "$function" "$actual" ;; 70 *) fail "unknown result $result" ;; 71 esac >> "$B/case-$i.om" 72 printf 'ret 0\nend\n' >> "$B/case-$i.om" 73 nice -n 19 "$OMC" < "$B/case-$i.om" > "$B/case-$i.native" 74 chmod +x "$B/case-$i.native" 75 set +e 76 timeout 10 "$B/case-$i.native" > "$B/case-$i.out" 77 rc=$? 78 set -e 79 printf '%s\n' "$rc" > "$B/case-$i.status" 80 [ "$rc" = "$status" ] || fail "case $i $unit.$function native exit $rc expected $status" 81 done < seed/wasm/cases.tsv 82 # The pinned simple fixture has BIN ADD at offsets 38,39. Assert before mutating. 83 [ "$(od -An -j 38 -N 2 -t u1 "$B/mutant.ir" | tr -s ' ' | tr -d '\n')" = ' 3 1' ] || fail 'mutant IR layout changed' 84 cp "$B/mutant.ir" "$B/mutant-flipped.ir" 85 printf '\002' | dd of="$B/mutant-flipped.ir" bs=1 seek=39 conv=notrunc status=none 86 "$B/irwasm" < "$B/mutant-flipped.ir" > "$B/mutant-flipped.wasm" 87 node seed/wasm/oracle.js "$B" seed/wasm/cases.tsv 88 set +e 89 node seed/wasm/oracle.js "$B" seed/wasm/cases.tsv --mutant-baseline > "$B/negative.log" 2>&1 90 rc=$? 91 set -e 92 [ "$rc" = 1 ] || fail "mutant comparison exited $rc instead of 1" 93 grep -q 'result mismatch' "$B/negative.log" || fail 'mutant failed for unrelated reason' 94 echo 'PASS parity checker rejects mutant substituted as baseline (exit 1)' 95 refuse() { 96 name=$1; expected=$2; class=$3 97 set +e 98 "$B/irwasm" < "$B/$name.ir" > "$B/$name.refused" 2> "$B/$name.err" 99 rc=$? 100 set -e 101 [ "$rc" = "$expected" ] || fail "$name exit $rc expected $expected" 102 [ ! -s "$B/$name.refused" ] || fail "$name emitted partial module" 103 printf 'irwasm: %s\n' "$class" > "$B/expected.err" 104 cmp "$B/expected.err" "$B/$name.err" || fail "$name wrong refusal name" 105 echo "PASS $name $class exit=$rc stdout=empty" 106 } 107 bytecase() { 108 name=$1; offset=$2; bytes=$3; code=$4; class=$5 109 cp "$B/mutant.ir" "$B/$name.ir" 110 printf '%b' "$bytes" | dd of="$B/$name.ir" bs=1 seek="$offset" conv=notrunc status=none 111 refuse "$name" "$code" "$class" 112 } 113 bytecase bad-magic 0 '\130' 20 MAGIC 114 bytecase version2 7 '\002' 21 VERSION 115 bytecase version6 7 '\006' 21 VERSION 116 bytecase unsupported-op 38 '\007' 24 UNSUPPORTED_OP 117 bytecase unknown-op 38 '\036' 24 UNSUPPORTED_OP 118 bytecase unsupported-tag 18 '\012' 25 UNSUPPORTED_TAG 119 bytecase unknown-tag 18 '\015' 25 UNSUPPORTED_TAG 120 bytecase bad-register 44 '\003' 26 INVALID 121 bytecase undefined-register 42 '\002' 26 INVALID 122 bytecase nonascii-name 11 '\377' 26 INVALID 123 bytecase oversized-count 8 '\041' 23 CAPACITY 124 size=$(wc -c < "$B/mutant.ir") 125 dd if="$B/mutant.ir" of="$B/truncated.ir" bs=1 count=$((size-1)) status=none 126 refuse truncated 22 TRUNCATED 127 : > "$B/empty.ir" 128 refuse empty 22 TRUNCATED 129 cp "$B/mutant.ir" "$B/trailing.ir" 130 printf x >> "$B/trailing.ir" 131 refuse trailing 27 TRAILING 132 dd if=/dev/zero of="$B/oversized.ir" bs=`2620252` count=1 status=none 133 refuse oversized 23 CAPACITY 134 printf 'PASS IRWASM native parity cases=%s deterministic mutant refusals\n' "$i" 135 # OSC IR v7 (spec 10): regions, f32/f64, RLOAD/RSTORE/BITCAST/RINIT. Units come 136 # from the independent hand writer seed/wasm/v7/writer.js and seed/wasm/v7cases.js; 137 # expected verdicts and outputs come from the independent oracle seed/wasm/v7/oracle.js. 138 V="$B/v7" 139 rm -rf "$V" 140 mkdir -p "$V/fx" "$V/rc" 141 [ -f seed/wasm/v7/oracle.js ] && [ -f seed/wasm/v7/writer.js ] || fail 'v7 oracle or writer missing' 142 node seed/wasm/v7/writer.js "$V/fx" > /dev/null 143 node seed/wasm/v7cases.js "$V/rc" > /dev/null 144 code() { 145 case $1 in 146 MAGIC) echo 20 ;; VERSION) echo 21 ;; TRUNCATED) echo 22 ;; CAPACITY) echo 23 ;; 147 UNSUPPORTED_OP) echo 24 ;; UNSUPPORTED_TAG) echo 25 ;; INVALID) echo 26 ;; TRAILING) echo 27 ;; 148 *) fail "oracle class $1" ;; 149 esac 150 } 151 accepts=0 152 refusals=0 153 for unit in "$V"/fx/*.unit "$V"/rc/*.unit; do 154 id=${unit%.unit} 155 set +e 156 verdict=$(node seed/wasm/v7/oracle.js check "$unit") 157 "$B/irwasm" < "$unit" > "$id.wasm" 2> "$id.err" 158 rc=$? 159 set -e 160 case $verdict in 161 ACCEPT*) 162 [ "$rc" = 0 ] || fail "v7 $id refused ($(cat "$id.err")) but oracle: $verdict" 163 "$B/irwasm" < "$unit" > "$id.again.wasm" 164 cmp "$id.wasm" "$id.again.wasm" || fail "v7 $id nondeterministic" 165 node -e 'new WebAssembly.Module(require("fs").readFileSync(process.argv[1]))' "$id.wasm" || 166 fail "v7 $id invalid wasm" 167 accepts=$((accepts + 1)) ;; 168 REFUSE*) 169 class=$(printf '%s\n' "$verdict" | cut -d ' ' -f 2) 170 [ "$rc" = "$(code "$class")" ] || fail "v7 $id exit $rc, oracle: $verdict" 171 [ ! -s "$id.wasm" ] || fail "v7 $id emitted partial module" 172 printf 'irwasm: %s\n' "$class" > "$V/expected.err" 173 cmp "$V/expected.err" "$id.err" || fail "v7 $id wrong refusal name" 174 refusals=$((refusals + 1)) ;; 175 *) fail "v7 $id oracle verdict: $verdict" ;; 176 esac 177 done 178 [ "$accepts" -gt 0 ] && [ "$refusals" -gt 0 ] || fail 'v7 fixture set empty' 179 echo "PASS v7 verdict parity accepts=$accepts (valid, deterministic) refusals=$refusals (class, exit, stdout=empty)" 180 runs=0 181 for script in "$V"/rc/*.script; do 182 id=${script%.script} 183 node seed/wasm/v7/oracle.js run "$id.unit" "$script" > "$id.oracle" 184 node seed/wasm/v7run.js "$id.wasm" "$script" > "$id.out" 185 [ -s "$id.oracle" ] || fail "v7 $id oracle printed nothing" 186 diff "$id.oracle" "$id.out" || fail "v7 $id run differs from oracle" 187 runs=$((runs + 1)) 188 done 189 lines=$(cat "$V"/rc/*.oracle | wc -l) 190 traps=$(cat "$V"/rc/*.oracle | grep -c ' TRAP$') 191 echo "PASS v7 run parity cases=$runs lines=$lines traps=$traps" 192 # RGBX gradient: the framebuffer bytes after fill() hash the same in wasm and the 193 # oracle, and a one-channel mutant and a channel-order mutant hash differently. 194 fbsum() { 195 sed -n '3p' "$1" | grep '^region fb ' | cut -d ' ' -f 3 | 196 node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const b=Buffer.from(s.trim(),"hex");if(b.length!==512)process.exit(1);console.log(require("crypto").createHash("sha256").update(b).digest("hex"))})' 197 } 198 rgbx=$(fbsum "$V/rc/rgbx.out") || fail 'rgbx framebuffer line' 199 [ "$rgbx" = "$(fbsum "$V/rc/rgbx.oracle")" ] || fail 'rgbx framebuffer hash differs' 200 for m in rgbx_mut_b rgbx_mut_order; do 201 [ "$(fbsum "$V/rc/$m.out")" != "$rgbx" ] || fail "$m not distinguished" 202 done 203 echo "PASS v7 RGBX framebuffer sha256=$rgbx; channel and order mutants differ" 204 # Out-of-bounds: index == count, count + 1, negative and wide indexes trap in 205 # both (case oob above). A translator with the bounds check removed must differ. 206 [ "$(grep -c '^boundchk ' seed/wasm/irwasm.om)" = 2 ] || fail 'bounds check call sites changed' 207 sed '/^boundchk /d' seed/wasm/irwasm.om > "$V/nobound.om" 208 nice -n 19 "$OMC" < "$V/nobound.om" > "$V/nobound" 2> "$V/nobound.err" 209 [ ! -s "$V/nobound.err" ] || fail 'bounds mutant compile stderr' 210 chmod +x "$V/nobound" 211 "$V/nobound" < "$V/rc/oob.unit" > "$V/nobound.wasm" 212 node seed/wasm/v7run.js "$V/nobound.wasm" "$V/rc/oob.script" > "$V/nobound.out" 213 if diff "$V/rc/oob.oracle" "$V/nobound.out" > "$V/nobound.diff"; then 214 fail 'bounds-check mutant not caught' 215 fi 216 grep -q '^< .* TRAP$' "$V/nobound.diff" || fail 'bounds mutant differs for an unrelated reason' 217 echo "PASS v7 OOB traps=$(grep -c ' TRAP$' "$V/rc/oob.oracle"); no-bounds mutant caught ($(grep -c '^>' "$V/nobound.diff") differing lines)" 218 sha256sum seed/wasm/v7cases.js seed/wasm/v7run.js seed/wasm/v7/oracle.js seed/wasm/v7/writer.js 219 sha256sum seed/wasm/irwasm.om "$B/irwasm" seed/wasm/cases.tsv