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 / amd / rest / classify.om

298 lines · 5733 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/amd/rest/classify.om: writes gpu/amd/NOT-YET-OMEGA.tsv. It reads a list of CUDApp paths, one per
3note line, on standard input and the rules in RULES (gpu/amd/rest/classes.tsv), and prints one row per path:
4note PATH, KIND (the extension after the last '.' of the file name, or none), CLASS, REASON, REPLACEMENT.
5note The first rule whose PREFIX and SUFFIX both match decides ("-" is the empty string). CLASS skip prints
6note nothing; CLASS error prints the path to standard error and makes the exit status 1, so a file the rules
7note do not cover is loud. Usage: classify RULES < LIST > OUT. Exit 0 done, 1 unclassified path, 2 usage,
8note 3 RULES or LIST unreadable, malformed or larger than its buffer (refused, nothing partial is claimed).
9text t_usage "usage: classify RULES < LIST > OUT\n"
10text t_bad "classify: RULES or LIST unreadable, malformed, or larger than its buffer\n"
11text t_unc "classify: no rule covers "
12text t_h1 "# generated by gpu/amd/rest/classify.om from gpu/amd/rest/classes.tsv; do not edit by hand\n"
13text t_h2 "# git -C CUDApp ls-tree -r --name-only 84b524cadaaa8bc9b556adfaea9d6dd2e0d67a66 | classify gpu/amd/rest/classes.tsv\n"
14text t_h3 "path\tkind\tclass\treason\treplacement\n"
15text t_none "none"
16text t_skip "skip"
17text t_err "error"
18text t_nl "\n"
19global g_pa uchar 4096
20global g_in uchar 8388608
21global g_r uchar 1048576
22global g_o uchar 8192
23global g_rs ulong 5120
24global g_re ulong 5120
25global g_n ulong 8
26note g_n: 0 output length, 1 LIST length, 2 RULES length, 3 rule count, 4 unclassified count
27fn oc c ulong to void
28n = get g_n 0
29if ge n len g_o
30r = write 1 g_o 0 n
31n = ulong 0
32end
33put g_o n uchar c
34put g_n 0 add n 1
35end
36fn ot t view uchar * to void
37for i ulong len t bound 4096
38oc ulong get t i
39end
40end
41fn oflush to void
42r = write 1 g_o 0 get g_n 0
43put g_n 0 0
44end
45note print g_in[s, e)
46fn oin s ulong e ulong to void
47i = s
48while lt i e bound 8388609
49oc ulong get g_in i
50i = add i 1
51end
52end
53note print g_r[s, e)
54fn orl s ulong e ulong to void
55i = s
56while lt i e bound 1048577
57oc ulong get g_r i
58i = add i 1
59end
60end
61note read all of fd into g_in; its length, or a value over the buffer when unreadable or too large
62fn rdin fd int to ulong
63n = ulong 0
64while true bound 8388610
65x = read fd g_in n sub len g_in n
66if lt x 0
67ret add len g_in 1
68end
69if eq x 0
70ret n
71end
72n = add n ulong x
73if ge n len g_in
74ret add len g_in 1
75end
76end
77ret n
78end
79fn rdrl fd int to ulong
80n = ulong 0
81while true bound 1048578
82x = read fd g_r n sub len g_r n
83if lt x 0
84ret add len g_r 1
85end
86if eq x 0
87ret n
88end
89n = add n ulong x
90if ge n len g_r
91ret add len g_r 1
92end
93end
94ret n
95end
96note field start and end, with "-" meaning empty
97fn rfs k ulong to ulong
98ret get g_rs k
99end
100fn rfe k ulong to ulong
101s = get g_rs k
102e = get g_re k
103if and eq sub e s 1 eq get g_r s 45
104ret s
105end
106ret e
107end
108note split RULES into rows of exactly five tab-separated fields; '#' lines and empty lines are skipped
109fn rparse to bool
110n = get g_n 2
111p = ulong 0
112c = ulong 0
113while lt p n bound 1048577
114if or eq get g_r p 35 eq get g_r p 10
115while and lt p n ne get g_r p 10 bound 1048577
116p = add p 1
117end
118p = add p 1
119continue
120end
121if ge mul add c 1 5 len g_rs
122ret false
123end
124f = ulong 0
125put g_rs mul c 5 p
126while lt p n bound 1048577
127b = get g_r p
128if eq b 10
129break
130end
131if eq b 9
132if ge f 4
133ret false
134end
135put g_re add mul c 5 f p
136f = add f 1
137put g_rs add mul c 5 f add p 1
138end
139p = add p 1
140end
141if ne f 4
142ret false
143end
144put g_re add mul c 5 f p
145c = add c 1
146p = add p 1
147end
148put g_n 3 c
149ret true
150end
151note g_in[s, s + l) equals g_r[a, a + l)
152fn seq s ulong a ulong l ulong to bool
153for i ulong l bound 1048576
154if ne get g_in add s i get g_r add a i
155ret false
156end
157end
158ret true
159end
160note rule k covers the path g_in[s, e)
161fn rmatch k ulong s ulong e ulong to bool
162b = mul k 5
163ps = rfs b
164pl = sub rfe b ps
165ss = rfs add b 1
166sl = sub rfe add b 1 ss
167if lt sub e s add pl sl
168ret false
169end
170if not seq s ps pl
171ret false
172end
173ret seq sub e sl ss sl
174end
175note the class field of rule k is the text t
176fn ris k ulong t view uchar * to bool
177s = get g_rs add mul k 5 2
178e = get g_re add mul k 5 2
179if ne sub e s len t
180ret false
181end
182for i ulong len t bound 16
183if ne get g_r add s i get t i
184ret false
185end
186end
187ret true
188end
189note print the extension of g_in[s, e), or none
190fn okind s ulong e ulong to void
191d = e
192i = e
193while gt i s bound 8388609
194c = get g_in sub i 1
195if eq c 47
196break
197end
198if and eq c 46 eq d e
199d = sub i 1
200end
201i = sub i 1
202end
203if or eq d e eq d i
204ot t_none
205ret
206end
207oin add d 1 e
208end
209note classify one path g_in[s, e)
210note field f + 2 of rule k, after a tab
211fn orf k ulong f ulong to void
212b = mul k 5
213oc 9
214orl get g_rs add b add f 2 get g_re add b add f 2
215end
216fn cpath s ulong e ulong to void
217c = get g_n 3
218for k ulong c bound 1024
219if rmatch k s e
220if ris k t_skip
221ret
222end
223if ris k t_err
224oflush
225r = write 2 t_unc 0 len t_unc
226r = write 2 g_in s sub e s
227r = write 2 t_nl 0 1
228put g_n 4 add get g_n 4 1
229ret
230end
231oin s e
232oc 9
233okind s e
234orf k 0
235orf k 1
236orf k 2
237oc 10
238ret
239end
240end
241oflush
242r = write 2 t_unc 0 len t_unc
243r = write 2 g_in s sub e s
244r = write 2 t_nl 0 1
245put g_n 4 add get g_n 4 1
246end
247fn bad to int
248r = write 2 t_bad 0 len t_bad
249ret 3
250end
251fn main to int
252if ne argcnt 2
253r = write 2 t_usage 0 len t_usage
254ret 2
255end
256r = argread 1 g_pa 0 4095
257if lt r 1
258r = write 2 t_usage 0 len t_usage
259ret 2
260end
261fd = fopen g_pa 0 ulong r int 524288 int 0
262if lt fd 0
263ret bad
264end
265m = rdrl int fd
266x = fclose int fd
267if gt m len g_r
268ret bad
269end
270put g_n 2 m
271if not rparse
272ret bad
273end
274n = rdin 0
275if gt n len g_in
276ret bad
277end
278put g_n 1 n
279ot t_h1
280ot t_h2
281ot t_h3
282p = ulong 0
283while lt p n bound 8388609
284q = p
285while and lt q n ne get g_in q 10 bound 8388609
286q = add q 1
287end
288if gt q p
289cpath p q
290end
291p = add q 1
292end
293oflush
294if gt get g_n 4 0
295ret 1
296end
297ret 0
298end