Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/ng/src/ir.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / ng / src / ir.om` 2104 lines · 48978 bytes Raw Blame History 1 om2 2 note SPDX-License-Identifier: Apache-2.0 3 note seed/ng/src/ir.om: ΩIR in memory (seed/ng/IR.md s14), its builder, and the one binary reader 4 note and writer of the ng compiler. Owner: ng-ir lane. First unit of seed/ng/ng.units; no fn main. 5 note Names: functions ir_*, globals i_* (D1b). Other lanes read the i_* tables and call ir_*; they 6 note never write a table directly. Handles are uint, 0 = none, numbered from 1 in creation order. 7 note 8 note Row table: one line per op, "OP NAME TK IMM FIX VAR TY" (IR.md s7.12). TK 0 P, 1 E, 2 R, 3 T. 9 note TY 0 always 0, 1 result type, 2 optional result, 3 parameter (no result value). 10 text i_rows "1 const 0 1 0 0 1\n2 select 0 0 3 0 1\n10 add 0 0 2 0 1\n11 sub 0 0 2 0 1\n12 mul 0 0 2 0 1\n13 div 0 0 2 0 1\n14 rem 0 0 2 0 1\n15 neg 0 0 1 0 1\n16 and 0 0 2 0 1\n17 or 0 0 2 0 1\n18 xor 0 0 2 0 1\n19 not 0 0 1 0 1\n20 shl 0 0 2 0 1\n21 shr 0 0 2 0 1\n22 rotl 0 0 2 0 1\n23 rotr 0 0 2 0 1\n24 min 0 0 2 0 1\n25 max 0 0 2 0 1\n26 fsqrt 0 0 1 0 1\n27 fabs 0 0 1 0 1\n28 fmath 0 1 1 0 1\n30 eq 0 0 2 0 1\n31 ne 0 0 2 0 1\n32 lt 0 0 2 0 1\n33 le 0 0 2 0 1\n34 gt 0 0 2 0 1\n35 ge 0 0 2 0 1\n36 conv 0 1 1 0 1\n37 bitcast 0 0 1 0 1\n40 gpu.id 0 1 0 0 1\n41 shared 0 0 0 0 1\n42 load 2 0 2 0 1\n43 store 1 0 3 0 0\n44 sync 1 0 0 0 0\n45 shfl 0 1 2 0 1\n46 fma 0 0 3 0 1\n47 atom 1 1 3 0 1\n48 atomcas 1 1 4 0 1\n50 alloca 1 0 0 0 1\n51 fill 1 0 2 0 0\n52 gaddr 0 1 0 0 1\n53 len 0 0 1 0 1\n54 slice 2 0 3 0 1\n55 fload 2 1 1 0 1\n56 fstore 1 1 2 0 0\n57 fref 0 1 1 0 1\n58 vload 2 0 2 0 1\n59 vstore 1 0 3 0 0\n60 br 3 0 1 1 0\n61 cbr 3 0 3 0 0\n62 ret 3 0 0 0 0\n63 retv 3 0 1 0 0\n64 call 1 0 1 1 2\n65 trap 3 1 0 0 0\n66 exit 3 0 1 0 0\n67 launch 1 0 4 1 0\n70 chk.add 1 1 2 0 0\n71 chk.sub 1 1 2 0 0\n72 chk.mul 1 1 2 0 0\n73 chk.neg 1 1 1 0 0\n74 chk.divz 1 1 1 0 0\n75 chk.divovf 1 1 2 0 0\n76 chk.shl 1 1 2 0 0\n77 chk.shift 1 1 1 0 0\n78 chk.conv 1 1 1 0 3\n79 chk.bounds 1 1 3 0 0\n80 chk.slice 1 1 3 0 0\n81 chk.fuel 1 1 2 0 0\n82 chk.true 1 1 1 0 0\n90 fact.true 0 1 1 0 0\n91 fact.range 0 1 3 0 0\n92 fact.inbounds 0 1 3 0 0\n93 fact.slice 0 1 3 0 0\n100 vsplat 0 0 1 0 1\n101 vextract 0 1 1 0 1\n102 vinsert 0 1 2 0 1\n103 vreduce 0 1 1 0 1\n104 mmald 2 1 4 0 1\n105 mmast 1 1 5 0 0\n106 mma 0 1 3 0 1\n110 host 1 1 0 1 2\n111 pool.grow 1 1 1 0 1\n112 pool.len 2 1 0 0 1\n113 pool.load 2 1 1 0 1\n114 pool.store 1 1 2 0 0\n115 pool.read 1 1 3 0 1\n116 pool.write 1 1 3 0 1\n" 11 text i_magic "OSC1IR" 12 text i_tag "omega.ng.ir.v1" 13 global i_rok uchar 256 14 global i_rtk uchar 256 15 global i_rim uchar 256 16 global i_rfx uchar 256 17 global i_rvr uchar 256 18 global i_rty uchar 256 19 global i_rno uint 256 20 global i_rnl uchar 256 21 global i_rp ulong 1 22 note counters: 0 table types, 1 struct fields, 2 globals, 3 functions, 4 blocks, 5 ops, 6 values, 23 note 7 operand slots, 8 global data bytes, 15 row table parsed 24 global i_n ulong 16 25 global i_sp ulong 4 26 global i_tq uint 8 27 global i_tk uchar 65568 28 global i_t1 uint 65568 29 global i_t2 uint 65568 30 global i_t3 uint 65568 31 global i_t4 uint 65568 32 global i_t5 uint 65568 33 global i_xty uint 65536 34 global i_xof uint 65536 35 global i_xor uchar 65536 36 global i_fk uchar 65537 37 global i_ffl uchar 65537 38 global i_frs uint 65537 39 global i_fnp uint 65537 40 global i_ftk uint 65537 41 global i_fp1 uint 65537 42 global i_fpt uint 65537 43 global i_fb1 uint 65537 44 global i_fbt uint 65537 45 global i_fnb uint 65537 46 global i_ftx uint 65537 47 global i_fty uint 65537 48 global i_ftz uint 65537 49 global i_fsg uchar 65537 50 global i_bf uint `1048577` 51 global i_bnx uint `1048577` 52 global i_bp1 uint `1048577` 53 global i_bpt uint `1048577` 54 global i_bnp uint `1048577` 55 global i_bo1 uint `1048577` 56 global i_bot uint `1048577` 57 global i_bno uint `1048577` 58 global i_bix uint `1048577` 59 global i_oop uchar `4194305` 60 global i_oty uint `4194305` 61 global i_oim ulong `4194305` 62 global i_ona uint `4194305` 63 global i_oa0 uint `4194305` 64 global i_ob uint `4194305` 65 global i_onx uint `4194305` 66 global i_otk uint `4194305` 67 global i_ors uint `4194305` 68 global i_oof uint `4194305` 69 global i_arg uint `16777216` 70 global i_vty uint `8388609` 71 global i_vk uchar `8388609` 72 global i_vo uint `8388609` 73 global i_vnx uint `8388609` 74 global i_vno uint `8388609` 75 note ---- the arena (no table capacities; Drake 2026-11-11, OMEGESE 9.6; port of omc.om's a_* unit) ------- 76 note Every ng table whose size depends on the input is a region of one pool, ar_m (`16777216` words, 128 MiB): 77 note the payload (front input or ΩIR binary), the output, ΩIR global data and globals, the front's names, 78 note long names, functions, calls, blocks, breaks, continues, inline edges, value-depth cells, call-graph 79 note order, om2 diag site records and the front-ir lowering tables, and a64's global addresses. A region 80 note starts empty and doubles when an index reaches its group's capacity (ar_need); when the moved copies 81 note do not fit, the arena is compacted and the group grows in place to the largest size that fits, so the 82 note only capacity left is the arena itself. Running out of it is a refusal of the stage that asked 83 note (front error 14, a reader's LIMIT class 23, a writer's `ng: arena full`) with an ng-use record on 84 note stderr naming every group and the words it held (ar_rec). What bounds the arena: ng has no run-time 85 note growth (no heap, decision 24); one pool is at most `16777216` elements (OMEGESE 9.4), so 128 MiB of 86 note ulong words; its pages are never resident until touched. It lives in ir.om because every ng tool is 87 note composed with ir.om first (ng, ngrun, ngrand and the oracles), so each has the same arena. 88 note Regions (ar_defs): ar_rb base word, ar_rw words held, ar_rg group, ar_rm words per group index (0: a 89 note byte region, eight bytes to a word). Groups: ar_gc capacity, ar_gp highest index asked for, plus 1. 90 note ar_top words handed out, ar_wst words left behind by moves, ar_fl 1 once the arena was full, ar_nr 91 note regions defined, ar_wb staging bytes of read and write. Element i of a word region R is 92 note `get ar_m add get ar_rb R i` (a uchar or uint region keeps one element per word, read through a 93 note conversion and written by ar_pc / ar_pu); an index below the group capacity holds by construction 94 note at every such access (the count that bounds it was asked of ar_need first). Where an index comes from 95 note input it is checked (ar_g, ar_p): past its region is a fault of ng itself and traps 3, never another 96 note region's word. 97 global ar_m ulong `16777216` 98 global ar_rb ulong 160 99 global ar_rw ulong 160 100 global ar_rg ulong 160 101 global ar_rm ulong 160 102 global ar_gc ulong 48 103 global ar_gp ulong 48 104 global ar_top ulong 1 105 global ar_wst ulong 1 106 global ar_fl ulong 1 107 global ar_nr ulong 1 108 global ar_ord ulong 160 109 global ar_np ulong 160 110 global ar_wb uchar 65536 111 global ar_rbuf uchar 4096 112 global ar_rc ulong 1 113 note ar_inl: bytes read into region 0 by ar_rdin (also while it reads, so a full arena's record shows them) 114 global ar_inl ulong 1 115 note ar_oc: bytes of region 1 (the output) written so far, for the record 116 global ar_oc ulong 1 117 note ar_gl (generated with ar_defs): the group labels of the ng-use record, each ended by a space 118 text ar_gl "in out gdat site names namehash long longhash fns fnhash calls blocks breaks conts inledge depth kahnfn kahncall lnames lnamehash lstack lsnap laq lca irglob a64glob a64val a64live a64call a64code a64fix " 119 120 note ar_def: region r is in group g with m words per group index (0: a byte region) 121 fn ar_def r ulong g ulong m ulong to void 122 put ar_rg r g 123 put ar_rm r m 124 if ge r get ar_nr 0 125 put ar_nr 0 add r 1 126 end 127 end 128 129 note ar_words: the words region r takes at group capacity c 130 fn ar_words r ulong c ulong to ulong 131 m = get ar_rm r 132 if eq m 0 133 ret shr add c 7 3 134 end 135 ret mul c m 136 end 137 138 note ar_move: room in region r for group capacity c. The last region handed out grows in place; any other 139 note moves to the top with its words copied, and the words it leaves behind are counted in ar_wst. Words 140 note past ar_top were never handed out and are 0. ar_need has checked that the group fits first, so the two 141 note full tests below are never met (they stay as a defence: 1 is returned and nothing moves). 142 fn ar_move r ulong c ulong to ulong 143 w = ar_words r c 144 o = get ar_rw r 145 if le w o 146 ret 0 147 end 148 b = get ar_rb r 149 t = get ar_top 0 150 if and ne o 0 eq add b o t 151 if gt sub w o sub len ar_m t 152 ret 1 153 end 154 put ar_top 0 add b w 155 put ar_rw r w 156 ret 0 157 end 158 if gt w sub len ar_m t 159 ret 1 160 end 161 ar_copy t b o 162 put ar_wst 0 add get ar_wst 0 o 163 put ar_rb r t 164 put ar_rw r w 165 put ar_top 0 add t w 166 ret 0 167 end 168 169 note ar_copy: words s .. s + n - 1 to d .. d + n - 1 in ascending order (d above s + n, or d below s) 170 fn ar_copy d ulong s ulong n ulong to void 171 i = ulong 0 172 while lt i n bound `16777217` 173 put ar_m add d i get ar_m add s i 174 i = add i 1 175 end 176 end 177 178 note ar_copyd: words s .. s + n - 1 to d .. d + n - 1 in descending order (d above s: a slide up) 179 fn ar_copyd d ulong s ulong n ulong to void 180 i = n 181 while gt i 0 bound `16777217` 182 i = sub i 1 183 put ar_m add d i get ar_m add s i 184 end 185 end 186 187 note ar_clear: words a .. b - 1 become 0 188 fn ar_clear a ulong b ulong to void 189 i = a 190 while lt i b bound `16777217` 191 put ar_m i 0 192 i = add i 1 193 end 194 end 195 196 note ar_need: group g is about to use index n; 0 when it may, 1 when the arena has no room (ar_fl set, 197 note nothing changed but a compaction). Below the group's capacity nothing happens; at or above it every 198 note region of the group grows to twice the capacity (at least n + 1, at least 64), moving to the top when 199 note not there already. When the moved copies do not fit in the free words, the arena is compacted (the 200 note words moved regions left behind are reclaimed) and the group grows in place (ar_relayout), to twice 201 note when that fits, else to the largest capacity that does (ar_gfit). So a table is refused only when 202 note the live tables with its group grown by one entry no longer fit in the arena. 203 fn ar_need g ulong n ulong to ulong 204 if eq get ar_nr 0 0 205 ar_defs 206 end 207 if ge n get ar_gp g 208 put ar_gp g add n 1 209 end 210 c = get ar_gc g 211 if lt n c 212 ret 0 213 end 214 c = shl c 1 215 if le c n 216 c = add n 1 217 end 218 if lt c 64 219 c = ulong 64 220 end 221 if gt ar_gneed g c sub len ar_m get ar_top 0 222 ar_compact 223 if gt ar_gextra g c sub len ar_m get ar_top 0 224 c = ar_gfit g n c 225 if eq c 0 226 put ar_fl 0 1 227 ret 1 228 end 229 end 230 ar_relayout g c 231 put ar_gc g c 232 ret 0 233 end 234 r = ulong 0 235 while lt r get ar_nr 0 bound 161 236 if eq get ar_rg r g 237 if ne ar_move r c 0 238 put ar_fl 0 1 239 ret 1 240 end 241 end 242 r = add r 1 243 end 244 put ar_gc g c 245 ret 0 246 end 247 248 note ar_gneed: the words group g's regions take at capacity c, counted as if every one of them moved 249 fn ar_gneed g ulong c ulong to ulong 250 s = ulong 0 251 r = ulong 0 252 while lt r get ar_nr 0 bound 161 253 if eq get ar_rg r g 254 s = add s ar_words r c 255 end 256 r = add r 1 257 end 258 ret s 259 end 260 261 note ar_gextra: the words group g's regions need beyond the words they hold, at capacity c 262 fn ar_gextra g ulong c ulong to ulong 263 s = ulong 0 264 r = ulong 0 265 while lt r get ar_nr 0 bound 161 266 if eq get ar_rg r g 267 w = ar_words r c 268 if gt w get ar_rw r 269 s = add s sub w get ar_rw r 270 end 271 end 272 r = add r 1 273 end 274 ret s 275 end 276 277 note ar_gfit: when doubling does not fit, the capacity group g grows to in place: the largest in n + 1 .. hi whose 278 note growth takes at most half the free words (binary search; the need grows with the capacity), so the other 279 note groups keep room to grow (omc's a_gfit takes all of it; ng's a64 stage grows several groups per function), 280 note else n + 1 when that alone fits in the free words, else 0 (the arena is full) 281 fn ar_gfit g ulong n ulong hi ulong to ulong 282 f = sub len ar_m get ar_top 0 283 lo = add n 1 284 if gt ar_gextra g lo f 285 ret 0 286 end 287 h = shr f 1 288 if gt ar_gextra g lo h 289 ret lo 290 end 291 while gt sub hi lo 1 bound 64 292 mid = add lo shr sub hi lo 1 293 if gt ar_gextra g mid h 294 hi = mid 295 else 296 lo = mid 297 end 298 end 299 ret lo 300 end 301 302 note ar_lowest: index + 1 of the region holding words with the lowest base above lb (any base when any is 303 note false), or 0 when none is left 304 fn ar_lowest any bool lb ulong to ulong 305 best = ulong 0 306 bb = ulong 0 307 r = ulong 0 308 while lt r get ar_nr 0 bound 161 309 if ne get ar_rw r 0 310 b = get ar_rb r 311 if or not any gt b lb 312 if or eq best 0 lt b bb 313 best = add r 1 314 bb = b 315 end 316 end 317 end 318 r = add r 1 319 end 320 ret best 321 end 322 323 note ar_compact: slide every region down over the words moved regions left behind, in order of base, so 324 note the free words are one run at the top again; the words above the new top become 0. Region 0, the 325 note payload, has base 0 and stays there. 326 fn ar_compact to void 327 t = get ar_top 0 328 pos = ulong 0 329 lb = ulong 0 330 any = false 331 k = ulong 0 332 while lt k 161 bound 162 333 best = ar_lowest any lb 334 if eq best 0 335 k = ulong 161 336 else 337 r = sub best 1 338 b = get ar_rb r 339 w = get ar_rw r 340 if ne b pos 341 ar_copy pos b w 342 put ar_rb r pos 343 end 344 pos = add pos w 345 lb = b 346 any = true 347 k = add k 1 348 end 349 end 350 ar_clear pos t 351 put ar_top 0 pos 352 put ar_wst 0 0 353 end 354 355 note ar_relayout: after ar_compact (regions contiguous from word 0 in order of base), give group g's 356 note regions their words at capacity c in place: new places in the same order, every region at or above 357 note its old place, moved from the top down (ar_copyd), each new tail zeroed. A region of g that holds no 358 note words yet goes at the top. 359 fn ar_relayout g ulong c ulong to void 360 k = ulong 0 361 lb = ulong 0 362 any = false 363 go = true 364 while go bound 162 365 best = ar_lowest any lb 366 if eq best 0 367 go = false 368 else 369 r = sub best 1 370 put ar_ord k r 371 k = add k 1 372 lb = get ar_rb r 373 any = true 374 end 375 end 376 r = ulong 0 377 while lt r get ar_nr 0 bound 161 378 if and eq get ar_rg r g eq get ar_rw r 0 379 put ar_ord k r 380 k = add k 1 381 end 382 r = add r 1 383 end 384 pos = ulong 0 385 i = ulong 0 386 while lt i k bound 161 387 r = get ar_ord i 388 put ar_np i pos 389 w = get ar_rw r 390 if eq get ar_rg r g 391 w = ar_words r c 392 end 393 pos = add pos w 394 i = add i 1 395 end 396 i = k 397 while gt i 0 bound 161 398 i = sub i 1 399 r = get ar_ord i 400 np = get ar_np i 401 b = get ar_rb r 402 w = get ar_rw r 403 if and ne np b ne w 0 404 ar_copyd np b w 405 end 406 put ar_rb r np 407 if eq get ar_rg r g 408 nw = ar_words r c 409 if gt nw w 410 ar_clear add np w add np nw 411 put ar_rw r nw 412 end 413 end 414 end 415 put ar_top 0 pos 416 end 417 418 note ar_zero: the first k words of region r become 0 419 fn ar_zero r ulong k ulong to void 420 b = get ar_rb r 421 ar_clear b add b k 422 end 423 424 note ar_gzero: every word of every region of group g becomes 0 (a hash table about to be rebuilt) 425 fn ar_gzero g ulong to void 426 r = ulong 0 427 while lt r get ar_nr 0 bound 161 428 if eq get ar_rg r g 429 ar_zero r get ar_rw r 430 end 431 r = add r 1 432 end 433 end 434 435 note ar_hash: the b-bit multiplicative hash of w (2^64 divided by the golden ratio, odd) 436 fn ar_hash w ulong b ulong to ulong 437 ret shr mul w `11400714819323198485` sub 64 b 438 end 439 440 note ar_oob: an index past its region is a fault of ng itself, never an input's: trap 3 (the pool check on 441 note ar_rb at index 160 + i, always past its 160), as an index past a fixed pool trapped 442 fn ar_oob i ulong to void 443 z = get ar_rb add 160 i 444 end 445 446 note ar_g / ar_p: element i of word region r, read or written, checked against the region (indices that 447 note come from input). ar_pc / ar_pu: element i of a uchar / uint region written (index by construction). 448 fn ar_g r ulong i ulong to ulong 449 if ge i get ar_rw r 450 ar_oob i 451 end 452 ret get ar_m add get ar_rb r i 453 end 454 fn ar_p r ulong i ulong v ulong to void 455 if ge i get ar_rw r 456 ar_oob i 457 end 458 put ar_m add get ar_rb r i v 459 end 460 note ar_w / ar_c / ar_u: element i of a ulong / uchar / uint region read through a call: the form of a line 461 note whose inline reads do not fit omc's 16-register expression pool (index by construction, unchecked) 462 fn ar_w r ulong i ulong to ulong 463 ret get ar_m add get ar_rb r i 464 end 465 fn ar_c r ulong i ulong to uchar 466 ret uchar get ar_m add get ar_rb r i 467 end 468 fn ar_u r ulong i ulong to uint 469 ret uint get ar_m add get ar_rb r i 470 end 471 fn ar_pw r ulong i ulong v ulong to void 472 put ar_m add get ar_rb r i v 473 end 474 fn ar_pc r ulong i ulong v uchar to void 475 put ar_m add get ar_rb r i ulong v 476 end 477 fn ar_pu r ulong i ulong v uint to void 478 put ar_m add get ar_rb r i ulong v 479 end 480 481 note ar_ib: byte i of region 0, the payload. It is the first region placed, so it starts at word 0. Past its 482 note words the byte is 0, as the zero pool past the input was. 483 fn ar_ib i ulong to uchar 484 x = shr i 3 485 if ge x get ar_rw 0 486 ret 0 487 end 488 ret uchar and shr get ar_m x shl and i 7 3 255 489 end 490 491 note ar_bg: byte i of byte region r (0 past its words) 492 fn ar_bg r ulong i ulong to uchar 493 x = shr i 3 494 if ge x get ar_rw r 495 ret 0 496 end 497 y = get ar_m add get ar_rb r x 498 ret uchar and shr y shl and i 7 3 255 499 end 500 501 note ar_bp: byte i of byte region r becomes v. Every writer asked ar_need for the byte first, so the index is in 502 note the region by construction and is not checked here (the omc owner measured 11 to 13% for checking every 503 note arena access; checks stay where an index comes from input: ar_g, ar_p, ar_ib) 504 fn ar_bp r ulong i ulong v uchar to void 505 x = add get ar_rb r shr i 3 506 s = shl and i 7 3 507 y = and get ar_m x not shl ulong 255 s 508 put ar_m x or y shl ulong v s 509 end 510 511 note ar_stage: bytes p .. p + c - 1 of the byte region at word b into ar_wb from 0 (c at most 65536). Bytes up to a 512 note word boundary one at a time, then each whole word read once for its 8 bytes, then the last bytes 513 fn ar_stage b ulong p ulong c ulong to void 514 i = ulong 0 515 while and lt i c ne and add p i 7 0 bound 8 516 ar_stage1 b add p i i 517 i = add i 1 518 end 519 while le add i 8 c bound 8193 520 y = get ar_m add b shr add p i 3 521 put ar_wb i uchar and y 255 522 put ar_wb add i 1 uchar and shr y 8 255 523 put ar_wb add i 2 uchar and shr y 16 255 524 put ar_wb add i 3 uchar and shr y 24 255 525 put ar_wb add i 4 uchar and shr y 32 255 526 put ar_wb add i 5 uchar and shr y 40 255 527 put ar_wb add i 6 uchar and shr y 48 255 528 put ar_wb add i 7 uchar shr y 56 529 i = add i 8 530 end 531 while lt i c bound 8 532 ar_stage1 b add p i i 533 i = add i 1 534 end 535 end 536 537 note ar_stage1: byte x of the byte region at word b into ar_wb at i 538 fn ar_stage1 b ulong x ulong i ulong to void 539 y = get ar_m add b shr x 3 540 put ar_wb i uchar and shr y shl and x 7 3 255 541 end 542 543 note ar_out: write bytes p .. e - 1 of byte region r to fd, 65536 at a time through ar_wb: 1 when every 544 note byte was written, 0 when a write returned 0 or less 545 fn ar_out fd ulong r ulong p ulong e ulong to ulong 546 b = get ar_rb r 547 q0 = p 548 while lt q0 e bound 2049 549 c = sub e q0 550 if gt c 65536 551 c = ulong 65536 552 end 553 ar_stage b q0 c 554 q = ulong 0 555 while lt q c bound 65537 556 n = write int fd ar_wb q sub c q 557 if le n 0 558 ret 0 559 end 560 q = add q ulong n 561 end 562 q0 = add q0 c 563 end 564 ret 1 565 end 566 567 note ar_rdin: all of fd into region 0 (the payload), eight bytes to a word from word 0, before any other 568 note region is placed: 0 done, 1 a read error, 2 the arena is full (ar_inl: the bytes read). The region 569 note then keeps the words the bytes fill and 8 more (zero): the input bytes are read inline past their end 570 note by at most that much (the tokenizers look one or two bytes ahead), and the next region starts after. 571 fn ar_rdin fd int to ulong 572 off = ulong 0 573 go = true 574 while go bound `134217729` 575 n = read fd ar_wb 0 65536 576 if eq n 0 577 go = false 578 else 579 if lt n 0 580 put ar_inl 0 off 581 ret 1 582 end 583 c = ulong n 584 put ar_inl 0 add off c 585 if ne ar_need 0 add off c 0 586 ret 2 587 end 588 ar_pack off c 589 off = add off c 590 end 591 end 592 put ar_inl 0 off 593 w = add shr off 3 8 594 if ne ar_need 0 sub shl w 3 1 0 595 ret 2 596 end 597 put ar_rw 0 w 598 put ar_top 0 w 599 put ar_gc 0 shl w 3 600 ret 0 601 end 602 603 note ar_pack: the c bytes of ar_wb become payload bytes off .. off + c - 1 (their words are 0 until now). Bytes 604 note up to a word boundary one at a time, then whole words of 8 (one store each), then the last bytes (measured 605 note under qemu-aarch64 on a 14785-byte unit: 502253 guest instructions a byte at a time, 160761 this way) 606 fn ar_pack off ulong c ulong to void 607 i = ulong 0 608 while and lt i c ne and add off i 7 0 bound 8 609 ar_pack1 add off i get ar_wb i 610 i = add i 1 611 end 612 while le add i 8 c bound 8193 613 y = ulong get ar_wb i 614 y = or y shl ulong get ar_wb add i 1 8 615 y = or y shl ulong get ar_wb add i 2 16 616 y = or y shl ulong get ar_wb add i 3 24 617 y = or y shl ulong get ar_wb add i 4 32 618 y = or y shl ulong get ar_wb add i 5 40 619 y = or y shl ulong get ar_wb add i 6 48 620 y = or y shl ulong get ar_wb add i 7 56 621 put ar_m shr add off i 3 y 622 i = add i 8 623 end 624 while lt i c bound 8 625 ar_pack1 add off i get ar_wb i 626 i = add i 1 627 end 628 end 629 630 note ar_pack1: payload byte x becomes b (its word's other bytes are kept) 631 fn ar_pack1 x ulong b uchar to void 632 w = shr x 3 633 put ar_m w or get ar_m w shl ulong b shl and x 7 3 634 end 635 636 note ar_gwords: the words the regions of group g hold 637 fn ar_gwords g ulong to ulong 638 s = ulong 0 639 r = ulong 0 640 while lt r get ar_nr 0 bound 161 641 if eq get ar_rg r g 642 s = add s get ar_rw r 643 end 644 r = add r 1 645 end 646 ret s 647 end 648 649 note ar_gcount: what group g was asked to hold: the payload's and the output's bytes, else the highest index 650 note asked for, plus 1 (bytes for a byte group) 651 fn ar_gcount g ulong to ulong 652 if eq g 0 653 ret get ar_inl 0 654 end 655 if eq g 1 656 ret get ar_oc 0 657 end 658 ret get ar_gp g 659 end 660 661 note record writer: bytes into ar_rbuf (flushed to fd when near full) 662 fn ar_rb1 fd ulong b ulong to void 663 c = get ar_rc 0 664 if ge c 4000 665 w = write int fd ar_rbuf 0 c 666 c = ulong 0 667 end 668 put ar_rbuf c uchar b 669 put ar_rc 0 add c 1 670 end 671 fn ar_rn fd ulong v ulong to void 672 d = ulong 1 673 while le d div v 10 bound 20 674 d = mul d 10 675 end 676 x = v 677 while gt d 0 bound 21 678 ar_rb1 fd add 48 div x d 679 x = rem x d 680 d = div d 10 681 end 682 end 683 note ar_rs: the bytes "k=" of a key packed little-endian in w (n bytes) 684 fn ar_rs fd ulong w ulong n ulong to void 685 x = w 686 for i ulong n bound 8 687 ar_rb1 fd and x 255 688 x = shr x 8 689 end 690 end 691 692 note ar_rec: the ng-use record, one line to fd: ng-use 1 arena=A top=T waste=W full=F, then for each group 693 note LABEL=N/H, N what it was asked to hold (ar_gcount) and H the words it holds. A, T, W and H count 8-byte 694 note words of the arena; F is 1 when a stage was refused because the arena was full. 695 fn ar_rec fd ulong to void 696 put ar_rc 0 0 697 ar_rs fd `3539940853674764142` 8 698 ar_rs fd `17277100355641632` 7 699 ar_rn fd len ar_m 700 ar_rs fd `263879357472` 5 701 ar_rn fd get ar_top 0 702 ar_rs fd `17281524405729056` 7 703 ar_rn fd get ar_wst 0 704 ar_rs fd `67535885395488` 6 705 ar_rn fd get ar_fl 0 706 g = ulong 0 707 p = ulong 0 708 while lt p len ar_gl bound 1024 709 ar_rb1 fd 32 710 while ne get ar_gl p 32 bound 16 711 ar_rb1 fd ulong get ar_gl p 712 p = add p 1 713 end 714 p = add p 1 715 ar_rb1 fd 61 716 ar_rn fd ar_gcount g 717 ar_rb1 fd 47 718 ar_rn fd ar_gwords g 719 g = add g 1 720 end 721 ar_rb1 fd 10 722 w = write int fd ar_rbuf 0 get ar_rc 0 723 put ar_rc 0 0 724 end 725 726 note ar_die: a stage with no refusal path of its own: `ng: arena full`, the record, exit 14 727 text ar_dmsg "ng: arena full\n" 728 fn ar_die to void 729 w = write 2 ar_dmsg 0 len ar_dmsg 730 ar_rec 2 731 exit int 14 732 end 733 734 note ar_defs: the regions (generated by the one-off NgNoCaps codemod; region: name, group, kind) 735 note 0 f_inp group 0 (in) bytes 736 note 1 i_out group 1 (out) bytes 737 note 2 i_gdat group 2 (gdat) bytes 738 note 3 f_sitebu group 3 (site) bytes 739 note 4 f_nmname group 4 (names) ulong x1 740 note 5 f_nm_reg group 4 (names) uchar in a word x1 741 note 6 f_nmtype group 4 (names) uchar in a word x1 742 note 7 f_nm_len group 4 (names) ulong x1 743 note 8 f_nmkind group 4 (names) uchar in a word x1 744 note 9 f_nmaddr group 4 (names) ulong x1 745 note 10 f_nm_fv group 4 (names) uchar in a word x1 746 note 11 f_nm_lay group 4 (names) uchar in a word x1 747 note 12 f_nm_fr group 4 (names) uchar in a word x1 748 note 13 f_nm_lr group 4 (names) uchar in a word x1 749 note 14 f_nm_nx group 4 (names) ulong x1 750 note 15 f_nm_h group 5 (namehash) ulong x1 751 note 16 f_ln_o group 6 (long) ulong x1 752 note 17 f_ln_l group 6 (long) uchar in a word x1 753 note 18 f_ln_x group 6 (long) ulong x1 754 note 19 f_ln_h group 7 (longhash) ulong x1 755 note 20 f_fnname group 8 (fns) ulong x1 756 note 21 f_fn_ret group 8 (fns) uchar in a word x1 757 note 22 f_fn_np group 8 (fns) uchar in a word x1 758 note 23 f_fnnmle group 8 (fns) ulong x1 759 note 24 f_fn_off group 8 (fns) ulong x1 760 note 25 f_fn_inl group 8 (fns) uchar in a word x1 761 note 26 f_fnbody group 8 (fns) ulong x1 762 note 27 f_fn_bln group 8 (fns) ulong x1 763 note 28 f_settle group 8 (fns) uchar in a word x1 764 note 29 f_reach group 8 (fns) uchar in a word x1 765 note 30 f_fn_exp group 8 (fns) uchar in a word x1 766 note 31 f_fn_nx group 8 (fns) ulong x1 767 note 32 f_fn_pn group 8 (fns) ulong x6 768 note 33 f_fn_pt group 8 (fns) uchar in a word x6 769 note 34 f_fn_pl group 8 (fns) ulong x6 770 note 35 f_fn_pk group 8 (fns) uchar in a word x6 771 note 36 f_fnplay group 8 (fns) uchar in a word x6 772 note 37 f_fn_pfr group 8 (fns) uchar in a word x6 773 note 38 f_fn_h group 9 (fnhash) ulong x1 774 note 39 f_callfr group 10 (calls) ulong x1 775 note 40 f_callto group 10 (calls) ulong x1 776 note 41 f_bkind group 11 (blocks) ulong x1 777 note 42 f_breg group 11 (blocks) ulong x1 778 note 43 f_btyp group 11 (blocks) ulong x1 779 note 44 f_bnames group 11 (blocks) ulong x1 780 note 45 f_bheld group 11 (blocks) ulong x1 781 note 46 f_bdead group 11 (blocks) ulong x1 782 note 47 f_u_cur group 11 (blocks) ulong x1 783 note 48 f_u_line group 11 (blocks) ulong x1 784 note 49 f_u_it group 11 (blocks) ulong x1 785 note 50 f_u_k group 11 (blocks) ulong x1 786 note 51 f_u_nn group 11 (blocks) ulong x1 787 note 52 f_u_held group 11 (blocks) ulong x1 788 note 53 f_fz_ent group 11 (blocks) ulong x16 789 note 54 f_fz_thn group 11 (blocks) ulong x16 790 note 55 f_brkblk group 12 (breaks) ulong x1 791 note 56 f_cblk group 13 (conts) ulong x1 792 note 57 f_iefrom group 14 (inledge) ulong x1 793 note 58 f_ie_to group 14 (inledge) ulong x1 794 note 59 f_fr group 15 (depth) ulong x32 795 note 60 f_fwv group 15 (depth) ulong x1 796 note 61 f_ul_k group 15 (depth) ulong x6 797 note 62 f_ul_v group 15 (depth) ulong x6 798 note 63 f_k_deg group 16 (kahnfn) ulong x1 799 note 64 f_k_st group 16 (kahnfn) ulong x1 800 note 65 f_k_cu group 16 (kahnfn) ulong x1 801 note 66 f_k_q group 16 (kahnfn) ulong x1 802 note 67 f_k_ed group 17 (kahncall) ulong x1 803 note 68 f_lnw group 18 (lnames) ulong x1 804 note 69 f_lnk group 18 (lnames) uchar in a word x1 805 note 70 f_lnt group 18 (lnames) ulong x1 806 note 71 f_lnv group 18 (lnames) uint in a word x1 807 note 72 f_lnc group 18 (lnames) ulong x1 808 note 73 f_lnx group 18 (lnames) ulong x1 809 note 74 f_lnh group 19 (lnamehash) ulong x1 810 note 75 f_lsk group 20 (lstack) uchar in a word x1 811 note 76 f_lsn group 20 (lstack) ulong x1 812 note 77 f_lsm group 20 (lstack) ulong x1 813 note 78 f_lsj group 20 (lstack) uint in a word x1 814 note 79 f_lsh group 20 (lstack) uint in a word x1 815 note 80 f_lsx group 20 (lstack) uint in a word x1 816 note 81 f_lse group 20 (lstack) uint in a word x1 817 note 82 f_lsl group 20 (lstack) uint in a word x1 818 note 83 f_lss group 20 (lstack) ulong x1 819 note 84 f_lsv group 21 (lsnap) uint in a word x1 820 note 85 f_laq group 22 (laq) uint in a word x1 821 note 86 f_lca group 23 (lca) uint in a word x1 822 note 87 i_gty group 24 (irglob) uint in a word x1 823 note 88 i_gcl group 24 (irglob) uchar in a word x1 824 note 89 i_gd0 group 24 (irglob) ulong x1 825 note 90 a_gad group 25 (a64glob) ulong x1 826 note 91 a_vh group 26 (a64val) ulong x1 827 note 92 a_vs group 26 (a64val) ulong x1 828 note 93 a_ve group 26 (a64val) ulong x1 829 note 94 a_vx group 26 (a64val) uchar in a word x1 830 note 95 a_vr group 26 (a64val) uchar in a word x1 831 note 96 a_vsl group 26 (a64val) ulong x1 832 note 97 a_vnx group 26 (a64val) ulong x1 833 note 98 a_vln group 26 (a64val) ulong x1 834 note 99 a_vf group 26 (a64val) uchar in a word x1 835 note 100 a_nu group 26 (a64val) uint in a word x1 836 note 101 a_lin group 27 (a64live) ulong x1 837 note 102 a_lout group 27 (a64live) ulong x1 838 note 103 a_luse group 27 (a64live) ulong x1 839 note 104 a_ldef group 27 (a64live) ulong x1 840 note 105 a_cpc group 28 (a64call) ulong x1 841 note 106 a_cft group 28 (a64call) ulong x1 842 note 107 a_code group 29 (a64code) bytes 843 note 108 a_xpc group 30 (a64fix) ulong x1 844 note 109 a_xfm group 30 (a64fix) ulong x1 845 note 110 a_xa group 30 (a64fix) ulong x1 846 note 111 a_xl group 30 (a64fix) ulong x1 847 fn ar_defs to void 848 ar_def 0 0 0 849 ar_def 1 1 0 850 ar_def 2 2 0 851 ar_def 3 3 0 852 ar_def 4 4 1 853 ar_def 5 4 1 854 ar_def 6 4 1 855 ar_def 7 4 1 856 ar_def 8 4 1 857 ar_def 9 4 1 858 ar_def 10 4 1 859 ar_def 11 4 1 860 ar_def 12 4 1 861 ar_def 13 4 1 862 ar_def 14 4 1 863 ar_def 15 5 1 864 ar_def 16 6 1 865 ar_def 17 6 1 866 ar_def 18 6 1 867 ar_def 19 7 1 868 ar_def 20 8 1 869 ar_def 21 8 1 870 ar_def 22 8 1 871 ar_def 23 8 1 872 ar_def 24 8 1 873 ar_def 25 8 1 874 ar_def 26 8 1 875 ar_def 27 8 1 876 ar_def 28 8 1 877 ar_def 29 8 1 878 ar_def 30 8 1 879 ar_def 31 8 1 880 ar_def 32 8 6 881 ar_def 33 8 6 882 ar_def 34 8 6 883 ar_def 35 8 6 884 ar_def 36 8 6 885 ar_def 37 8 6 886 ar_def 38 9 1 887 ar_def 39 10 1 888 ar_def 40 10 1 889 ar_def 41 11 1 890 ar_def 42 11 1 891 ar_def 43 11 1 892 ar_def 44 11 1 893 ar_def 45 11 1 894 ar_def 46 11 1 895 ar_def 47 11 1 896 ar_def 48 11 1 897 ar_def 49 11 1 898 ar_def 50 11 1 899 ar_def 51 11 1 900 ar_def 52 11 1 901 ar_def 53 11 16 902 ar_def 54 11 16 903 ar_def 55 12 1 904 ar_def 56 13 1 905 ar_def 57 14 1 906 ar_def 58 14 1 907 ar_def 59 15 32 908 ar_def 60 15 1 909 ar_def 61 15 6 910 ar_def 62 15 6 911 ar_def 63 16 1 912 ar_def 64 16 1 913 ar_def 65 16 1 914 ar_def 66 16 1 915 ar_def 67 17 1 916 ar_def 68 18 1 917 ar_def 69 18 1 918 ar_def 70 18 1 919 ar_def 71 18 1 920 ar_def 72 18 1 921 ar_def 73 18 1 922 ar_def 74 19 1 923 ar_def 75 20 1 924 ar_def 76 20 1 925 ar_def 77 20 1 926 ar_def 78 20 1 927 ar_def 79 20 1 928 ar_def 80 20 1 929 ar_def 81 20 1 930 ar_def 82 20 1 931 ar_def 83 20 1 932 ar_def 84 21 1 933 ar_def 85 22 1 934 ar_def 86 23 1 935 ar_def 87 24 1 936 ar_def 88 24 1 937 ar_def 89 24 1 938 ar_def 90 25 1 939 ar_def 91 26 1 940 ar_def 92 26 1 941 ar_def 93 26 1 942 ar_def 94 26 1 943 ar_def 95 26 1 944 ar_def 96 26 1 945 ar_def 97 26 1 946 ar_def 98 26 1 947 ar_def 99 26 1 948 ar_def 100 26 1 949 ar_def 101 27 1 950 ar_def 102 27 1 951 ar_def 103 27 1 952 ar_def 104 27 1 953 ar_def 105 28 1 954 ar_def 106 28 1 955 ar_def 107 29 0 956 ar_def 108 30 1 957 ar_def 109 30 1 958 ar_def 110 30 1 959 ar_def 111 30 1 960 end 961 note ar_init: every region but the payload gets its first room after it: hash buckets 1024 962 note (fnhash, lnamehash, longhash, namehash), the output 65536 bytes, every other group 64 entries 963 fn ar_init to void 964 ar_defs 965 z = ar_need 1 65535 966 z = ar_need 2 63 967 z = ar_need 3 63 968 z = ar_need 4 63 969 z = ar_need 5 1023 970 z = ar_need 6 63 971 z = ar_need 7 1023 972 z = ar_need 8 63 973 z = ar_need 9 1023 974 z = ar_need 10 63 975 z = ar_need 11 63 976 z = ar_need 12 63 977 z = ar_need 13 63 978 z = ar_need 14 63 979 z = ar_need 15 63 980 z = ar_need 16 63 981 z = ar_need 17 63 982 z = ar_need 18 63 983 z = ar_need 19 1023 984 z = ar_need 20 63 985 z = ar_need 21 63 986 z = ar_need 22 63 987 z = ar_need 23 63 988 z = ar_need 24 63 989 z = ar_need 25 63 990 z = ar_need 26 63 991 z = ar_need 27 63 992 z = ar_need 28 63 993 z = ar_need 29 63 994 z = ar_need 30 63 995 for g ulong 31 996 put ar_gp g 0 997 end 998 put ar_gp 0 get ar_inl 0 999 end 1000 global i_on ulong 1 1001 note reader state: 0 cursor, 1 end, 2 refusal class (0 none), 3 refusal offset, 4 value base, 1002 note 5 block base, 6 function value count 1003 global i_rd ulong 8 1004 note ---- row table ---------------------------------------------------------------------------- 1005 fn ir_rskip to void 1006 while lt get i_rp 0 len i_rows bound `1000000` 1007 c = get i_rows get i_rp 0 1008 if and ne c 32 ne c 10 1009 ret 1010 end 1011 put i_rp 0 add get i_rp 0 1 1012 end 1013 end 1014 fn ir_rnum to ulong 1015 ir_rskip 1016 v = ulong 0 1017 while lt get i_rp 0 len i_rows bound 32 1018 c = get i_rows get i_rp 0 1019 if or lt c 48 gt c 57 1020 ret v 1021 end 1022 v = add mul v 10 ulong sub c 48 1023 put i_rp 0 add get i_rp 0 1 1024 end 1025 ret v 1026 end 1027 fn ir_rinit to void 1028 if ne get i_n 15 0 1029 ret 1030 end 1031 put i_n 15 1 1032 put i_rp 0 0 1033 while lt get i_rp 0 len i_rows bound 256 1034 o = ir_rnum 1035 ir_rskip 1036 s = get i_rp 0 1037 put i_rno o uint s 1038 while ne get i_rows get i_rp 0 32 bound 64 1039 put i_rp 0 add get i_rp 0 1 1040 end 1041 put i_rnl o uchar sub get i_rp 0 s 1042 put i_rtk o uchar ir_rnum 1043 put i_rim o uchar ir_rnum 1044 put i_rfx o uchar ir_rnum 1045 put i_rvr o uchar ir_rnum 1046 put i_rty o uchar ir_rnum 1047 put i_rok o 1 1048 ir_rskip 1049 end 1050 end 1051 note 1 when op o carries a token operand (E, R, and T except br) 1052 fn ir_htok op uint to uint 1053 k = get i_rtk op 1054 if or eq k 1 eq k 2 1055 ret 1 1056 end 1057 if and eq k 3 ne op 60 1058 ret 1 1059 end 1060 ret 0 1061 end 1062 note operand kind of slot k of op: 0 value, 1 block, 2 function 1063 fn ir_okd op uint k ulong to uint 1064 if eq op 60 1065 if eq k 0 1066 ret 1 1067 end 1068 end 1069 if eq op 61 1070 if ge k 2 1071 ret 1 1072 end 1073 end 1074 if or eq op 64 eq op 67 1075 if eq k 1 1076 ret 2 1077 end 1078 end 1079 ret 0 1080 end 1081 note ---- builder ------------------------------------------------------------------------------ 1082 note The builder's tables are those of IR.md s12 for a whole module (65536 types, struct fields and functions, 1083 note `1048576` blocks, `4194304` ops, `16777216` operand slots, `8388608` values); the reader refuses a count past 1084 note s12 before building. A builder (front-ir, ngrand, the oracles) asked for more ends with ir_lim: one stderr 1085 note line and exit 23 (LIMIT), never an index past a table. Globals and their data are in the arena (ir_glob). 1086 text i_limm "ng: refused class 23 (IR.md s12 table full while building)\n" 1087 fn ir_lim to void 1088 w = write 2 i_limm 0 len i_limm 1089 exit 23 1090 end 1091 fn ir_init to void 1092 ir_rinit 1093 for i ulong 15 1094 put i_n i 0 1095 end 1096 put i_on 0 0 1097 end 1098 fn ir_newv t uint k uint o uint to uint 1099 n = add get i_n 6 1 1100 if gt n `8388608` 1101 ir_lim 1102 end 1103 put i_n 6 n 1104 put i_vty n t 1105 put i_vk n uchar k 1106 put i_vo n o 1107 put i_vnx n 0 1108 put i_vno n 0 1109 ret uint n 1110 end 1111 note a type id equal to (k a b c d e) among table types, else 0 (structs compare their fields) 1112 fn ir_tfind k uint a uint b uint c uint d uint e uint to uint 1113 put i_tq 0 k 1114 put i_tq 1 a 1115 put i_tq 2 b 1116 put i_tq 3 c 1117 put i_tq 4 d 1118 put i_tq 5 e 1119 for i ulong get i_n 0 bound 65536 1120 t = add i 32 1121 if ir_tmat t 1122 ret uint t 1123 end 1124 end 1125 ret 0 1126 end 1127 fn ir_tmat t ulong to bool 1128 if ne uint get i_tk t get i_tq 0 1129 ret false 1130 end 1131 if ne get i_t1 t get i_tq 1 1132 ret false 1133 end 1134 if ne get i_t2 t get i_tq 2 1135 ret false 1136 end 1137 if ne get i_t3 t get i_tq 3 1138 ret false 1139 end 1140 if ne get i_t4 t get i_tq 4 1141 ret false 1142 end 1143 ret eq get i_t5 t get i_tq 5 1144 end 1145 fn ir_tadd k uint a uint b uint c uint d uint e uint to uint 1146 t = add get i_n 0 32 1147 if ge get i_n 0 65536 1148 ir_lim 1149 end 1150 put i_n 0 add get i_n 0 1 1151 put i_tk t uchar k 1152 put i_t1 t a 1153 put i_t2 t b 1154 put i_t3 t c 1155 put i_t4 t d 1156 put i_t5 t e 1157 ret uint t 1158 end 1159 fn ir_tget k uint a uint b uint c uint d uint e uint to uint 1160 t = ir_tfind k a b c d e 1161 if ne t 0 1162 ret t 1163 end 1164 ret ir_tadd k a b c d e 1165 end 1166 fn ir_tvec e uint l uint to uint 1167 ret ir_tget 1 e l 0 0 0 1168 end 1169 fn ir_tarr e uint c uint to uint 1170 ret ir_tget 2 e c 0 0 0 1171 end 1172 fn ir_tref t uint a uint s uint to uint 1173 ret ir_tget 4 t a s 0 0 1174 end 1175 fn ir_tslc e uint a uint s uint to uint 1176 ret ir_tget 5 e a s 0 0 1177 end 1178 fn ir_tfrg r uint m uint n uint k uint e uint to uint 1179 ret ir_tget 6 r m n k e 1180 end 1181 fn ir_tsb size uint to void 1182 put i_sp 0 ulong size 1183 put i_sp 1 get i_n 1 1184 end 1185 fn ir_tsf t uint off uint ord uint to void 1186 x = get i_n 1 1187 if ge x 65536 1188 ir_lim 1189 end 1190 put i_xty x t 1191 put i_xof x off 1192 put i_xor x uchar ord 1193 put i_n 1 add x 1 1194 end 1195 note the struct with the same size and fields as fields [f0, f0+nf) among table types, else 0 1196 fn ir_sfind size uint f0 ulong nf ulong to uint 1197 for i ulong get i_n 0 bound 65536 1198 t = add i 32 1199 if ir_smat t size nf 1200 if ir_seq ulong get i_t3 t f0 nf 1201 ret uint t 1202 end 1203 end 1204 end 1205 ret 0 1206 end 1207 fn ir_smat t ulong size uint nf ulong to bool 1208 if ne get i_tk t 3 1209 ret false 1210 end 1211 if ne get i_t1 t size 1212 ret false 1213 end 1214 ret eq ulong get i_t2 t nf 1215 end 1216 fn ir_seq a ulong b ulong n ulong to bool 1217 for j ulong n bound 64 1218 x = add a j 1219 y = add b j 1220 if ne get i_xty x get i_xty y 1221 ret false 1222 end 1223 if ne get i_xof x get i_xof y 1224 ret false 1225 end 1226 if ne get i_xor x get i_xor y 1227 ret false 1228 end 1229 end 1230 ret true 1231 end 1232 fn ir_tse to uint 1233 f0 = get i_sp 1 1234 nf = sub get i_n 1 f0 1235 size = uint get i_sp 0 1236 t = ir_sfind size f0 nf 1237 if ne t 0 1238 put i_n 1 f0 1239 ret t 1240 end 1241 ret ir_tadd 3 size uint nf uint f0 0 0 1242 end 1243 note ir_glob / ir_gbyt: a new global and its data bytes, in the arena (groups irglob and gdat); a full 1244 note arena ends the build (ar_die), and the reader asks for the room first so that it refuses with LIMIT 1245 fn ir_glob t uint cls uint to uint 1246 g = add get i_n 2 1 1247 if ne ar_need 24 g 0 1248 ar_die 1249 end 1250 put i_n 2 g 1251 ar_pu 87 g t 1252 ar_pc 88 g uchar cls 1253 put ar_m add get ar_rb 89 g get i_n 8 1254 ret uint g 1255 end 1256 fn ir_gbyt g uint b uint to void 1257 x = get i_n 8 1258 if ne ar_need 2 x 0 1259 ar_die 1260 end 1261 ar_bp 2 x uchar b 1262 put i_n 8 add x 1 1263 end 1264 fn ir_fnew kind uint flags uint res uint to uint 1265 f = add get i_n 3 1 1266 if gt f 65536 1267 ir_lim 1268 end 1269 put i_n 3 f 1270 fu = uint f 1271 put i_fk f uchar kind 1272 put i_ffl f uchar flags 1273 put i_frs f res 1274 put i_fnp f 0 1275 put i_fp1 f 0 1276 put i_fpt f 0 1277 put i_fb1 f 0 1278 put i_fbt f 0 1279 put i_fnb f 0 1280 put i_ftx f 0 1281 put i_fty f 0 1282 put i_ftz f 0 1283 put i_fsg f 0 1284 put i_ftk f ir_newv 20 0 fu 1285 ret fu 1286 end 1287 fn ir_fpar f uint t uint to uint 1288 v = ir_newv t 1 f 1289 if eq get i_fp1 f 0 1290 put i_fp1 f v 1291 else 1292 put i_vnx get i_fpt f v 1293 end 1294 put i_fpt f v 1295 put i_fnp f add get i_fnp f 1 1296 ret v 1297 end 1298 fn ir_fker f uint x uint y uint z uint sg uint to void 1299 put i_ftx f x 1300 put i_fty f y 1301 put i_ftz f z 1302 put i_fsg f uchar sg 1303 end 1304 fn ir_ftok f uint to uint 1305 ret get i_ftk f 1306 end 1307 fn ir_bpar b uint t uint to uint 1308 v = ir_newv t 2 b 1309 if eq get i_bp1 b 0 1310 put i_bp1 b v 1311 else 1312 put i_vnx get i_bpt b v 1313 end 1314 put i_bpt b v 1315 put i_bnp b add get i_bnp b 1 1316 ret v 1317 end 1318 fn ir_blk f uint to uint 1319 b = add get i_n 4 1 1320 if gt b `1048576` 1321 ir_lim 1322 end 1323 put i_n 4 b 1324 bu = uint b 1325 put i_bf b f 1326 put i_bnx b 0 1327 put i_bp1 b 0 1328 put i_bpt b 0 1329 put i_bnp b 0 1330 put i_bo1 b 0 1331 put i_bot b 0 1332 put i_bno b 0 1333 put i_bix b 0 1334 if eq get i_fb1 f 0 1335 put i_fb1 f bu 1336 else 1337 put i_bnx get i_fbt f bu 1338 end 1339 put i_fbt f bu 1340 put i_fnb f add get i_fnb f 1 1341 if gt get i_fnb f 1 1342 t = ir_bpar bu 20 1343 end 1344 ret bu 1345 end 1346 fn ir_btok b uint to uint 1347 ret get i_bp1 b 1348 end 1349 fn ir_odefs o uint to void 1350 op = uint get i_oop o 1351 t = get i_oty o 1352 put i_otk o 0 1353 put i_ors o 0 1354 if eq get i_rtk op 1 1355 put i_otk o ir_newv 20 3 o 1356 end 1357 c = get i_rty op 1358 if and ne t 0 or eq c 1 eq c 2 1359 put i_ors o ir_newv t 4 o 1360 end 1361 end 1362 fn ir_op b uint op uint ty uint imm ulong n uint to uint 1363 o = add get i_n 5 1 1364 if or gt o `4194304` gt add get i_n 7 ulong n `16777216` 1365 ir_lim 1366 end 1367 put i_n 5 o 1368 ou = uint o 1369 put i_oop o uchar op 1370 put i_oty o ty 1371 put i_oim o imm 1372 put i_ona o n 1373 a = get i_n 7 1374 put i_oa0 o uint a 1375 for j ulong ulong n bound 1024 1376 put i_arg add a j 0 1377 end 1378 put i_n 7 add a ulong n 1379 put i_ob o b 1380 put i_onx o 0 1381 put i_oof o 0 1382 if eq get i_bo1 b 0 1383 put i_bo1 b ou 1384 else 1385 put i_onx get i_bot b ou 1386 end 1387 put i_bot b ou 1388 put i_bno b add get i_bno b 1 1389 ir_odefs ou 1390 ret ou 1391 end 1392 fn ir_set o uint k uint h uint to void 1393 put i_arg add ulong get i_oa0 o ulong k h 1394 end 1395 fn ir_arg o uint k uint to uint 1396 ret get i_arg add ulong get i_oa0 o ulong k 1397 end 1398 fn ir_res o uint to uint 1399 ret get i_ors o 1400 end 1401 fn ir_otok o uint to uint 1402 ret get i_otk o 1403 end 1404 note wire value ids (IR.md s6.2) into i_vno and block positions into i_bix; returns the value count 1405 fn ir_num f uint to uint 1406 n = uint 0 1407 put i_vno get i_ftk f n 1408 n = add n 1 1409 v = get i_fp1 f 1410 while ne v 0 bound 65 1411 put i_vno v n 1412 n = add n 1 1413 v = get i_vnx v 1414 end 1415 b = get i_fb1 f 1416 x = uint 0 1417 while ne b 0 bound `1048577` 1418 put i_bix b x 1419 x = add x 1 1420 n = ir_numb b n 1421 b = get i_bnx b 1422 end 1423 ret n 1424 end 1425 fn ir_numb b uint n0 uint to uint 1426 n = n0 1427 v = get i_bp1 b 1428 while ne v 0 bound 65 1429 put i_vno v n 1430 n = add n 1 1431 v = get i_vnx v 1432 end 1433 o = get i_bo1 b 1434 while ne o 0 bound `4194305` 1435 if ne get i_otk o 0 1436 put i_vno get i_otk o n 1437 n = add n 1 1438 end 1439 if ne get i_ors o 0 1440 put i_vno get i_ors o n 1441 n = add n 1 1442 end 1443 o = get i_onx o 1444 end 1445 ret n 1446 end 1447 note bytes of one element or object of type t (0 for void, tok and invalid ids) 1448 fn ir_tsize t uint to ulong 1449 if lt t 32 1450 if or eq t 1 or eq t 2 or eq t 6 or eq t 18 eq t 19 1451 ret 1 1452 end 1453 if or eq t 3 or eq t 7 or eq t 16 eq t 17 1454 ret 2 1455 end 1456 if or eq t 4 or eq t 8 eq t 13 1457 ret 4 1458 end 1459 if or eq t 5 or eq t 9 eq t 14 1460 ret 8 1461 end 1462 ret 0 1463 end 1464 if ge ulong t add get i_n 0 32 1465 ret 0 1466 end 1467 k = get i_tk t 1468 if eq k 1 1469 ret mul ulong get i_t2 t ir_tsize get i_t1 t 1470 end 1471 if eq k 2 1472 ret mul ulong get i_t2 t ir_tsize get i_t1 t 1473 end 1474 if eq k 3 1475 ret ulong get i_t1 t 1476 end 1477 ret 0 1478 end 1479 note ---- binary writer (IR.md s3-s7) ---------------------------------------------------------- 1480 note ir_wn: the k (at most 8) low bytes of v at the output's end (region 1 asked for them first). The output is 1481 note written from byte 0 in order, so the first byte of each word sets the word and the others are ORed in (inline) 1482 fn ir_wn v ulong k ulong to void 1483 p = get i_on 0 1484 if ne ar_need 1 add p k 0 1485 ar_die 1486 end 1487 b = get ar_rb 1 1488 for j ulong k bound 8 1489 q = add p j 1490 x = add b shr q 3 1491 d = and shr v mul j 8 255 1492 c = shl d shl and q 7 3 1493 if ne and q 7 0 1494 c = or c get ar_m x 1495 end 1496 put ar_m x c 1497 end 1498 put i_on 0 add p k 1499 put ar_oc 0 add p k 1500 end 1501 fn ir_wty t ulong to void 1502 k = ulong get i_tk t 1503 ir_wn k 1 1504 if eq k 6 1505 ir_wn ulong get i_t1 t 1 1506 ir_wn ulong get i_t2 t 2 1507 ir_wn ulong get i_t3 t 2 1508 ir_wn ulong get i_t4 t 2 1509 ir_wn ulong get i_t5 t 4 1510 ret 1511 end 1512 if eq k 3 1513 ir_wn ulong get i_t1 t 4 1514 ir_wn ulong get i_t2 t 4 1515 f0 = ulong get i_t3 t 1516 for j ulong ulong get i_t2 t bound 64 1517 ir_wn ulong get i_xty add f0 j 4 1518 ir_wn ulong get i_xof add f0 j 4 1519 ir_wn ulong get i_xor add f0 j 1 1520 end 1521 ret 1522 end 1523 ir_wn ulong get i_t1 t 4 1524 if or eq k 1 eq k 2 1525 ir_wn ulong get i_t2 t 4 1526 ret 1527 end 1528 ir_wn ulong get i_t2 t 1 1529 ir_wn ulong get i_t3 t 1 1530 end 1531 fn ir_wglb g ulong to void 1532 ir_wn ulong uint get ar_m add get ar_rb 87 g 4 1533 ir_wn ulong uchar get ar_m add get ar_rb 88 g 1 1534 if eq ar_c 88 g 1 1535 s = ir_tsize uint get ar_m add get ar_rb 87 g 1536 d = get ar_m add get ar_rb 89 g 1537 p = get i_on 0 1538 if ne ar_need 1 add p s 0 1539 ar_die 1540 end 1541 for j ulong s bound `134217729` 1542 ar_bp 1 add p j ar_bg 2 add d j 1543 end 1544 put i_on 0 add p s 1545 end 1546 end 1547 fn ir_wval h uint to void 1548 ir_wn ulong get i_vno h 4 1549 end 1550 fn ir_wop o uint to void 1551 op = uint get i_oop o 1552 ir_wn ulong op 1 1553 ir_wn ulong get i_oty o 4 1554 if eq get i_rim op 1 1555 if or eq op 52 and ge op 111 le op 116 1556 ir_wn sub get i_oim o 1 8 1557 else 1558 ir_wn get i_oim o 8 1559 end 1560 end 1561 na = ulong get i_ona o 1562 if eq get i_rvr op 1 1563 ir_wn sub sub na ulong get i_rfx op ulong ir_htok op 4 1564 end 1565 a0 = ulong get i_oa0 o 1566 for k ulong na bound 1024 1567 h = get i_arg add a0 k 1568 d = ir_okd op k 1569 if eq d 0 1570 ir_wval h 1571 end 1572 if eq d 1 1573 ir_wn ulong get i_bix h 4 1574 end 1575 if eq d 2 1576 ir_wn sub ulong h 1 4 1577 end 1578 end 1579 end 1580 fn ir_wblk b uint to void 1581 ir_wn ulong get i_bnp b 4 1582 v = get i_bp1 b 1583 while ne v 0 bound 65 1584 ir_wn ulong get i_vty v 4 1585 v = get i_vnx v 1586 end 1587 ir_wn ulong get i_bno b 4 1588 o = get i_bo1 b 1589 while ne o 0 bound `4194305` 1590 ir_wop o 1591 o = get i_onx o 1592 end 1593 end 1594 fn ir_wfn f uint to void 1595 n = ir_num f 1596 ir_wn ulong get i_fk f 1 1597 ir_wn ulong get i_ffl f 1 1598 ir_wn ulong get i_fnp f 4 1599 v = get i_fp1 f 1600 while ne v 0 bound 65 1601 ir_wn ulong get i_vty v 4 1602 v = get i_vnx v 1603 end 1604 ir_wn ulong get i_frs f 4 1605 if eq get i_fk f 1 1606 ir_wn ulong get i_ftx f 4 1607 ir_wn ulong get i_fty f 4 1608 ir_wn ulong get i_ftz f 4 1609 ir_wn ulong get i_fsg f 1 1610 end 1611 ir_wn ulong get i_fnb f 4 1612 b = get i_fb1 f 1613 while ne b 0 bound `1048577` 1614 ir_wblk b 1615 b = get i_bnx b 1616 end 1617 end 1618 fn ir_wr to ulong 1619 put i_on 0 0 1620 for j ulong 6 1621 ir_wn ulong get i_magic j 1 1622 end 1623 ir_wn 0 1 1624 ir_wn 9 1 1625 for j ulong 14 1626 ir_wn ulong get i_tag j 1 1627 end 1628 ir_wn 0 2 1629 ir_wn get i_n 0 4 1630 for i ulong get i_n 0 bound 65536 1631 ir_wty add i 32 1632 end 1633 ir_wn get i_n 2 4 1634 for i ulong get i_n 2 bound `134217729` 1635 ir_wglb add i 1 1636 end 1637 ir_wn get i_n 3 4 1638 for i ulong get i_n 3 bound 65536 1639 ir_wfn uint add i 1 1640 end 1641 ret get i_on 0 1642 end 1643 note ---- binary reader ------------------------------------------------------------------------ 1644 note refusal: the first class sticks, with the cursor offset (or at, when given) 1645 fn ir_bad c ulong ofs ulong to void 1646 if eq get i_rd 2 0 1647 put i_rd 2 c 1648 put i_rd 3 ofs 1649 end 1650 end 1651 fn ir_ok to bool 1652 ret eq get i_rd 2 0 1653 end 1654 fn ir_rn k ulong to ulong 1655 p = get i_rd 0 1656 if gt add p k get i_rd 1 1657 ir_bad 12 p 1658 put i_rd 0 get i_rd 1 1659 ret 0 1660 end 1661 note the payload bytes p .. p + k - 1 are inside region 0 (p + k is at most the payload's end, checked above), 1662 note which sits at word 0: read inline, no per-byte check 1663 v = ulong 0 1664 for j ulong k bound 8 1665 q = add p j 1666 w = get ar_m shr q 3 1667 v = or v shl and shr w shl and q 7 3 255 mul j 8 1668 end 1669 put i_rd 0 add p k 1670 ret v 1671 end 1672 fn ir_rhdr to void 1673 p = get i_rd 0 1674 for j ulong 6 1675 if ne ir_rn 1 ulong get i_magic j 1676 ir_bad 10 p 1677 end 1678 end 1679 if ne ir_rn 1 0 1680 ir_bad 10 p 1681 end 1682 q = get i_rd 0 1683 if ne ir_rn 1 9 1684 ir_bad 11 q 1685 end 1686 q = get i_rd 0 1687 for j ulong 14 1688 if ne ir_rn 1 ulong get i_tag j 1689 ir_bad 11 q 1690 end 1691 end 1692 if ne ir_rn 2 0 1693 ir_bad 11 q 1694 end 1695 end 1696 note a type id usable inside table entry id: a valid built-in or an earlier table id 1697 fn ir_tval t ulong id ulong to bool 1698 if lt t 32 1699 if or or eq t 10 eq t 11 or eq t 12 eq t 15 1700 ret false 1701 end 1702 ret le t 20 1703 end 1704 ret lt t id 1705 end 1706 fn ir_rtref t ulong id ulong ofs ulong to uint 1707 if not ir_tval t id 1708 ir_bad 24 ofs 1709 end 1710 ret uint t 1711 end 1712 fn ir_rty1 to void 1713 ofs = get i_rd 0 1714 id = add get i_n 0 32 1715 k = ir_rn 1 1716 if or eq k 1 eq k 2 1717 e = ir_rtref ir_rn 4 id ofs 1718 c = uint ir_rn 4 1719 if ne ir_tfind uint k e c 0 0 0 0 1720 ir_bad 13 ofs 1721 end 1722 t = ir_tadd uint k e c 0 0 0 1723 ret 1724 end 1725 if eq k 3 1726 ir_rstr ofs id 1727 ret 1728 end 1729 if or eq k 4 eq k 5 1730 e = ir_rtref ir_rn 4 id ofs 1731 a = ir_rn 1 1732 s = ir_rn 1 1733 if or gt a 1 gt s 4 1734 ir_bad 13 ofs 1735 end 1736 if ne ir_tfind uint k e uint a uint s 0 0 0 1737 ir_bad 13 ofs 1738 end 1739 t = ir_tadd uint k e uint a uint s 0 0 1740 ret 1741 end 1742 if eq k 6 1743 r = uint ir_rn 1 1744 m = uint ir_rn 2 1745 n = uint ir_rn 2 1746 kk = uint ir_rn 2 1747 e = ir_rtref ir_rn 4 id ofs 1748 if gt r 2 1749 ir_bad 13 ofs 1750 end 1751 if ne ir_tfind 6 r m n kk e 0 1752 ir_bad 13 ofs 1753 end 1754 t = ir_tadd 6 r m n kk e 1755 ret 1756 end 1757 ir_bad 13 ofs 1758 end 1759 fn ir_rstr ofs ulong id ulong to void 1760 size = uint ir_rn 4 1761 nf = ir_rn 4 1762 if gt nf 64 1763 ir_bad 23 sub get i_rd 0 4 1764 ret 1765 end 1766 f0 = get i_n 1 1767 if gt add f0 nf 65536 1768 ir_bad 23 sub get i_rd 0 4 1769 ret 1770 end 1771 for j ulong nf bound 64 1772 t = ir_rtref ir_rn 4 id ofs 1773 o = uint ir_rn 4 1774 r = ir_rn 1 1775 if gt r 1 1776 ir_bad 13 ofs 1777 end 1778 ir_tsf t o uint r 1779 end 1780 if ne ir_sfind size f0 nf 0 1781 ir_bad 13 ofs 1782 end 1783 t = ir_tadd 3 size uint nf uint f0 0 0 1784 end 1785 fn ir_rtys to void 1786 ofs = get i_rd 0 1787 n = ir_rn 4 1788 if gt n 65536 1789 ir_bad 23 ofs 1790 ret 1791 end 1792 for i ulong n bound 65536 1793 if not ir_ok 1794 ret 1795 end 1796 ir_rty1 1797 end 1798 end 1799 note globals: the count is bounded by the arena only (group irglob; src/ir.om, no-caps 2026-11-11); ngcheck 1800 note and the text tools keep the 65536 of IR.md s12. A count the arena cannot hold is LIMIT at the entry. 1801 fn ir_rglbs to void 1802 n = ir_rn 4 1803 for i ulong n bound `134217729` 1804 if not ir_ok 1805 ret 1806 end 1807 if ne ar_need 24 add get i_n 2 1 0 1808 ir_bad 23 get i_rd 0 1809 ret 1810 end 1811 ir_rglb 1812 end 1813 end 1814 fn ir_rglb to void 1815 ofs = get i_rd 0 1816 t = uint ir_rn 4 1817 c = ir_rn 1 1818 if gt c 2 1819 ir_bad 13 ofs 1820 ret 1821 end 1822 g = ir_glob t uint c 1823 if ne c 1 1824 ret 1825 end 1826 if or ge ulong t add get i_n 0 32 lt t 32 1827 ir_bad 16 ofs 1828 ret 1829 end 1830 if ne get i_tk t 2 1831 ir_bad 16 ofs 1832 ret 1833 end 1834 s = ir_tsize t 1835 p = get i_rd 0 1836 if gt add p s get i_rd 1 1837 ir_bad 12 p 1838 put i_rd 0 get i_rd 1 1839 ret 1840 end 1841 d = get i_n 8 1842 if ne ar_need 2 add d s 0 1843 ir_bad 23 p 1844 put i_rd 0 get i_rd 1 1845 ret 1846 end 1847 for j ulong s bound `134217729` 1848 ar_bp 2 add d j ar_ib add p j 1849 end 1850 put i_n 8 add d s 1851 put i_rd 0 add p s 1852 end 1853 fn ir_rfns to void 1854 ofs = get i_rd 0 1855 n = ir_rn 4 1856 if gt n 65536 1857 ir_bad 23 ofs 1858 ret 1859 end 1860 for i ulong n bound 65536 1861 if not ir_ok 1862 ret 1863 end 1864 ir_rfn 1865 end 1866 end 1867 fn ir_rfn to void 1868 ofs = get i_rd 0 1869 k = ir_rn 1 1870 fl = ir_rn 1 1871 if or gt k 2 gt fl 3 1872 ir_bad 13 ofs 1873 ret 1874 end 1875 pa = get i_rd 0 1876 np = ir_rn 4 1877 if gt np 64 1878 ir_bad 23 pa 1879 ret 1880 end 1881 note flags bit 1 (IR.md s6.1): the callback function of a `target macos` unit, six u64 and a u64 result 1882 bk = ge fl 2 1883 if and bk or ne k 0 ne np 6 1884 ir_bad 13 ofs 1885 ret 1886 end 1887 f = ir_fnew uint k uint fl 0 1888 if bk 1889 g = ulong 1 1890 while lt g ulong f bound 65537 1891 if ge ulong get i_ffl g 2 1892 ir_bad 13 ofs 1893 end 1894 g = add g 1 1895 end 1896 end 1897 put i_rd 4 ulong get i_ftk f 1898 put i_rd 5 add get i_n 4 1 1899 for j ulong np bound 64 1900 pt = ir_rn 4 1901 if and bk ne pt 5 1902 ir_bad 13 ofs 1903 end 1904 v = ir_fpar f uint pt 1905 end 1906 rs = ir_rn 4 1907 if and bk ne rs 5 1908 ir_bad 13 ofs 1909 end 1910 if not ir_ok 1911 ret 1912 end 1913 put i_frs f uint rs 1914 if eq k 1 1915 x = uint ir_rn 4 1916 y = uint ir_rn 4 1917 z = uint ir_rn 4 1918 ir_fker f x y z uint ir_rn 1 1919 end 1920 pb = get i_rd 0 1921 nb = ir_rn 4 1922 if or eq nb 0 gt nb 65536 1923 ir_bad 23 pb 1924 ret 1925 end 1926 for j ulong nb bound 65536 1927 if not ir_ok 1928 ret 1929 end 1930 ir_rblk f 1931 end 1932 if ir_ok 1933 ir_rfix f 1934 end 1935 end 1936 fn ir_rblk f uint to void 1937 b = ir_blk f 1938 pa = get i_rd 0 1939 np = ir_rn 4 1940 if gt np 64 1941 ir_bad 23 pa 1942 ret 1943 end 1944 for j ulong np bound 64 1945 t = uint ir_rn 4 1946 if and eq j 0 gt get i_fnb f 1 1947 put i_vty get i_bp1 b t 1948 else 1949 v = ir_bpar b t 1950 end 1951 end 1952 if and gt get i_fnb f 1 eq np 0 1953 ir_bad 19 pa 1954 ret 1955 end 1956 po = get i_rd 0 1957 no = ir_rn 4 1958 if gt no `1048576` 1959 ir_bad 23 po 1960 ret 1961 end 1962 if eq no 0 1963 ir_bad 20 po 1964 ret 1965 end 1966 for j ulong no bound `1048576` 1967 if not ir_ok 1968 ret 1969 end 1970 ir_rop b 1971 end 1972 end 1973 fn ir_rop b uint to void 1974 ofs = get i_rd 0 1975 op = uint ir_rn 1 1976 if eq get i_rok op 0 1977 ir_bad 15 ofs 1978 ret 1979 end 1980 ty = uint ir_rn 4 1981 im = ulong 0 1982 if eq get i_rim op 1 1983 im = ir_rn 8 1984 end 1985 n = add uint get i_rfx op ir_htok op 1986 if eq get i_rvr op 1 1987 pn = get i_rd 0 1988 x = ir_rn 4 1989 if gt x 64 1990 ir_bad 23 pn 1991 ret 1992 end 1993 n = add n uint x 1994 end 1995 if or eq op 52 and ge op 111 le op 116 1996 im = add im 1 1997 end 1998 if gt add get i_n 5 1 `4194304` 1999 ir_bad 23 ofs 2000 ret 2001 end 2002 o = ir_op b op ty im n 2003 put i_oof o uint ofs 2004 a0 = ulong get i_oa0 o 2005 for k ulong ulong n bound 1024 2006 put i_arg add a0 k uint ir_rn 4 2007 end 2008 end 2009 note turn wire ids of function f into handles (values, blocks) and check them (IR.md s6.2) 2010 fn ir_rfix f uint to void 2011 put i_rd 7 ulong ir_num f 2012 put i_rd 6 ulong get i_fnb f 2013 b = get i_fb1 f 2014 while ne b 0 bound `1048577` 2015 o = get i_bo1 b 2016 while ne o 0 bound `4194305` 2017 ir_rfxo o 2018 o = get i_onx o 2019 end 2020 b = get i_bnx b 2021 end 2022 end 2023 fn ir_rfxo o uint to void 2024 n = ulong get i_ona o 2025 for k ulong n bound 1024 2026 if not ir_rfx1 o k 2027 ir_bad 24 ulong get i_oof o 2028 ret 2029 end 2030 end 2031 if eq get i_oop o 52 2032 im = get i_oim o 2033 if or eq im 0 gt im get i_n 2 2034 ir_bad 24 ulong get i_oof o 2035 end 2036 end 2037 end 2038 note map operand slot k of op o from a wire id to a handle; false when the id is out of range 2039 fn ir_rfx1 o uint k ulong to bool 2040 s = add ulong get i_oa0 o k 2041 x = ulong get i_arg s 2042 d = ir_okd uint get i_oop o k 2043 if eq d 0 2044 if ge x get i_rd 7 2045 ir_bad 17 ulong get i_oof o 2046 ret true 2047 end 2048 put i_arg s uint add get i_rd 4 x 2049 end 2050 if eq d 1 2051 if ge x get i_rd 6 2052 ret false 2053 end 2054 put i_arg s uint add get i_rd 5 x 2055 end 2056 if eq d 2 2057 if ge x 65536 2058 ret false 2059 end 2060 put i_arg s uint add x 1 2061 end 2062 ret true 2063 end 2064 note function operands after all functions are known 2065 fn ir_rfnref to void 2066 for i ulong get i_n 5 bound `4194304` 2067 o = add i 1 2068 op = uint get i_oop o 2069 if or eq op 64 eq op 67 2070 if gt ulong ir_arg uint o 1 get i_n 3 2071 ir_bad 24 ulong get i_oof o 2072 end 2073 end 2074 end 2075 end 2076 fn ir_read off ulong stop ulong to ulong 2077 ir_init 2078 put i_rd 0 off 2079 put i_rd 1 stop 2080 put i_rd 2 0 2081 put i_rd 3 0 2082 ir_rhdr 2083 if ir_ok 2084 ir_rtys 2085 end 2086 if ir_ok 2087 ir_rglbs 2088 end 2089 if ir_ok 2090 ir_rfns 2091 end 2092 if ir_ok 2093 ir_rfnref 2094 end 2095 if ir_ok 2096 if ne get i_rd 0 stop 2097 ir_bad 14 get i_rd 0 2098 end 2099 end 2100 ret get i_rd 2 2101 end 2102 fn ir_badat to ulong 2103 ret get i_rd 3 2104 end