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