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 / ng / tests / ir / host-audit.om

291 lines · 4674 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Build with seed/ng/src/ir.om (OM-2). Usage: host-audit hostwords.tsv < seed/omc/omc.om
3note Decodes the actual seeded kw function, not genkw.awk or a copied list of names.
4note Closed host id set is the hostval/typing dispatch of the pinned compiler. Excludes exit=152,
5note efi=178, qty=96, const=97, fma=227 and the OM-2 register words dit=225/scrub=226.
6note The set ends at the scheduler words cpuset..getprio 236..240 (omc f4fa7951, OMEGESE s10).
7global ha_buf uchar 2097152
8global ha_tab ulong 256
9global ha_kw ulong 256
10global ha_nums ulong 8
11global ha_path uchar 4096
12global ha_tmp uchar 32
13global ha_s ulong 8
14text ha_fn "fn kw "
15text ha_end "fn kw2 "
16text ha_if "if eq w "
17text ha_pk "packed = "
18text ha_pk0 "packed = or ulong "
19text ha_ret "ret "
20
21text ha_miss "MISSING\t"
22text ha_extra "EXTRA\t"
23text ha_chang "CHANGED\t"
24text ha_rows "HOSTTABLE rows="
25text ha_diff " differences="
26fn ha_match p ulong z ulong word view uchar * to bool
27if gt len word sub z p
28ret false
29end
30for j ulong len word bound 64
31if ne get ha_buf add p j get word j
32ret false
33end
34end
35ret true
36end
37fn ha_num p ulong z ulong to ulong
38v = ulong 0
39for j ulong sub z p bound 128
40c = ulong get ha_buf add p j
41if or lt c 48 gt c 57
42break
43end
44v = add mul v 10 sub c 48
45end
46ret v
47end
48fn ha_word p ulong z ulong to ulong
49v = ulong 0
50for j ulong 8
51if ge add p j z
52break
53end
54c = ulong get ha_buf add p j
55if or eq c 9 eq c 32
56break
57end
58v = or v shl c mul j 8
59end
60ret v
61end
62fn ha_read fd int to ulong
63n = ulong 0
64while lt n len ha_buf bound 2097153
65k = read fd ha_buf n sub len ha_buf n
66if lt k 0
67exit 2
68end
69if eq k 0
70ret n
71end
72n = add n ulong k
73end
74exit 2
75end
76fn ha_lend p ulong n ulong to ulong
77j = p
78while lt j n bound 2097153
79if eq get ha_buf j 10
80ret j
81end
82j = add j 1
83end
84ret j
85end
86fn ha_digits p ulong z ulong to ulong
87n = ulong 0
88j = p
89while lt j z bound 4096
90c = get ha_buf j
91if and ge c 48 le c 57
92if ge n 8
93exit 2
94end
95put ha_nums n ha_num j z
96n = add n 1
97while lt j z bound 128
98c = get ha_buf j
99if or lt c 48 gt c 57
100break
101end
102j = add j 1
103end
104else
105j = add j 1
106end
107end
108ret n
109end
110fn ha_host id ulong to bool
111if or eq id 53 eq id 54
112ret true
113end
114if and ge id 100 le id 177
115ret ne id 152
116end
117if and ge id 197 le id 200
118ret true
119end
120if and ge id 220 le id 222
121ret true
122end
123if eq id 224
124ret true
125end
126if and ge id 228 le id 233
127ret true
128end
129if eq id 235
130ret true
131end
132ret and ge id 236 le id 240
133end
134fn ha_table n ulong to void
135p = add ha_lend 0 n 1
136while lt p n bound 257
137z = ha_lend p n
138id = ha_num p z
139if or eq id 0 ge id 256
140exit 2
141end
142q = p
143while and lt q z ne get ha_buf q 9 bound 128
144q = add q 1
145end
146if eq q z
147exit 2
148end
149if ne get ha_tab id 0
150exit 2
151end
152put ha_tab id ha_word add q 1 z
153p = add z 1
154end
155end
156fn ha_source n ulong to void
157p = ulong 0
158active = false
159word = ulong 0
160packed = ulong 0
161while lt p n bound 65536
162z = ha_lend p n
163if ha_match p z ha_fn
164active = true
165end
166if ha_match p z ha_end
167ret
168end
169if active
170if ha_match p z ha_pk
171nd = ha_digits p z
172if ha_match p z ha_pk0
173if ne nd 3
174exit 2
175end
176packed = or get ha_nums 0 shl get ha_nums 1 get ha_nums 2
177else
178if ne nd 2
179exit 2
180end
181packed = or packed shl get ha_nums 0 get ha_nums 1
182end
183end
184if ha_match p z ha_if
185q = add p len ha_if
186word = packed
187c = get ha_buf q
188if and ge c 48 le c 57
189word = ha_num q z
190end
191end
192if ha_match p z ha_ret
193id = ha_num add p len ha_ret z
194if ha_host id
195if eq word 0
196exit 2
197end
198put ha_kw id word
199end
200word = 0
201end
202end
203p = add z 1
204end
205exit 2
206end
207fn ha_print n ulong to void
208v = n
209i = ulong 32
210while true bound 32
211i = sub i 1
212put ha_tmp i uchar add 48 rem v 10
213v = div v 10
214if eq v 0
215k = write 1 ha_tmp i sub 32 i
216ret
217end
218end
219end
220fn ha_name word ulong to void
221n = ulong 0
222v = word
223while ne v 0 bound 8
224put ha_tmp n uchar and v 255
225v = shr v 8
226n = add n 1
227end
228k = write 1 ha_tmp 0 n
229end
230fn ha_tabchar to void
231put ha_tmp 0 9
232k = write 1 ha_tmp 0 1
233end
234fn ha_newline to void
235put ha_tmp 0 10
236k = write 1 ha_tmp 0 1
237end
238fn main to int
239if ne argcnt 2
240ret 2
241end
242m = argread 1 ha_path 0 len ha_path
243if or le m 0 ge m long len ha_path
244ret 2
245end
246fd = fopen ha_path 0 ulong m 524288 0
247if lt fd 0
248ret 2
249end
250n = ha_read int fd
251k = fclose int fd
252ha_table n
253n = ha_read 0
254ha_source n
255rows = ulong 0
256diff = ulong 0
257for id ulong 256
258w = get ha_kw id
259t = get ha_tab id
260if ne w 0
261rows = add rows 1
262end
263if ne w t
264diff = add diff 1
265if eq t 0
266k = write 1 ha_miss 0 len ha_miss
267else
268if eq w 0
269k = write 1 ha_extra 0 len ha_extra
270else
271k = write 1 ha_chang 0 len ha_chang
272end
273end
274ha_print id
275ha_tabchar
276ha_name w
277ha_tabchar
278ha_name t
279ha_newline
280end
281end
282k = write 1 ha_rows 0 len ha_rows
283ha_print rows
284k = write 1 ha_diff 0 len ha_diff
285ha_print diff
286ha_newline
287if ne diff 0
288ret 1
289end
290ret 0
291end