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