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 / gpu / runtime / inventory.om

838 lines · 17832 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/runtime/inventory.om: the inventory of CUDApp src/ against this repository, in seeded Omega (OM-2 program
3note mode, Linux AArch64). Build from the repository root (seed/ng/sha256.om supplies sh_dat, sh_blk, sh_out;
4note gpu/runtime/zsha.om the streaming hash):
5note { printf 'om2\n'; cat seed/ng/sha256.om gpu/runtime/zsha.om gpu/runtime/inventory.om; } | seed/out/omc > inventory
6note Run from the repository root: inventory [DIR] (DIR defaults to gpu/runtime)
7note Inputs, all in DIR, made outside the tree by the commands in gpu/runtime/README.md:
8note cudapp-src.sha256.txt sha256sum lines (64 hex, two spaces, path) of every file under CUDApp src/
9note omega-base.sha256.txt sha256sum lines of every file under src/ and gpu/ of this repository at the base
10note cudapp-ident.txt every CUDApp src/*.ident record, concatenated: the Omega Bridge provenance lines
11note pathmap.tsv FROM TAB TO: a CUDApp Omega path starting FROM lives in this tree at TO then the rest
12note rewrites.tsv CUDAPP-PATH TAB OMEGA-PATH: a CUDApp file without an ident record rewritten in Omega here
13note A line of pathmap.tsv or rewrites.tsv starting with # is a comment; an empty line is skipped.
14note Output on stdout, one row per CUDApp file in list order: PATH KIND OMEGA_SRC ORIGIN OMEGA DETAIL, tab separated.
15note KIND the file name's extension (c, h, inc, ident, ...)
16note OMEGA_SRC identical | diverged | cudapp-only: this repository's file at the same path, from the base list;
17note the file in the tree is hashed and must still match the base list (cudapp-only: must not exist)
18note ORIGIN record (an .ident file) | bridge (its sha256 is the c= or h= of an ident record, so the Omega
19note Bridge emitted it from Omega source) | unrecorded (no ident record names it: written by hand,
20note or emitted by a CUDApp generator that writes no ident record)
21note OMEGA bridge: same (every source part is in this tree and the parts compose to the record's src=
22note sha256), changed (all parts here, another composition), absent (a part is not here);
23note unrecorded: rewritten (rewrites.tsv names an Omega file that exists here), rewrite-missing, none;
24note record: -
25note An omega-ident record composes its parts each followed by a newline (CUDApp om/units.sh); an
26note omega-native-ident record (parts joined by +) composes them with nothing between.
27note Then summary lines starting with #. Exit 0, 2 bad usage, 3 an input is malformed, a tree file differs from the
28note base list or a cudapp-only path exists in the tree (the list is stale: regenerate it), 4 the host refused memory.
29note Every input is length-checked.
30note Memory grows with the input (run-time pools); the one fixed buffer is a path of PATH_MAX (4096) bytes.
31text iv_dflt "gpu/runtime"
32text iv_fsrc "/cudapp-src.sha256.txt"
33text iv_fbase "/omega-base.sha256.txt"
34text iv_fid "/cudapp-ident.txt"
35text iv_fmap "/pathmap.tsv"
36text iv_frw "/rewrites.tsv"
37text iv_hdr "path\tkind\tomega_src\torigin\tomega\tdetail\n"
38text iv_kid "ident"
39text iv_kc "c"
40text iv_kh "h"
41text iv_kinc "inc"
42text iv_knat "omega-native-ident "
43text iv_kunit "unit="
44text iv_ksrc "src="
45text iv_kpath "path="
46text iv_identical "identical"
47text iv_diverged "diverged"
48text iv_conly "cudapp-only"
49text iv_record "record"
50text iv_bridge "bridge"
51text iv_unrec "unrecorded"
52text iv_same "same"
53text iv_changed "changed"
54text iv_absent "absent"
55text iv_rewritten "rewritten"
56text iv_rwmiss "rewrite-missing"
57text iv_none "none"
58text iv_dash "-"
59text iv_s_rows "# rows="
60text iv_s_rec " record="
61text iv_s_br " bridge="
62text iv_s_bs " bridge_same="
63text iv_s_bc " bridge_changed="
64text iv_s_ba " bridge_absent="
65text iv_s_hd " unrecorded="
66text iv_s_hr " unrecorded_rewritten="
67text iv_s_hm " unrecorded_rewrite_missing="
68text iv_s_hn " unrecorded_none="
69text iv_s_id "# omega_src identical="
70text iv_s_dv " diverged="
71text iv_s_co " cudapp_only="
72text iv_s_rem "# unrecorded_none by kind c="
73text iv_s_rh " h="
74text iv_s_ri " inc="
75text iv_s_ro " other="
76text iv_s_rd "# unrecorded_none by omega_src identical="
77text iv_e_usage "usage: inventory [DIR] (run from the repository root)\n"
78text iv_e_read "inventory: cannot read "
79text iv_e_list "inventory: malformed sha256 list line in "
80text iv_e_tab "inventory: malformed row (FROM TAB TO) in "
81text iv_e_drift "inventory: tree file differs from omega-base.sha256.txt (regenerate the list): "
82text iv_e_new "inventory: tree file is not in omega-base.sha256.txt (regenerate the list): "
83text iv_e_part "inventory: cannot read Omega source part "
84text iv_e_mem "inventory: the host refused memory\n"
85text iv_e_long "inventory: a path is longer than 4095 bytes\n"
86text iv_e_rec "inventory: an ident record has no unit=, src= or path= value of the expected form\n"
87global iv_t uchar *
88global iv_o uchar *
89global iv_x ulong *
90global iv_bl ulong *
91global iv_pa uchar 4096
92global iv_dir uchar 4096
93global iv_n ulong 64
94note iv_n: 0 path length, 1 dir length, 2 iv_t used, 3 iv_o used, 4..13 input ranges [s,e) of src, base, ident,
95note pathmap, rewrites; 14 hash fill, 15 hash total; 16, 17 a token value [s,e); 18 a part is absent;
96note 19 iv_x entries, 20 rows, 21 record, 22 bridge, 23 same, 24 changed, 25 absent, 26 unrecorded, 27 rewritten,
97note 28 rewrite-missing, 29 unrecorded none, 30 identical, 31 diverged, 32 cudapp-only, 33..36 unrecorded none c h
98note inc other, 37..39 unrecorded none identical diverged cudapp-only, 40 iv_bl entries, 41 parts emitted
99const IV_NONE ulong 9223372036854775808
100note ---- failure
101fn die t view uchar * code int to void
102r = write 2 t 0 len t
103exit code
104end
105note die naming the path in iv_pa
106fn diepa t view uchar * to void
107r = write 2 t 0 len t
108r = write 2 iv_pa 0 get iv_n 0
109q = new uchar 1 10
110r = write 2 q 0 1
111exit 3
112end
113note ---- output pool
114fn oc c ulong to void
115n = get iv_n 3
116if ge n len iv_o
117r = enlarge iv_o add mul n 2 65536
118if ne r 0
119die iv_e_mem 4
120end
121end
122put iv_o n uchar c
123put iv_n 3 add n 1
124end
125fn ot t view uchar * to void
126for i ulong len t bound 4096
127oc ulong get t i
128end
129end
130fn otr a ulong b ulong to void
131for i ulong sub b a bound 9223372036854775807
132oc ulong get iv_t add a i
133end
134end
135fn opa to void
136for i ulong get iv_n 0 bound 4096
137oc ulong get iv_pa i
138end
139end
140fn onum v ulong to void
141if ge v 10
142onum div v 10
143end
144oc add 48 rem v 10
145end
146fn oflush to void
147n = get iv_n 3
148o = ulong 0
149while lt o n bound 9223372036854775807
150x = write 1 iv_o o sub n o
151if le x 0
152exit 3
153end
154o = add o ulong x
155end
156put iv_n 3 0
157end
158note ---- paths: iv_pa[0, iv_n 0)
159fn pclr to void
160put iv_n 0 0
161end
162fn pc c ulong to void
163n = get iv_n 0
164if ge n 4095
165die iv_e_long 3
166end
167put iv_pa n uchar c
168put iv_n 0 add n 1
169end
170fn pt t view uchar * to void
171for i ulong len t bound 4096
172pc ulong get t i
173end
174end
175fn ptr a ulong b ulong to void
176for i ulong sub b a bound 9223372036854775807
177pc ulong get iv_t add a i
178end
179end
180note DIR then a file name
181fn pdir t view uchar * to void
182pclr
183for i ulong get iv_n 1 bound 4096
184pc ulong get iv_dir i
185end
186pt t
187end
188fn popen to int
189r = fopen iv_pa 0 get iv_n 0 int 524288 int 0
190if lt r 0
191ret -1
192end
193ret int r
194end
195note ---- input pool: append the file at iv_pa to iv_t; slot k gets its start, k+1 its end
196fn tload k ulong to void
197fd = popen
198if lt fd 0
199diepa iv_e_read
200end
201s = get iv_n 2
202n = s
203while true bound 9223372036854775807
204if ge add n 65536 len iv_t
205r = enlarge iv_t add mul len iv_t 2 131072
206if ne r 0
207die iv_e_mem 4
208end
209end
210x = read fd iv_t n sub len iv_t n
211if lt x 0
212diepa iv_e_read
213end
214if eq x 0
215break
216end
217n = add n ulong x
218end
219r = fclose fd
220put iv_n 2 n
221put iv_n k s
222put iv_n add k 1 n
223end
224note ---- bytes of iv_t
225fn eol p ulong e ulong to ulong
226q = p
227while lt q e bound 9223372036854775807
228if eq get iv_t q 10
229ret q
230end
231q = add q 1
232end
233ret e
234end
235note first index of byte c in [p, e), or e
236fn tfind p ulong e ulong c ulong to ulong
237q = p
238while lt q e bound 9223372036854775807
239if eq ulong get iv_t q c
240ret q
241end
242q = add q 1
243end
244ret e
245end
246fn teq a ulong b ulong n ulong to bool
247for i ulong n bound 9223372036854775807
248if ne get iv_t add a i get iv_t add b i
249ret false
250end
251end
252ret true
253end
254note iv_t[a, a+n) equals the text t
255fn tteq a ulong n ulong t view uchar * to bool
256if ne n len t
257ret false
258end
259for i ulong n bound 4096
260if ne get iv_t add a i get t i
261ret false
262end
263end
264ret true
265end
266note iv_t at a starts with the text t, inside [a, e)
267fn tpre a ulong e ulong t view uchar * to bool
268if lt sub e a len t
269ret false
270end
271ret tteq a len t t
272end
273note iv_t[a, a+n) equals iv_pa
274fn tpaeq a ulong n ulong to bool
275if ne n get iv_n 0
276ret false
277end
278for i ulong n bound 4096
279if ne get iv_t add a i get iv_pa i
280ret false
281end
282end
283ret true
284end
285fn ishex c uchar to bool
286if and ge c 48 le c 57
287ret true
288end
289ret and ge c 97 le c 102
290end
291note ---- sha256sum lists: a line is 64 lowercase hex, two spaces, a path of at least one byte
292fn lineok p ulong q ulong to bool
293if lt sub q p 67
294ret false
295end
296for i ulong 64
297if not ishex get iv_t add p i
298ret false
299end
300end
301ret and eq get iv_t add p 64 32 eq get iv_t add p 65 32
302end
303note check every line of list k (slots k, k+1); a list that is not newline-terminated is malformed
304fn listok k ulong nm view uchar * to void
305p = get iv_n k
306e = get iv_n add k 1
307while lt p e bound 9223372036854775807
308q = eol p e
309if or eq q e not lineok p q
310pdir nm
311diepa iv_e_list
312end
313p = add q 1
314end
315end
316note index the base list: iv_bl holds line starts
317fn blindex to void
318p = get iv_n 6
319e = get iv_n 7
320n = ulong 0
321while lt p e bound 9223372036854775807
322if ge n len iv_bl
323r = enlarge iv_bl add mul n 2 4096
324if ne r 0
325die iv_e_mem 4
326end
327end
328put iv_bl n p
329n = add n 1
330p = add eol p e 1
331end
332put iv_n 40 n
333end
334note the base-list line whose path is iv_t[a, b), or IV_NONE
335fn bfind a ulong b ulong to ulong
336e = get iv_n 7
337for j ulong get iv_n 40 bound 9223372036854775807
338p = get iv_bl j
339q = eol p e
340if eq sub q add p 66 sub b a
341if teq add p 66 a sub b a
342ret p
343end
344end
345end
346ret IV_NONE
347end
348note the base-list line whose path is iv_pa, or IV_NONE
349fn bfindpa to ulong
350e = get iv_n 7
351for j ulong get iv_n 40 bound 9223372036854775807
352p = get iv_bl j
353q = eol p e
354if tpaeq add p 66 sub q add p 66
355ret p
356end
357end
358ret IV_NONE
359end
360note ---- ident records: iv_x holds (hash offset, record line start) for every c= and h= value
361fn xadd h ulong ls ulong to void
362n = get iv_n 19
363if ge add n 1 len iv_x
364r = enlarge iv_x add mul n 2 4096
365if ne r 0
366die iv_e_mem 4
367end
368end
369put iv_x n h
370put iv_x add n 1 ls
371put iv_n 19 add n 2
372end
373note a token at q (up to the next space or e) that is c= or h= then 64 hex
374fn xtok q ulong e ulong ls ulong to void
375c = get iv_t q
376if not or eq c 99 eq c 104
377ret
378end
379if lt sub e q 66
380ret
381end
382if ne get iv_t add q 1 61
383ret
384end
385t = tfind q e 32
386if ne sub t q 66
387ret
388end
389xadd add q 2 ls
390end
391fn xindex to void
392p = get iv_n 8
393e = get iv_n 9
394while lt p e bound 9223372036854775807
395q = eol p e
396a = p
397while lt a q bound 9223372036854775807
398b = tfind a q 32
399xtok a b p
400a = add b 1
401end
402p = add q 1
403end
404end
405note the record line whose c= or h= is iv_t[h, h+64), or IV_NONE
406fn xfind h ulong to ulong
407for j ulong div get iv_n 19 2 bound 9223372036854775807
408if teq get iv_x mul j 2 h 64
409ret get iv_x add mul j 2 1
410end
411end
412ret IV_NONE
413end
414note the value of the token KEY... in the record line [ls, le) into slots 16, 17; false when absent
415fn tokval ls ulong lz ulong kw view uchar * to bool
416a = ls
417while lt a lz bound 9223372036854775807
418b = tfind a lz 32
419if tpre a b kw
420put iv_n 16 add a len kw
421put iv_n 17 b
422ret true
423end
424a = add b 1
425end
426ret false
427end
428note ---- hash the file at iv_pa into the gpu/runtime/zsha.om stream; false when unreadable
429fn zfile to bool
430fd = popen
431if lt fd 0
432ret false
433end
434ok = zfd fd
435r = fclose fd
436ret ok
437end
438note sh_dig equals the hex at iv_t[p, p+64)
439fn digeq p ulong to bool
440for j ulong 32
441b = get sh_dig j
442if ne get iv_t add p mul j 2 sh_hexd uint shr b 4
443ret false
444end
445if ne get iv_t add p add mul j 2 1 sh_hexd uint and b 15
446ret false
447end
448end
449ret true
450end
451note ---- tables (pathmap, rewrites): FROM TAB TO rows
452fn rowskip p ulong q ulong to bool
453if eq p q
454ret true
455end
456ret eq get iv_t p 35
457end
458note check every row of table k: a tab with bytes on both sides, newline-terminated
459fn tabok k ulong nm view uchar * to void
460p = get iv_n k
461e = get iv_n add k 1
462while lt p e bound 9223372036854775807
463q = eol p e
464if eq q e
465pdir nm
466diepa iv_e_tab
467end
468if not rowskip p q
469t = tfind p q 9
470if or or eq t q eq t p eq add t 1 q
471pdir nm
472diepa iv_e_tab
473end
474end
475p = add q 1
476end
477end
478note map the CUDApp Omega path iv_t[a, b) into iv_pa by the first pathmap row whose FROM it starts with
479fn pmap a ulong b ulong to void
480pclr
481p = get iv_n 10
482e = get iv_n 11
483while lt p e bound 9223372036854775807
484q = eol p e
485if not rowskip p q
486t = tfind p q 9
487if le sub t p sub b a
488if teq p a sub t p
489ptr add t 1 q
490ptr add a sub t p b
491ret
492end
493end
494end
495p = add q 1
496end
497ptr a b
498end
499note ---- one bridge record: its parts
500note the parts of record [ls, le) into slots 16, 17 (after unit=... or as is); false for a malformed record
501fn partsof ls ulong lz ulong to bool
502if not tokval ls lz iv_kpath
503ret false
504end
505if tpre ls lz iv_knat
506ret true
507end
508s = get iv_n 16
509e = get iv_n 17
510q = tfind s e 61
511if lt q e
512put iv_n 16 add q 1
513end
514ret true
515end
516note one part [a, b), mode 0 check presence and the base digest, 1 hash, 2 print
517fn part1 a ulong b ulong mode ulong nat bool to void
518pmap a b
519if eq mode 0
520f = bfindpa
521if eq f IV_NONE
522put iv_n 18 1
523ret
524end
525zbeg
526if not zfile
527diepa iv_e_part
528end
529zend
530if not digeq f
531diepa iv_e_drift
532end
533ret
534end
535if eq mode 1
536if not zfile
537diepa iv_e_part
538end
539if not nat
540zbyte 10
541end
542ret
543end
544if ne get iv_n 41 0
545oc 44
546end
547opa
548put iv_n 41 add get iv_n 41 1
549end
550note every part of record [ls, le) in mode
551fn parts ls ulong lz ulong mode ulong to void
552if not partsof ls lz
553die iv_e_rec 3
554end
555nat = tpre ls lz iv_knat
556sep = ulong 44
557if nat
558sep = 43
559end
560s = get iv_n 16
561e = get iv_n 17
562if eq s e
563die iv_e_rec 3
564end
565put iv_n 41 0
566a = s
567while lt a e bound 9223372036854775807
568b = tfind a e sep
569part1 a b mode nat
570a = add b 1
571end
572end
573note OMEGA and DETAIL of a bridge file whose record line starts at ls
574fn bridge ls ulong to void
575e = get iv_n 9
576lz = eol ls e
577put iv_n 18 0
578parts ls lz 0
579st = ulong 0
580if eq get iv_n 18 0
581zbeg
582parts ls lz 1
583zend
584if not tokval ls lz iv_ksrc
585die iv_e_rec 3
586end
587if or ne sub get iv_n 17 get iv_n 16 64 not digeq get iv_n 16
588st = 1
589end
590else
591st = 2
592end
593if eq st 0
594ot iv_same
595put iv_n 23 add get iv_n 23 1
596end
597if eq st 1
598ot iv_changed
599put iv_n 24 add get iv_n 24 1
600end
601if eq st 2
602ot iv_absent
603put iv_n 25 add get iv_n 25 1
604end
605oc 9
606if not tokval ls lz iv_kunit
607die iv_e_rec 3
608end
609otr get iv_n 16 get iv_n 17
610oc 58
611parts ls lz 2
612end
613note ---- files without an ident record
614note OMEGA and DETAIL of an unrecorded file at path [a, b), kind slot ks, omega_src slot os
615fn unrec a ulong b ulong ks ulong os ulong to void
616p = get iv_n 12
617e = get iv_n 13
618while lt p e bound 9223372036854775807
619q = eol p e
620if not rowskip p q
621t = tfind p q 9
622if eq sub t p sub b a
623if teq p a sub t p
624pclr
625ptr add t 1 q
626fd = popen
627if lt fd 0
628ot iv_rwmiss
629put iv_n 28 add get iv_n 28 1
630else
631r = fclose fd
632ot iv_rewritten
633put iv_n 27 add get iv_n 27 1
634end
635oc 9
636opa
637ret
638end
639end
640end
641p = add q 1
642end
643ot iv_none
644oc 9
645ot iv_dash
646put iv_n 29 add get iv_n 29 1
647put iv_n ks add get iv_n ks 1
648put iv_n os add get iv_n os 1
649end
650note ---- the tree file at path [a, b) against its base digest at iv_t f (IV_NONE: the base has no such file)
651fn treeok a ulong b ulong f ulong to void
652pclr
653ptr a b
654if eq f IV_NONE
655fd = popen
656if ge fd 0
657r = fclose fd
658diepa iv_e_new
659end
660ret
661end
662zbeg
663if not zfile
664diepa iv_e_drift
665end
666zend
667if not digeq f
668diepa iv_e_drift
669end
670end
671note ---- one CUDApp file: the list line [p, q)
672fn bump k ulong to void
673put iv_n k add get iv_n k 1
674end
675note the kind of path [a, b): the bytes after the last dot of the file name, into slots 16, 17
676fn kindof a ulong b ulong to void
677d = b
678q = a
679while lt q b bound 9223372036854775807
680c = get iv_t q
681if eq c 47
682d = b
683end
684if eq c 46
685d = q
686end
687q = add q 1
688end
689if eq d b
690put iv_n 16 b
691else
692put iv_n 16 add d 1
693end
694put iv_n 17 b
695end
696fn kslot ks ulong ke ulong to ulong
697if tteq ks sub ke ks iv_kc
698ret 33
699end
700if tteq ks sub ke ks iv_kh
701ret 34
702end
703if tteq ks sub ke ks iv_kinc
704ret 35
705end
706ret 36
707end
708fn row p ulong q ulong to void
709a = add p 66
710bump 20
711otr a q
712oc 9
713kindof a q
714ks = get iv_n 16
715ke = get iv_n 17
716otr ks ke
717oc 9
718f = bfind a q
719treeok a q f
720os = ulong 39
721if eq f IV_NONE
722ot iv_conly
723bump 32
724else
725if teq f p 64
726ot iv_identical
727bump 30
728os = 37
729else
730ot iv_diverged
731bump 31
732os = 38
733end
734end
735oc 9
736if tteq ks sub ke ks iv_kid
737ot iv_record
738oc 9
739ot iv_dash
740oc 9
741ot iv_dash
742bump 21
743oc 10
744ret
745end
746ls = xfind p
747if ne ls IV_NONE
748ot iv_bridge
749oc 9
750bump 22
751bridge ls
752oc 10
753ret
754end
755ot iv_unrec
756oc 9
757bump 26
758unrec a q kslot ks ke os
759oc 10
760end
761note ---- summary
762fn okv t view uchar * k ulong to void
763ot t
764onum get iv_n k
765end
766fn summary to void
767okv iv_s_rows 20
768okv iv_s_rec 21
769okv iv_s_br 22
770okv iv_s_bs 23
771okv iv_s_bc 24
772okv iv_s_ba 25
773okv iv_s_hd 26
774okv iv_s_hr 27
775okv iv_s_hm 28
776okv iv_s_hn 29
777oc 10
778okv iv_s_id 30
779okv iv_s_dv 31
780okv iv_s_co 32
781oc 10
782okv iv_s_rem 33
783okv iv_s_rh 34
784okv iv_s_ri 35
785okv iv_s_ro 36
786oc 10
787okv iv_s_rd 37
788okv iv_s_dv 38
789okv iv_s_co 39
790oc 10
791end
792fn main to int
793if gt argcnt 2
794die iv_e_usage 2
795end
796if eq argcnt 2
797r = argread 1 iv_dir 0 4000
798if lt r 1
799die iv_e_usage 2
800end
801put iv_n 1 ulong r
802else
803for i ulong len iv_dflt
804put iv_dir i get iv_dflt i
805end
806put iv_n 1 len iv_dflt
807end
808pdir iv_fsrc
809tload 4
810pdir iv_fbase
811tload 6
812pdir iv_fid
813tload 8
814pdir iv_fmap
815tload 10
816pdir iv_frw
817tload 12
818listok 4 iv_fsrc
819listok 6 iv_fbase
820tabok 10 iv_fmap
821tabok 12 iv_frw
822blindex
823xindex
824ot iv_hdr
825p = get iv_n 4
826e = get iv_n 5
827while lt p e bound 9223372036854775807
828q = eol p e
829row p q
830p = add q 1
831if ge get iv_n 3 1048576
832oflush
833end
834end
835summary
836oflush
837ret 0
838end