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 / nvidia / checks / lib.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/nvidia/checks/lib.om: the table reader every check of gpu/nvidia/checks shares. A check is the gpu/ |
| 3 | note units it tests, then this part, then the check's own part, concatenated (gpu/nvidia/checks/checks.tsv) and |
| 4 | note compiled by seed/out/omc. Run: CHECK TABLE. The table holds one case per line, fields split by tabs; an |
| 5 | note empty line or one starting with # is skipped. For each case main calls the check's `fn crow to bool` with |
| 6 | note the fields of the case; false is a failed case. The check prints its own name in `fn cname to void` (a |
| 7 | note text must be declared before its first use, so lib.om cannot name the check's text). |
| 8 | note Output: one FAIL line per failed case (its line number and text), then NAME PASS rows=N (exit 0), or |
| 9 | note NAME FAIL rows=N failed=F (exit 1). A table with no case fails. Exit 2: bad usage, a table that cannot be |
| 10 | note read or held (enlarge refused), or a field the check cannot read (ckbad). The table and the field list |
| 11 | note are run-time pools sized from the input; the path is at most 4095 bytes (Linux PATH_MAX less the 0). |
| 12 | text t_ckusage "usage: CHECK TABLE\n" |
| 13 | text t_ckread "check: cannot read the table, or the host refused memory to hold it\n" |
| 14 | text t_ckbadf "check: unreadable field on line " |
| 15 | text t_ckfail "FAIL line " |
| 16 | text t_ckpass " PASS rows=" |
| 17 | text t_ckfl " FAIL rows=" |
| 18 | text t_ckfd " failed=" |
| 19 | global ck_t uchar * |
| 20 | global ck_fs ulong * |
| 21 | global ck_fe ulong * |
| 22 | global ck_p uchar 4096 |
| 23 | global ck_o uchar 65536 |
| 24 | global ck_n ulong 16 |
| 25 | note ck_n: 0 table length, 1 output length, 2 fields in the row, 3 line number, 4 rows, 5 failed |
| 26 | fn ckflush to void |
| 27 | o = ulong 0 |
| 28 | n = get ck_n 1 |
| 29 | while lt o n bound 65537 |
| 30 | x = write 1 ck_o o sub n o |
| 31 | if le x 0 |
| 32 | exit 2 |
| 33 | end |
| 34 | o = add o ulong x |
| 35 | end |
| 36 | put ck_n 1 0 |
| 37 | end |
| 38 | fn ckoc c ulong to void |
| 39 | n = get ck_n 1 |
| 40 | if ge n len ck_o |
| 41 | ckflush |
| 42 | n = 0 |
| 43 | end |
| 44 | put ck_o n uchar c |
| 45 | put ck_n 1 add n 1 |
| 46 | end |
| 47 | note lib.om is OM-1 so that it composes with units of either profile (an OM-1 unit may use words OM-2 reserves, |
| 48 | note such as layout); OM-1 has no unsized view, so a text is never passed: ckout k prints lib's own text k (0 FAIL |
| 49 | note line, 1 PASS rows=, 2 FAIL rows=, 3 failed=), and a check prints its name with ckoc in its own cname |
| 50 | fn ckout k ulong to void |
| 51 | if eq k 0 |
| 52 | for i ulong len t_ckfail bound 64 |
| 53 | ckoc ulong get t_ckfail i |
| 54 | end |
| 55 | end |
| 56 | if eq k 1 |
| 57 | for i ulong len t_ckpass bound 64 |
| 58 | ckoc ulong get t_ckpass i |
| 59 | end |
| 60 | end |
| 61 | if eq k 2 |
| 62 | for i ulong len t_ckfl bound 64 |
| 63 | ckoc ulong get t_ckfl i |
| 64 | end |
| 65 | end |
| 66 | if eq k 3 |
| 67 | for i ulong len t_ckfd bound 64 |
| 68 | ckoc ulong get t_ckfd i |
| 69 | end |
| 70 | end |
| 71 | end |
| 72 | fn cknumo v ulong to void |
| 73 | if ge v 10 |
| 74 | cknumo div v 10 |
| 75 | end |
| 76 | ckoc add 48 rem v 10 |
| 77 | end |
| 78 | note exit 2 with lib's own message k: 0 usage, 1 the table cannot be read or held |
| 79 | fn ckrefuse k ulong to void |
| 80 | ckflush |
| 81 | if eq k 0 |
| 82 | r = write 2 t_ckusage 0 len t_ckusage |
| 83 | end |
| 84 | if eq k 1 |
| 85 | r = write 2 t_ckread 0 len t_ckread |
| 86 | end |
| 87 | exit 2 |
| 88 | end |
| 89 | note a field the check cannot read: exit 2 naming the line (a broken table is not a failed case) |
| 90 | fn ckbad to void |
| 91 | ckflush |
| 92 | r = write 2 t_ckbadf 0 len t_ckbadf |
| 93 | cknumo get ck_n 3 |
| 94 | ckoc 10 |
| 95 | r = write 2 ck_o 0 get ck_n 1 |
| 96 | exit 2 |
| 97 | end |
| 98 | fn ckcnt to ulong |
| 99 | ret get ck_n 2 |
| 100 | end |
| 101 | fn cklen i ulong to ulong |
| 102 | if ge i get ck_n 2 |
| 103 | ckbad |
| 104 | end |
| 105 | ret sub get ck_fe i get ck_fs i |
| 106 | end |
| 107 | note byte j of field i |
| 108 | fn ckch i ulong j ulong to ulong |
| 109 | if ge j cklen i |
| 110 | ckbad |
| 111 | end |
| 112 | ret ulong get ck_t add get ck_fs i j |
| 113 | end |
| 114 | note field i as an unsigned decimal below 2^64; anything else is ckbad |
| 115 | fn cknum i ulong to ulong |
| 116 | n = cklen i |
| 117 | if or eq n 0 gt n 20 |
| 118 | ckbad |
| 119 | end |
| 120 | v = ulong 0 |
| 121 | for j ulong n bound 20 |
| 122 | c = ckch i j |
| 123 | if or lt c 48 gt c 57 |
| 124 | ckbad |
| 125 | end |
| 126 | d = sub c 48 |
| 127 | if gt v div sub 18446744073709551615 d 10 |
| 128 | ckbad |
| 129 | end |
| 130 | v = add mul v 10 d |
| 131 | end |
| 132 | ret v |
| 133 | end |
| 134 | fn cknib c ulong to ulong |
| 135 | if and ge c 48 le c 57 |
| 136 | ret sub c 48 |
| 137 | end |
| 138 | if and ge c 97 le c 102 |
| 139 | ret sub c 87 |
| 140 | end |
| 141 | ckbad |
| 142 | ret 0 |
| 143 | end |
| 144 | note field i as lowercase hex bytes: their count (0 for "-"); ckhex i j is byte j |
| 145 | fn ckhexn i ulong to ulong |
| 146 | n = cklen i |
| 147 | if and eq n 1 eq ckch i 0 45 |
| 148 | ret 0 |
| 149 | end |
| 150 | if or eq n 0 ne rem n 2 0 |
| 151 | ckbad |
| 152 | end |
| 153 | ret div n 2 |
| 154 | end |
| 155 | fn ckhex i ulong j ulong to ulong |
| 156 | hi = cknib ckch i mul j 2 |
| 157 | lo = cknib ckch i add mul j 2 1 |
| 158 | ret or shl hi 4 lo |
| 159 | end |
| 160 | note field slot k exists in ck_fs and ck_fe |
| 161 | fn ckslot k ulong to void |
| 162 | if lt k len ck_fs |
| 163 | ret |
| 164 | end |
| 165 | n = mul add k 1 2 |
| 166 | r = enlarge ck_fs n |
| 167 | q = enlarge ck_fe n |
| 168 | if or lt r 0 lt q 0 |
| 169 | ckrefuse 1 |
| 170 | end |
| 171 | end |
| 172 | note split ck_t[s, e) at tabs into ck_fs/ck_fe |
| 173 | fn cksplit s ulong e ulong to void |
| 174 | k = ulong 0 |
| 175 | ckslot 0 |
| 176 | put ck_fs 0 s |
| 177 | i = s |
| 178 | while lt i e bound 1099511627776 |
| 179 | if eq get ck_t i 9 |
| 180 | put ck_fe k i |
| 181 | k = add k 1 |
| 182 | ckslot k |
| 183 | put ck_fs k add i 1 |
| 184 | end |
| 185 | i = add i 1 |
| 186 | end |
| 187 | put ck_fe k e |
| 188 | put ck_n 2 add k 1 |
| 189 | end |
| 190 | fn ckline s ulong e ulong to void |
| 191 | if or eq s e eq get ck_t s 35 |
| 192 | ret |
| 193 | end |
| 194 | cksplit s e |
| 195 | put ck_n 4 add get ck_n 4 1 |
| 196 | if not crow |
| 197 | put ck_n 5 add get ck_n 5 1 |
| 198 | ckout 0 |
| 199 | cknumo get ck_n 3 |
| 200 | ckoc 58 |
| 201 | ckoc 32 |
| 202 | for j ulong sub e s bound 1099511627776 |
| 203 | c = ulong get ck_t add s j |
| 204 | if eq c 9 |
| 205 | c = 32 |
| 206 | end |
| 207 | ckoc c |
| 208 | end |
| 209 | ckoc 10 |
| 210 | end |
| 211 | end |
| 212 | note read the file named by argument 1 into ck_t, growing it as the file needs; its length |
| 213 | fn ckload to ulong |
| 214 | p = argread 1 ck_p 0 4095 |
| 215 | if lt p 1 |
| 216 | ckrefuse 0 |
| 217 | end |
| 218 | fd = fopen ck_p 0 ulong p int 524288 int 0 |
| 219 | if lt fd 0 |
| 220 | ckrefuse 1 |
| 221 | end |
| 222 | n = ulong 0 |
| 223 | while true bound 1099511627776 |
| 224 | if eq n len ck_t |
| 225 | g = add mul n 2 65536 |
| 226 | r = enlarge ck_t g |
| 227 | if lt r 0 |
| 228 | ckrefuse 1 |
| 229 | end |
| 230 | end |
| 231 | x = read int fd ck_t n sub len ck_t n |
| 232 | if lt x 0 |
| 233 | ckrefuse 1 |
| 234 | end |
| 235 | if eq x 0 |
| 236 | break |
| 237 | end |
| 238 | n = add n ulong x |
| 239 | end |
| 240 | r = fclose int fd |
| 241 | ret n |
| 242 | end |
| 243 | fn main to int |
| 244 | if ne argcnt 2 |
| 245 | ckrefuse 0 |
| 246 | end |
| 247 | n = ckload |
| 248 | put ck_n 0 n |
| 249 | s = ulong 0 |
| 250 | line = ulong 1 |
| 251 | while lt s n bound 1099511627776 |
| 252 | e = s |
| 253 | while and lt e n ne get ck_t e 10 bound 1099511627776 |
| 254 | e = add e 1 |
| 255 | end |
| 256 | put ck_n 3 line |
| 257 | ckline s e |
| 258 | s = add e 1 |
| 259 | line = add line 1 |
| 260 | end |
| 261 | f = get ck_n 5 |
| 262 | ckrows = get ck_n 4 |
| 263 | cname |
| 264 | if and eq f 0 gt ckrows 0 |
| 265 | ckout 1 |
| 266 | cknumo ckrows |
| 267 | ckoc 10 |
| 268 | ckflush |
| 269 | ret 0 |
| 270 | end |
| 271 | ckout 2 |
| 272 | cknumo ckrows |
| 273 | ckout 3 |
| 274 | cknumo f |
| 275 | ckoc 10 |
| 276 | ckflush |
| 277 | ret 1 |
| 278 | end |