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 / seed / omc / gate-ir.sh

654 lines · 21843 bytes Raw Blame History
1#!/bin/sh
2# Experimental scalar IR checkpoint; not the completed R6 gate.
3# Requires C-built omegese/omega_emit/checker2 as comparison oracles only.
4set -eu
5cd "$(dirname "$0")/../.."
6B=build/seed/ir
7mkdir -p "$B"
8fail() { printf 'FAIL %s\n' "$*"; exit 1; }
9seed/rung4/om4.bin < seed/omc/omc.om > "$B/stage1"
10chmod +x "$B/stage1"
11"$B/stage1" < seed/omc/omc.om > "$B/stage2"
12chmod +x "$B/stage2"
13"$B/stage2" < seed/omc/omc.om > "$B/stage3"
14cmp "$B/stage1" "$B/stage2"
15cmp "$B/stage2" "$B/stage3"
16echo "PASS fixpoint $(sha256sum "$B/stage3")"
17n=0
18for f in tests/one_layer/omegese/dev/*.omegese; do
19 id=$(basename "$f" .omegese)
20 build/omegese/omegese emit "$f" "$B/$id.json"
21 build/omega_emit/omega_emit emit "$B/$id.json" "$B/$id.oracle"
22 { printf 'ir\n'; cat "$f"; } > "$B/$id.input"
23 timeout 5 "$B/stage2" < "$B/$id.input" > "$B/$id.got"
24 cmp "$B/$id.oracle" "$B/$id.got" || fail "$id byte mismatch"
25 build/checker2/checker2 check "$B/$id.got" > "$B/$id.check"
26 grep -q '^checker2=ACCEPT ' "$B/$id.check" || fail "$id checker refusal"
27 echo "PASS $id identical; checker2 ACCEPT"
28 n=$((n+1))
29done
30[ "$n" = 10 ] || fail "ran $n expected 10"
31# Exercise the result comparison: change the arithmetic operation while preserving a valid program.
32sed 's/ret mul a b/ret add a b/' tests/one_layer/omegese/dev/dev05.omegese > "$B/mut.om"
33{ printf 'ir\n'; cat "$B/mut.om"; } > "$B/mut.input"
34timeout 5 "$B/stage2" < "$B/mut.input" > "$B/mut.ir"
35if cmp -s "$B/mut.ir" "$B/dev05.oracle"; then fail 'mutant did not change IR'; fi
36echo 'PASS mul-to-add mutant differs'
37# IR mode must refuse what it cannot lower, never skip a declaration silently.
38ir_refuse() { # name expected-error source
39 printf '%s\n' "$3" > "$B/$1.om"
40 set +e
41 timeout 5 "$B/stage2" < "$B/$1.om" > "$B/$1.out" 2> "$B/$1.err"
42 crc=$?
43 set -e
44 [ "$crc" = "$2" ] || fail "$1: exit $crc, wanted $2"
45 echo "PASS $1 refused $2"
46}
47ir_refuse struct_decl 9 'ir
48struct S a uchar end
49fn main to int
50ret 0
51end'
52ir_refuse global_decl 9 'ir
53global g uchar 4
54fn main to int
55ret 0
56end'
57ir_refuse text_decl 9 'ir
58text t "x"
59fn main to int
60ret 0
61end'
62ir_refuse float_use 3 'ir
63fn main to int
64x = f64 1.0
65ret 0
66end'
67ir_refuse continue_use 3 'ir
68fn main to int
69continue
70end'
71# Contract lines are not IR v1 statements: refuse with 30, never read them as a local (#791).
72ir_refuse requires_line 30 'ir
73fn f x uint to uint
74requires lt x 10
75ret x
76end'
77ir_refuse ensures_line 30 'ir
78fn f x uint to uint
79ensures lt x 10
80ret x
81end'
82ir_refuse invariant_line 30 'ir
83fn f x uint to uint
84invariant lt x 10
85ret x
86end'
87# Integer constants fold to the IR of their literal; float constants are still refused.
88printf 'ir\nconst N uint 5\nfn f to uint\nret N\nend\n' > "$B/c1.om"
89printf 'ir\nfn f to uint\nret uint 5\nend\n' > "$B/c2.om"
90timeout 5 "$B/stage2" < "$B/c1.om" > "$B/c1.ir"
91timeout 5 "$B/stage2" < "$B/c2.om" > "$B/c2.ir"
92cmp -s "$B/c1.ir" "$B/c2.ir" || fail 'integer constant IR differs from its literal'
93echo 'PASS integer constant folds to the literal IR'
94# Constants in trap, bound and for positions fold to the same IR as literals.
95ir_fold() { # name const-source literal-source
96 printf '%b\n' "$2" > "$B/$1c.om"
97 printf '%b\n' "$3" > "$B/$1l.om"
98 timeout 5 "$B/stage2" < "$B/$1c.om" > "$B/$1c.ir"
99 timeout 5 "$B/stage2" < "$B/$1l.om" > "$B/$1l.ir"
100 cmp -s "$B/$1c.ir" "$B/$1l.ir" || fail "$1 constant IR differs from its literal"
101 echo "PASS $1 constant folds to the literal IR"
102}
103ir_fold trap_const 'ir\nconst T uint 2\nfn f to uint\ntrap T\nend' 'ir\nfn f to uint\ntrap 2\nend'
104ir_fold bound_const 'ir\nconst B ulong 3\nfn f to uint\nx = uint 0\nwhile lt x uint 2 bound B\nx = add x uint 1\nend\nret x\nend' 'ir\nfn f to uint\nx = uint 0\nwhile lt x uint 2 bound 3\nx = add x uint 1\nend\nret x\nend'
105ir_fold for_const 'ir\nconst K ulong 4\nfn f to uint\nx = uint 0\nfor i ulong K\nx = add x uint 1\nend\nret x\nend' 'ir\nfn f to uint\nx = uint 0\nfor i ulong 4\nx = add x uint 1\nend\nret x\nend'
106# for ... bound N: a constant N folds to its literal; an explicit bound 1000000 is the unbounded default.
107ir_fold for_bound_const 'ir\nconst B ulong 3\nfn f a uint to uint\nx = uint 0\nfor i uint a bound B\nx = add x uint 1\nend\nret x\nend' 'ir\nfn f a uint to uint\nx = uint 0\nfor i uint a bound 3\nx = add x uint 1\nend\nret x\nend'
108ir_fold for_bound_default 'ir\nfn f a uint to uint\nx = uint 0\nfor i uint a bound 1000000\nx = add x uint 1\nend\nret x\nend' 'ir\nfn f a uint to uint\nx = uint 0\nfor i uint a\nx = add x uint 1\nend\nret x\nend'
109ir_refuse for_bound_zero 8 'ir
110fn f a uint to uint
111for i uint a bound 0
112end
113ret a
114end'
115ir_refuse for_bound_over 8 'ir
116fn f a uint to uint
117for i uint 3 bound 9223372036854775808
118end
119ret a
120end'
121# A number count with a bound gets the counter guard, which checker2 proves terminating.
122printf 'ir\nfn f a uint to uint\ns = uint 0\nfor i uint 7 bound 5\ns = add s a\nend\nret s\nend\n' > "$B/forbn.om"
123timeout 5 "$B/stage2" < "$B/forbn.om" > "$B/forbn.ir"
124build/checker2/checker2 check "$B/forbn.ir" > "$B/forbn.check"
125grep -q '^checker2=ACCEPT ' "$B/forbn.check" || fail 'for_num_bound checker refusal'
126echo 'PASS for_num_bound guarded; checker2 ACCEPT'
127# IR bound range = the C oracle's (omegese.c, 1..1000000) = the guard range checker2 proves
128# (c2_check.c "loop bounds"): bound 1000000 is emitted and accepted, bound 1000001 is error 8.
129printf 'fn f a uint to uint\nx = uint 0\nwhile lt x a bound 1000000\nx = add x uint 1\nend\nret x\nend\n' > "$B/wbmax.omegese"
130build/omegese/omegese emit "$B/wbmax.omegese" "$B/wbmax.json" > /dev/null
131build/omega_emit/omega_emit emit "$B/wbmax.json" "$B/wbmax.oracle" > /dev/null
132{ printf 'ir\n'; cat "$B/wbmax.omegese"; } > "$B/wbmax.om"
133timeout 5 "$B/stage2" < "$B/wbmax.om" > "$B/wbmax.ir"
134cmp -s "$B/wbmax.oracle" "$B/wbmax.ir" || fail 'while_bound_max differs from the oracle'
135build/checker2/checker2 check "$B/wbmax.ir" > "$B/wbmax.check"
136grep -q '^checker2=ACCEPT ' "$B/wbmax.check" || fail 'while_bound_max checker refusal'
137echo 'PASS while_bound_max identical; checker2 ACCEPT'
138printf 'fn f a uint to uint\nx = uint 0\nwhile lt x a bound 1000001\nx = add x uint 1\nend\nret x\nend\n' > "$B/wbover.omegese"
139if build/omegese/omegese emit "$B/wbover.omegese" "$B/wbover.json" > /dev/null 2>&1; then fail 'oracle accepted while bound 1000001'; fi
140ir_refuse while_bound_over 8 'ir
141fn f a uint to uint
142x = uint 0
143while lt x a bound 1000001
144x = add x uint 1
145end
146ret x
147end'
148printf 'ir\nfn f a uint to uint\nx = uint 0\nfor i uint a bound 1000000\nx = add x uint 1\nend\nret x\nend\n' > "$B/fbmax.om"
149timeout 5 "$B/stage2" < "$B/fbmax.om" > "$B/fbmax.ir"
150build/checker2/checker2 check "$B/fbmax.ir" > "$B/fbmax.check"
151grep -q '^checker2=ACCEPT ' "$B/fbmax.check" || fail 'for_bound_max checker refusal'
152echo 'PASS for_bound_max guarded; checker2 ACCEPT'
153ir_refuse for_bound_c2 8 'ir
154fn f a uint to uint
155x = uint 0
156for i uint a bound 1000001
157x = add x uint 1
158end
159ret x
160end'
161# IR count range = the C oracle's (omegese.c for_line, 0..1000000), so an unguarded loop over a number never
162# counts past what checker2 proves: count 1000000 is emitted identical to the oracle and accepted; 1000001 and a
163# minus sign (-1, -0) are refused by both; an integer constant count is held to the same range (error 8).
164printf 'fn f to ulong\ns = ulong 0\nfor i ulong 1000000\ns = add s i\nend\nret s\nend\n' > "$B/fcmax.omegese"
165build/omegese/omegese emit "$B/fcmax.omegese" "$B/fcmax.json" > /dev/null
166build/omega_emit/omega_emit emit "$B/fcmax.json" "$B/fcmax.oracle" > /dev/null
167{ printf 'ir\n'; cat "$B/fcmax.omegese"; } > "$B/fcmax.om"
168timeout 5 "$B/stage2" < "$B/fcmax.om" > "$B/fcmax.ir"
169cmp -s "$B/fcmax.oracle" "$B/fcmax.ir" || fail 'for_count_max differs from the oracle'
170build/checker2/checker2 check "$B/fcmax.ir" > "$B/fcmax.check"
171grep -q '^checker2=ACCEPT ' "$B/fcmax.check" || fail 'for_count_max checker refusal'
172echo 'PASS for_count_max identical; checker2 ACCEPT'
173for v in 1000001 -1 -0; do
174 printf 'fn f to long\ns = long 0\nfor i long %s\ns = add s i\nend\nret s\nend\n' "$v" > "$B/fcbad.omegese"
175 if build/omegese/omegese emit "$B/fcbad.omegese" "$B/fcbad.json" > /dev/null 2>&1; then fail "oracle accepted for count $v"; fi
176done
177ir_refuse for_count_over 8 'ir
178fn f to ulong
179s = ulong 0
180for i ulong 1000001
181s = add s i
182end
183ret s
184end'
185ir_refuse for_count_neg 8 'ir
186fn f to long
187s = long 0
188for i long -1
189s = add s i
190end
191ret s
192end'
193ir_refuse for_count_negzero 8 'ir
194fn f to long
195s = long 0
196for i long -0
197s = add s i
198end
199ret s
200end'
201ir_refuse for_count_const_over 8 'ir
202const K ulong 1000001
203fn f to ulong
204s = ulong 0
205for i ulong K
206s = add s i
207end
208ret s
209end'
210ir_refuse float_const 9 'ir
211const H f64 0.1
212fn f to f64
213ret H
214end'
215ir_refuse call_self 3 'ir
216fn f to uint
217ret f
218end'
219ir_refuse call_forward 3 'ir
220fn f to uint
221ret g
222end
223fn g to uint
224ret uint 1
225end'
226ir_refuse call_nonvoid_stmt 7 'ir
227fn inc a uint to uint
228ret add a uint 1
229end
230fn f to uint
231inc uint 4
232ret uint 2
233end'
234ir_refuse call_void_value 7 'ir
235fn sink a uint to void
236ret
237end
238fn f to uint
239x = sink uint 1
240ret uint 2
241end'
242ir_refuse call_arg_type 7 'ir
243fn inc a uchar to uint
244ret uint 1
245end
246fn f to uint
247ret inc uint 4
248end'
249ir_refuse call_arg_local 7 'ir
250fn inc a uchar to uint
251ret uint 1
252end
253fn f to uint
254x = uint 4
255ret inc x
256end'
257ir_refuse call_result_type 7 'ir
258fn inc a uint to uint
259ret add a uint 1
260end
261fn f to uchar
262ret inc uint 4
263end'
264ir_refuse break_outside 9 'ir
265fn f to uint
266break
267end'
268ir_refuse after_break 17 'ir
269fn f to uint
270while lt uint 1 uint 2 bound 3
271break
272ret uint 0
273end
274ret uint 0
275end'
276ir_refuse bin_type_local 7 'ir
277fn f to uint
278s = uint 1
279i = ulong 2
280x = add s i
281ret uint 0
282end'
283ir_refuse bin_bool 7 'ir
284fn f to uint
285x = add bool true true
286ret uint 0
287end'
288ir_refuse bin_shift_bool 7 'ir
289fn f to ulong
290ret shl ulong 1 true
291end'
292ir_refuse bin_result_type 7 'ir
293fn f to uchar
294ret add uint 1 uint 2
295end'
296ir_refuse cmp_assign_type 7 'ir
297fn f to uint
298x = uint 1
299x = eq x x
300ret x
301end'
302ir_refuse bool_result 7 'ir
303fn f to uint
304ret true
305end'
306ir_refuse neg_bool 7 'ir
307fn f to uint
308ret neg true
309end'
310ir_refuse cond_type 7 'ir
311fn f to uint
312x = uint 1
313if x
314ret 1
315end
316ret 0
317end'
318ir_refuse ret_type_local 7 'ir
319fn f to uchar
320x = uint 1
321ret x
322end'
323ir_refuse neg_bool_local 7 'ir
324fn f to uint
325x = neg true
326ret uint 0
327end'
328# Validation: every word of a line is read, names follow scope, and what IR v1 cannot lower is refused.
329ir_refuse trailing_value 5 'ir
330fn f a uint to uint
331x = add a 1 7
332ret x
333end'
334ir_refuse untyped_new 11 'ir
335fn f a uint to uint
336foo 1 a 0 1
337ret a
338end'
339ir_refuse missing_operand 4 'ir
340fn f a uint to uint
341x = add a
342ret x
343end'
344ir_refuse bare_neg 11 'ir
345fn f to ulong
346ret neg 5
347end'
348ir_refuse end_trailing 5 'ir
349fn f a uint to uint
350if eq a 0
351ret 1
352end a
353ret a
354end'
355ir_refuse while_trailing 5 'ir
356fn f to uint
357x = uint 0
358while lt x uint 3 x
359x = add x uint 1
360end
361ret x
362end'
363ir_refuse ret_missing 4 'ir
364fn f to uint
365ret
366end'
367ir_refuse ret_void_value 5 'ir
368fn f to void
369ret uint 1
370end'
371ir_refuse keyword_name 16 'ir
372fn f to uint
373add = uint 1
374ret uint 0
375end'
376ir_refuse stmt_number 16 'ir
377fn f to uint
3785
379ret uint 0
380end'
381ir_refuse shadow_param_for 10 'ir
382fn f n uint to uint
383for n uint 3
384end
385ret n
386end'
387ir_refuse shadow_nested_for 10 'ir
388fn f n uint to uint
389s = uint 0
390for i uint n
391for i uint 2
392s = add s i
393end
394end
395ret s
396end'
397ir_refuse param_dup 10 'ir
398fn f a uint a uint to uint
399ret a
400end'
401ir_refuse param_fn_name 10 'ir
402fn g to uint
403ret uint 1
404end
405fn f g uint to uint
406ret g
407end'
408ir_refuse param_self_name 10 'ir
409fn f f uint to uint
410ret f
411end'
412ir_refuse scope_if 3 'ir
413fn f n uint to uint
414if gt n 0
415y = uint 3
416end
417ret y
418end'
419ir_refuse scope_else 3 'ir
420fn f n uint to uint
421if gt n 0
422y = uint 3
423ret y
424else
425ret y
426end
427ret n
428end'
429ir_refuse scope_for 3 'ir
430fn f to uint
431for i uint 3
432end
433ret i
434end'
435ir_refuse fallthrough 18 'ir
436fn f a uint to uint
437if eq a 0
438ret 1
439end
440end'
441ir_refuse float_param 9 'ir
442fn f a f64 to f64
443ret a
444end'
445ir_refuse float_ret 9 'ir
446fn f a uint to f64
447ret a
448end'
449ir_refuse else_twice 15 'ir
450fn f a uint to uint
451if eq a 0
452ret 1
453else
454ret 2
455else
456ret 3
457end
458end'
459ir_refuse else_outside 15 'ir
460fn f to uint
461else
462ret uint 0
463end'
464ir_refuse eof_in_fn 15 'ir
465fn f to uint
466ret uint 0'
467ir_refuse range_typed 8 'ir
468fn f to uchar
469ret 300
470end'
471ir_refuse range_bare 8 'ir
472fn f a uchar to uchar
473ret add a 300
474end'
475ir_refuse range_bare_left 8 'ir
476fn f a uchar to uchar
477ret sub 256 a
478end'
479ir_refuse range_negative 8 'ir
480fn f to uint
481ret uint -1
482end'
483# Locals, parameters and for counters are at most 8 bytes (13, as native); a word over 8 bytes is never a
484ir_refuse cast_lit_range 8 'ir
485fn f to uchar
486ret uchar 256
487end'
488ir_refuse cast_opnd_range 8 'ir
489fn f c uchar to ulong
490ret ulong sub c 300
491end'
492ir_refuse cast_signed_range 8 'ir
493fn f c byte to long
494ret long sub c -129
495end'
496ir_refuse cast_bool_num 9 'ir
497fn f c uchar to bool
498ret bool c
499end'
500ir_refuse cast_num_bool 9 'ir
501fn f b bool to ulong
502ret ulong b
503end'
504ir_refuse cast_cmp_bool 9 'ir
505fn f a uint b uint to ulong
506ret ulong eq a b
507end'
508ir_refuse long_local 13 'ir
509fn f n uint to uint
510counterxy = add n uint 1
511ret counterxy
512end'
513ir_refuse long_param 13 'ir
514fn f counterxy uint to uint
515ret counterxy
516end'
517ir_refuse long_for 13 'ir
518fn f to uint
519for counterxy uint 3
520end
521ret uint 0
522end'
523ir_refuse long_prefix_ref 3 'ir
524fn f n uint to uint
525counterx = add n uint 1
526ret counterxy
527end'
528# Same IR from two spellings: a note after the path ended is skipped like any note.
529ir_same() { # name source-a source-b
530 printf '%b\n' "$2" > "$B/$1a.om"
531 printf '%b\n' "$3" > "$B/$1b.om"
532 timeout 5 "$B/stage2" < "$B/$1a.om" > "$B/$1a.ir"
533 timeout 5 "$B/stage2" < "$B/$1b.om" > "$B/$1b.ir"
534 cmp -s "$B/$1a.ir" "$B/$1b.ir" || fail "$1 IR differs between the two spellings"
535 echo "PASS $1 same IR"
536}
537ir_same note_dead 'ir\nfn f to uint\nret uint 1\nnote after the path ended\nend' 'ir\nfn f to uint\nret uint 1\nend'
538
539# Multi-function units with calls: byte-identical to the C oracle and checker2 ACCEPT.
540ir_multi() { # name source
541 printf '%b\n' "$2" > "$B/$1.omegese"
542 build/omegese/omegese emit "$B/$1.omegese" "$B/$1.json"
543 build/omega_emit/omega_emit emit "$B/$1.json" "$B/$1.oracle"
544 { printf 'ir\n'; cat "$B/$1.omegese"; } > "$B/$1.input"
545 timeout 5 "$B/stage2" < "$B/$1.input" > "$B/$1.got"
546 cmp -s "$B/$1.oracle" "$B/$1.got" || fail "$1 multi-function IR differs"
547 build/checker2/checker2 check "$B/$1.got" > "$B/$1.check"
548 grep -q '^checker2=ACCEPT ' "$B/$1.check" || fail "$1 checker refusal"
549 echo "PASS $1 IR identical; checker2 ACCEPT"
550}
551ir_multi call_value 'fn inc a uint to uint\nret add a uint 1\nend\nfn f to uint\nret inc uint 4\nend'
552ir_multi call_void 'fn sink a uint to void\nret\nend\nfn f to uint\nsink uint 1\nret uint 2\nend'
553ir_multi call_zero 'fn z to uint\nret uint 1\nend\nfn f to uint\nret z\nend'
554ir_multi call_two 'fn add2 a uint b uint to uint\nret add a b\nend\nfn f to uint\nret add2 uint 3 uint 4\nend'
555ir_multi call_long 'fn increment_one a uint to uint\nret add a uint 1\nend\nfn f to uint\nret increment_one uint 4\nend'
556ir_multi call_nested 'fn inc a uint to uint\nret add a uint 1\nend\nfn f to uint\nret inc inc uint 4\nend'
557ir_multi call_expr 'fn inc a uint to uint\nret add a uint 1\nend\nfn f to uint\nret add inc uint 1 inc uint 2\nend'
558ir_multi call_loop 'fn add1 a uint to uint\nret add a uint 1\nend\nfn f to uint\nx = uint 0\nwhile lt x uint 3 bound 8\nx = add1 x\nend\nret x\nend'
559ir_multi call_six 'fn sum6 a uint b uint c uint d uint e uint f uint to uint\nret add add add add add a b c d e f\nend\nfn f to uint\nret sum6 uint 1 uint 2 uint 3 uint 4 uint 5 uint 6\nend'
560ir_multi break_while 'fn f to uint\nx = uint 0\nwhile lt x uint 10 bound 100\nif eq x uint 3\nbreak\nend\nx = add x uint 1\nend\nret x\nend'
561ir_multi break_for 'fn f to uint\ns = uint 0\nfor i ulong 10\nif eq i ulong 3\nbreak\nend\ns = add s uint i\nend\nret s\nend'
562ir_multi break_nested 'fn f to uint\nx = uint 0\nwhile lt x uint 5 bound 20\ny = uint 0\nwhile lt y uint 5 bound 20\nif eq y uint 2\nbreak\nend\ny = add y uint 1\nend\nx = add x y\nend\nret x\nend'
563ir_multi shift_mixed 'fn f to ulong\nret shl ulong 1 uint 3\nend'
564ir_multi cmp_assign 'fn f to bool\nx = lt uint 1 uint 2\nx = eq uint 1 uint 1\nret x\nend'
565ir_multi cast_ret 'fn f to uchar\nret uchar uint 1\nend'
566ir_multi cast_wide 'fn f c uchar to ulong\nret ulong sub c 48\nend'
567ir_multi cast_left 'fn f c uchar to ulong\nret ulong sub 255 c\nend'
568ir_multi cast_u2s 'fn f c uchar to long\nret long sub c 48\nend'
569ir_multi cast_s2s 'fn f c byte to long\nret long add c 1\nend'
570ir_multi cast_s2u 'fn f c byte to ulong\nret ulong sub c 1\nend'
571ir_multi cast_narrow 'fn f x ulong to uchar\nret uchar sub x 1\nend'
572ir_multi cast_narrow_s 'fn f x long to byte\nret byte add x 1\nend'
573ir_multi cast_same_ty 'fn f x uint to uint\nret uint add x 1\nend'
574ir_multi cast_un 'fn f c uchar to ulong\nret ulong not c\nend'
575ir_multi cast_call 'fn g a uchar to uchar\nret add a 1\nend\nfn f c uchar to ulong\nret ulong g c\nend'
576ir_multi cast_assign 'fn f c uchar to ulong\nx = ulong sub c 48\nret x\nend'
577ir_multi cast_nested 'fn f c uchar to ulong\nret ulong uint mul c 2\nend'
578ir_multi cast_arg 'fn g a ulong to ulong\nret add a 1\nend\nfn f c uchar to ulong\nret g ulong sub c 48\nend'
579ir_multi cast_lit_var 'fn f to uint\nx = uint 5\nret uint x\nend'
580ir_multi cast_nest_var 'fn f x uint to uint\nret uint uint x\nend'
581ir_multi cast_same_assign 'fn f x uint to uint\ny = uint x\nret y\nend'
582ir_multi cast_same_param 'fn f x uint to uint\nret uint x\nend'
583ir_multi cast_neg_lit 'fn f c byte to long\nret long sub c -128\nend'
584ir_multi cast_ulong_max 'fn f to ulong\nret ulong 18446744073709551615\nend'
585ir_multi cast_cond 'fn f c uchar to uint\nif lt ulong c 10\nret 1\nend\nret 0\nend'
586# A same-type cast of an integer or bool constant is the constant itself (the oracle's konst rule), not a mov.
587ir_multi cast_same_konst 'fn f to uint\nret uint uint 5\nend'
588ir_multi cast_same_bool 'fn f to bool\nret bool true\nend'
589ir_multi cast_same_arg 'fn g a ulong to ulong\nret add a 1\nend\nfn f to ulong\nret g ulong ulong 7\nend'
590ir_multi bool_and 'fn f a bool b bool to bool\nret and a b\nend'
591ir_multi bool_or 'fn f a bool b bool to bool\nret or a b\nend'
592ir_multi bool_xor 'fn f a bool b bool to bool\nret xor a b\nend'
593ir_multi void_fall 'fn sink a uint to void\nend\nfn f to uint\nsink uint 1\nret uint 2\nend'
594ir_multi for_reuse 'fn f to uint\ns = uint 0\nfor i uint 3\ns = add s i\nend\nfor i uint 2\ns = add s i\nend\nret s\nend'
595ir_multi for_value 'fn f n uint to uint\ns = uint 0\nfor i uint n\ns = add s i\nend\nret s\nend'
596ir_multi for_value_expr 'fn f n uchar to uint\ns = uint 0\nfor i uchar add n uchar 1\nif eq i uchar 3\nbreak\nend\ns = add s uint 1\nend\nret s\nend'
597ir_multi scope_reuse 'fn f a uint to uint\nif gt a 1\ny = add a 1\nret y\nend\ny = add a 2\nret y\nend'
598ir_multi call_long_prefix 'fn increment_one a uint to uint\nret add a uint 1\nend\nfn increment_two a uint to uint\nret add a uint 2\nend\nfn f to uint\nret increment_two uint 4\nend'
599# A contract word followed by = is an assignment to a local of that name, as in the C oracle (only the clause form is error 30).
600ir_multi ensures_assign 'fn f to ulong\nensures = ulong 1\nret ensures\nend'
601ir_multi requires_assign 'fn f to ulong\nx = ulong 1\nrequires = add x x\nrequires = add requires x\nret requires\nend'
602# Random two-function programs with a call: differential against the oracle.
603rm -f "$B"/fz*
604awk -v dir="$B" 'BEGIN{
605 M = 65536;
606 split("add sub mul xor and or", O, " ");
607 split("eq ne lt le gt ge", C, " ");
608 for (p = 0; p < 30; p++) {
609 s = 1000 + p * 37;
610 s = (s * 25173 + 13849) % M; o1 = O[1 + (s % 6)];
611 s = (s * 25173 + 13849) % M; o2 = O[1 + (s % 6)];
612 s = (s * 25173 + 13849) % M; o3 = O[1 + (s % 6)];
613 s = (s * 25173 + 13849) % M; cm = C[1 + (s % 6)];
614 s = (s * 25173 + 13849) % M; n1 = 1 + (s % 9);
615 s = (s * 25173 + 13849) % M; n2 = 1 + (s % 9);
616 s = (s * 25173 + 13849) % M; n3 = 1 + (s % 9);
617 s = (s * 25173 + 13849) % M; n4 = 1 + (s % 9);
618 s = (s * 25173 + 13849) % M; o4 = O[1 + (s % 6)];
619 s = (s * 25173 + 13849) % M; n5 = 1 + (s % 9);
620 f = sprintf("%s/fz%02d.omegese", dir, p);
621 print "fn h a ulong b ulong to ulong" > f;
622 print "x = " o1 " a b" > f;
623 print "y = " o2 " x " n1 > f;
624 print "if " cm " y " n2 > f;
625 print "y = " o3 " y " n3 > f;
626 print "end" > f;
627 print "ret y" > f;
628 print "end" > f;
629 print "fn f to ulong" > f;
630 print "p = ulong " n4 > f;
631 print "q = ulong " n4 > f;
632 print "r = h p q" > f;
633 print "z = " o4 " r " n5 > f;
634 print "ret z" > f;
635 print "end" > f;
636 close(f);
637 }
638}'
639fzn=0
640for f in "$B"/fz*.omegese; do
641 fzn=$((fzn + 1))
642 b=${f%.omegese}
643 build/omegese/omegese emit "$f" "$b.json" > /dev/null
644 build/omega_emit/omega_emit emit "$b.json" "$b.oracle" > /dev/null
645 { printf 'ir\n'; cat "$f"; } > "$b.input"
646 timeout 5 "$B/stage2" < "$b.input" > "$b.got"
647 cmp -s "$b.oracle" "$b.got" || fail "fuzz $b differs from the oracle"
648 build/checker2/checker2 check "$b.got" > "$b.check"
649 grep -q '^checker2=ACCEPT ' "$b.check" || fail "fuzz $b checker refusal"
650done
651[ "$fzn" = 30 ] || fail "fuzz ran $fzn of 30 programs"
652echo "PASS 30 random two-function call units identical; checker2 ACCEPT"
653echo 'SCALAR_IR_CHECKPOINT 10/10 + 31 refusals + 9 multi-call units + 3 break units + 2 for-value units + 1 shift unit + 4 bool units + 24 cast units + 2 contract-name units + 30 fuzz units + 1 guarded for-bound unit + 2 bound-range pairs (1000000 accepted, 1000001 error 8) + 1 count-range set (1000000 identical to the oracle; 1000001, -1, -0, const 1000001 error 8); validation: 38 refusals + 1 same-IR pair + 4 scope/fallthrough/long-name units; structs IR spec-blocked'
654echo 'RC=0'