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/build/units.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 / build / units.om` 1138 lines ยท 23007 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/build/units.om: Pure seeded-Omega C-Binding & Units Regenerator. 3 note Replaces om/units.sh completely with exact byte-for-byte parity. Zero shell, zero sed/tr/wc/cmp. 4 note Build: cat seed/build/common.om seed/build/units.om | seed/out/omc > build/om-units 5 note Usage: om-units [--check] 6 note Env: 7 note OMEGA_OMC pinned omc binary (default checked against seed/out/omc.sha256 or OMEGA_OMC_PIN) 8 note OMEGA_BRIDGE omega-bridge checkout (src/native.om pinned against OMEGA_NATIVE_PIN) 9 note OMEGA_UNITS optional space-separated unit override 10 note OMEGA_UNITS_DEST optional output directory (default src) 11 12 text un_fcheck "--check" 13 text un_env_omc "OMEGA_OMC" 14 text un_env_br "OMEGA_BRIDGE" 15 text un_env_units "OMEGA_UNITS" 16 text un_env_dest "OMEGA_UNITS_DEST" 17 text un_env_omcpin "OMEGA_OMC_PIN" 18 text un_env_natpin "OMEGA_NATIVE_PIN" 19 text un_def_natpin "`9788b27a92c8dd365de7052439653de62f89634189a34cb6b3f582cae65dda83`" 20 text un_pin_file "seed/out/omc.sha256" 21 text un_nat_rel "/src/native.om" 22 text un_def_dest "src" 23 text un_nr_env "NOT_RUN: set OMEGA_OMC and OMEGA_BRIDGE\n" 24 text un_nr_omc "NOT_RUN: omc is not the pinned compiler\n" 25 text un_nr_nat "NOT_RUN: native.om is not the pinned generator\n" 26 text un_fail_io "FAIL: units I/O or tool error\n" 27 text un_fail_diff1 "FAIL " 28 text un_fail_diff2 " differs from the pinned tools' output\n" 29 text un_pass_chk "PASS src/{omega_om_units.c,omega_native.h,omega_api_decl.h,omega_om_units.ident,omega_om_units_fs.c} regenerate byte for byte\n" 30 text un_wrote1 "wrote " 31 text un_wrote2 "/{omega_om_units.c,omega_native.h,omega_api_decl.h,omega_om_units.ident,omega_om_units_fs.c}\n" 32 text un_nofs "/* No freestanding GPU units selected. */\n" 33 34 text un_def_units "om/arboris_arena.om om/arboris_spread.om om/arboris_spread_plan.om om/arboris_spread_cpu.om om/bw_arboris_spread_emit.om om/arboris_gated.om om/blackwell_arboris_emit.om om/blackwell_arboris_qmd.om gpu/nvidia/om/codegen/bw_hazard.om om/sha256/sha256-om2.om om/blake3/b3unit.om om/encoder/bw_enc_sm121.om om/aarch64/aarch64_om2.om om/visor/canonical_om2.om om/visor/validate_om2.om om/visor/codec_om2.om om/visor/verify_om2.om om/gpu/bw_qmd.om om/gpu/bw_sched.om om/gpu/bw_regalloc.om om/gpu/bw_vecadd.om om/gpu/cg_matmul.om om/gpu/cg_gpu_gemm.om om/gpu/cg_gpu_attn.om om/gpu/q38_plan.om om/gpu/moe_plan.om om/gpu/cg_pf.om om/gpu/cg_bf16.om om/gpu/cg_gemm.om om/gpu/cg_moe2.om om/gpu/cg_moe.om om/gpu/cg_qmma.om om/gpu/cg_pfhost.om om/gpu/cg_tgemm.om om/gpu/cg_tc2.om om/gpu/cg_qg.om om/gpu/cg_tc.om om/gpu/cg_pattn256.om om/gpu/cg_router.om om/gpu/cg_pattn.om om/gpu/cg_attn.om om/gpu/cg_tern.om om/gpu/cg_attn256.om om/gpu/cg_dec.om om/gpu/cg_gdn.om om/runtime/rx_regulate.om om/runtime/rx_mid.om om/runtime/rx_cortex_rec.om om/runtime/rx_plan_core.om om/runtime/rx_projection.om om/runtime/rx_capq_core.om om/runtime/rx_costmodel_core.om om/runtime/rx_route_core.om om/runtime/rx_world_core.om om/runtime/rx_coherent_om2.om om/runtime/rx_semantic_om2.om om/runtime/rx_skillroute_core.om om/runtime/rx_fusion_core.om seed/authority/cap_table_om2.om seed/authority/aegis_om2.om om/compiler/osc_literal.om om/compiler/osc_type.om om/compiler/osc_expr.om om/compiler/osc_scalar.om om/compiler/osc_a64_fields.om om/compiler/osc_statement.om om/compiler/osc_ownership.om om/compiler/osc_scope.om om/compiler/osc_pool.om om/compiler/osc_trace.om om/compiler/osc_lifetimes.om om/compiler/osc_flow.om om/compiler/osc_artifact.om src/tensor/tensor_shape.om src/tensor/tensor_ops.om src/train/sgd_update.om src/train/generation.om src/autodiff/gradient_shape.om src/allen/allen_core.om src/path/rx_path_core.om src/ans/ans_core.om src/reservoir/reservoir_readout.om src/crumbline/cl_core.om src/dual/rx_dual_core.om src/dual_experiment/applic_core.om src/estimation/est_core.om src/searchtrace/st_core.om src/language/lang_core.om src/visor/visor_core.om src/fabric/fab_core.om src/algebra/oma_core.om src/physics0/pd0_core.om src/turing/turing_core.om src/polyglot/omx_core.om src/osh/osh_core.om" 35 36 note Special composed unit paths & helpers 37 text un_p_as "om/arboris_spread.om" 38 text un_p_ao "om/arboris_ontology.om" 39 text un_p_sha2 "om/tls/sha2.om" 40 text un_p_ar "om/arboris_records.om" 41 text un_p_ag "om/arboris_gated.om" 42 text un_p_aa "om/arboris_arena.om" 43 text un_p_num "gpu/nvidia/om/numeric/numeric.om" 44 text un_p_bae "om/blackwell_arboris_emit.om" 45 text un_p_enc "om/encoder/bw_enc_sm121.om" 46 text un_p_bage "om/blackwell_arboris_gated_emit.om" 47 text un_p_baq "om/blackwell_arboris_qmd.om" 48 text un_p_qmd "om/gpu/bw_qmd.om" 49 text un_p_bse "om/bw_arboris_spread_emit.om" 50 text un_p_bhz "gpu/nvidia/om/codegen/bw_hazard.om" 51 text un_om2_ln "om2\n" 52 text un_exp_fn "export fn " 53 text un_fn_sp "fn " 54 text un_hz_from "fn hz_chk " 55 text un_hz_to "export fn hz_chk " 56 text un_note_w "note" 57 text un_om2_w "om2" 58 text un_om_ext ".om" 59 60 note Leaf unit paths (use caller-stack freest/fapic ABI) 61 text un_l01 "om/blackwell_arboris_emit.om" 62 text un_l02 "om/blackwell_arboris_qmd.om" 63 text un_l03 "om/arboris_spread.om" 64 text un_l04 "om/arboris_arena.om" 65 text un_l05 "src/tensor/tensor_shape.om" 66 text un_l06 "om/compiler/osc_flow.om" 67 text un_l07 "src/train/generation.om" 68 text un_l08 "om/compiler/osc_statement.om" 69 text un_l09 "om/compiler/osc_artifact.om" 70 text un_l10 "src/autodiff/gradient_shape.om" 71 72 note FS unit paths (freestanding GPU link) 73 text un_fs01 "om/sha256/sha256-om2.om" 74 text un_fs02 "om/gpu/bw_qmd.om" 75 text un_fs03 "om/gpu/bw_regalloc.om" 76 text un_fs04 "om/gpu/bw_vecadd.om" 77 text un_fs05 "om/gpu/cg_matmul.om" 78 text un_fs06 "om/gpu/cg_gpu_attn.om" 79 80 note Native generator commands & output filenames 81 text un_cmd_c "c" 82 text un_cmd_apic "apic" 83 text un_cmd_freest "freest" 84 text un_cmd_fapic "fapic" 85 text un_cmd_h "h" 86 text un_cmd_apih "apih" 87 text un_f_c "/omega_om_units.c" 88 text un_f_h "/omega_native.h" 89 text un_f_apih "/omega_api_decl.h" 90 text un_f_id "/omega_om_units.ident" 91 text un_f_fs "/omega_om_units_fs.c" 92 text un_tdir "build/om-units-work-" 93 text un_tnat "/native" 94 text un_tsrc "/u.src.om" 95 text un_tbin "/u.bin" 96 text un_tuin "/u.in" 97 text un_tunits "/units.in" 98 text un_thost "/host.in" 99 text un_tleaf "/leaf.in" 100 text un_tfs "/fs.in" 101 text un_tleafc "/leaf.c" 102 text un_tc1 "/c1.tmp" 103 text un_tc2 "/c2.tmp" 104 text un_id_1 "omega-ident 1 unit=" 105 text un_id_2 " abi=" 106 text un_id_3 " profile=" 107 text un_id_4 " src=" 108 text un_id_5 " omc=" 109 text un_id_6 " path=" 110 text un_om1_p "OM-1" 111 text un_om2_p "OM-2" 112 text un_tag_pre "omega-unit " 113 text un_ombr "ombr" 114 text un_ombr_leaf "ombr_leaf" 115 116 global un_omc uchar 4096 117 global un_omcl ulong 1 118 global un_br uchar 4096 119 global un_brl ulong 1 120 global un_dest uchar 4096 121 global un_destl ulong 1 122 global un_omcpin uchar 64 123 global un_natpin uchar 64 124 global un_ulist uchar * 125 global un_uln ulong 1 126 global un_tmp uchar 4096 127 global un_tmpl ulong 1 128 global un_cur uchar 4096 129 global un_curl ulong 1 130 global un_name uchar 256 131 global un_namel ulong 1 132 global un_chk ulong 1 133 global un_has_host ulong 1 134 global un_has_leaf ulong 1 135 global un_has_fs ulong 1 136 137 fn un_die msg view uchar * code int to void 138 un_cleanup 139 cb_err msg 140 exit code 141 end 142 143 fn un_tpath suf view uchar * to void 144 cb_pa_clr 145 for i ulong get un_tmpl 0 bound 4096 146 cb_pa_ch get un_tmp i 147 end 148 cb_pa_tx suf 149 end 150 151 fn un_tbpath suf view uchar * to void 152 cb_pb_clr 153 for i ulong get un_tmpl 0 bound 4096 154 cb_pb_ch get un_tmp i 155 end 156 cb_pb_tx suf 157 end 158 159 fn un_dpath name view uchar * to void 160 cb_pb_clr 161 for i ulong get un_destl 0 bound 4096 162 cb_pb_ch get un_dest i 163 end 164 cb_pb_tx name 165 end 166 167 fn un_hex_eq_pin is_omc bool to bool 168 for j ulong 64 169 if is_omc 170 if ne get cb_shex j get un_omcpin j 171 ret false 172 end 173 else 174 if ne get cb_shex j get un_natpin j 175 ret false 176 end 177 end 178 end 179 ret true 180 end 181 182 fn un_cur_eq t view uchar * to bool 183 n = get un_curl 0 184 if ne n len t 185 ret false 186 end 187 for i ulong n bound 4096 188 if ne get un_cur i get t i 189 ret false 190 end 191 end 192 ret true 193 end 194 195 fn un_cur_ends t view uchar * to bool 196 n = get un_curl 0 197 m = len t 198 if lt n m 199 ret false 200 end 201 off = sub n m 202 for i ulong m bound 4096 203 if ne get un_cur add off i get t i 204 ret false 205 end 206 end 207 if eq off 0 208 ret true 209 end 210 ret eq get un_cur sub off 1 47 211 end 212 213 fn un_is_leaf to bool 214 if un_cur_ends un_l01 215 ret true 216 end 217 if un_cur_ends un_l02 218 ret true 219 end 220 if un_cur_ends un_l03 221 ret true 222 end 223 if un_cur_ends un_l04 224 ret true 225 end 226 if un_cur_ends un_l05 227 ret true 228 end 229 if un_cur_ends un_l06 230 ret true 231 end 232 if un_cur_ends un_l07 233 ret true 234 end 235 if un_cur_ends un_l08 236 ret true 237 end 238 if un_cur_ends un_l09 239 ret true 240 end 241 ret un_cur_ends un_l10 242 end 243 244 fn un_is_fs to bool 245 if un_cur_eq un_fs01 246 ret true 247 end 248 if un_cur_eq un_fs02 249 ret true 250 end 251 if un_cur_eq un_fs03 252 ret true 253 end 254 if un_cur_eq un_fs04 255 ret true 256 end 257 if un_cur_eq un_fs05 258 ret true 259 end 260 ret un_cur_eq un_fs06 261 end 262 263 fn un_rb_line_starts pos ulong endp ulong t view uchar * to bool 264 m = len t 265 if lt sub endp pos m 266 ret false 267 end 268 for j ulong m bound 64 269 if ne get cb_rb add pos j get t j 270 ret false 271 end 272 end 273 ret true 274 end 275 276 note Append file at cb_pa to cb_wb with optional transforms: 277 note mode 0 = raw, 1 = sed 's/^export fn /fn /', 2 = sed '/^om2$/d; s/^export fn /fn /', 3 = sed 's/^fn hz_chk /export fn hz_chk /' 278 fn un_app_xform mode ulong to void 279 if eq mode 0 280 if not cb_append_pa_to_wb 281 un_die un_fail_io 1 282 end 283 ret 284 end 285 if not cb_read_pa 286 un_die un_fail_io 1 287 end 288 n = get cb_n 0 289 i = ulong 0 290 while lt i n bound `9223372036854775807` 291 e = i 292 while lt e n bound `9223372036854775807` 293 if eq get cb_rb e 10 294 break 295 end 296 e = add e 1 297 end 298 has_nl = lt e n 299 skip = false 300 if eq mode 2 301 if and eq sub e i 3 un_rb_line_starts i e un_om2_w 302 skip = true 303 end 304 end 305 if not skip 306 if and or eq mode 1 eq mode 2 un_rb_line_starts i e un_exp_fn 307 cb_wb_tx un_fn_sp 308 cb_wb_rb add i 10 sub sub e i 10 309 else 310 if and eq mode 3 un_rb_line_starts i e un_hz_from 311 cb_wb_tx un_hz_to 312 cb_wb_rb add i 10 sub sub e i 10 313 else 314 cb_wb_rb i sub e i 315 end 316 end 317 if has_nl 318 cb_wb_ch 10 319 end 320 end 321 i = add e 1 322 end 323 end 324 325 fn un_pa_set_cur to void 326 cb_pa_clr 327 for i ulong get un_curl 0 bound 4096 328 cb_pa_ch get un_cur i 329 end 330 end 331 332 note Compose current unit source into cb_wb 333 fn un_compose_unit to void 334 cb_wb_clr 335 if un_cur_ends un_p_as 336 cb_pa_set un_p_ao 337 un_app_xform 0 338 cb_pa_set un_p_sha2 339 un_app_xform 0 340 cb_pa_set un_p_ar 341 un_app_xform 0 342 un_pa_set_cur 343 un_app_xform 0 344 ret 345 end 346 if un_cur_ends un_p_ag 347 cb_pa_set un_p_aa 348 un_app_xform 1 349 cb_pa_set un_p_num 350 un_app_xform 0 351 un_pa_set_cur 352 un_app_xform 0 353 ret 354 end 355 if un_cur_ends un_p_bae 356 cb_wb_tx un_om2_ln 357 cb_pa_set un_p_enc 358 un_app_xform 0 359 un_pa_set_cur 360 un_app_xform 0 361 cb_pa_set un_p_bage 362 un_app_xform 0 363 ret 364 end 365 if un_cur_ends un_p_baq 366 cb_pa_set un_p_qmd 367 un_app_xform 1 368 un_pa_set_cur 369 un_app_xform 0 370 ret 371 end 372 if un_cur_ends un_p_bse 373 cb_wb_tx un_om2_ln 374 cb_pa_set un_p_enc 375 un_app_xform 0 376 cb_pa_set un_p_qmd 377 un_app_xform 2 378 un_pa_set_cur 379 un_app_xform 0 380 ret 381 end 382 if un_cur_ends un_p_bhz 383 cb_wb_tx un_om2_ln 384 un_pa_set_cur 385 un_app_xform 3 386 ret 387 end 388 un_pa_set_cur 389 un_app_xform 0 390 end 391 392 fn un_is_name_ch c uchar to bool 393 if and ge c 48 le c 57 394 ret true 395 end 396 if and ge c 65 le c 90 397 ret true 398 end 399 if and ge c 97 le c 122 400 ret true 401 end 402 ret eq c 95 403 end 404 405 note Derive unit name: basename(cur, .om) with non-[A-Za-z0-9_] mapped to '_' 406 fn un_derive_name to void 407 n = get un_curl 0 408 s = ulong 0 409 for i ulong n bound 4096 410 if eq get un_cur i 47 411 s = add i 1 412 end 413 end 414 e = n 415 if ge sub e s 3 416 if eq get un_cur sub e 3 46 417 if eq get un_cur sub e 2 111 418 if eq get un_cur sub e 1 109 419 e = sub e 3 420 end 421 end 422 end 423 end 424 m = sub e s 425 if gt m 255 426 m = 255 427 end 428 for i ulong m bound 256 429 c = get un_cur add s i 430 if un_is_name_ch c 431 put un_name i c 432 else 433 put un_name i 95 434 end 435 end 436 put un_namel 0 m 437 end 438 439 note Detect OM-2 profile from cb_wb[0..cb_n[1]): first non-blank, non-note line equals "om2" 440 fn un_detect_om2 to bool 441 n = get cb_n 1 442 i = ulong 0 443 while lt i n bound `9223372036854775807` 444 e = i 445 while lt e n bound `9223372036854775807` 446 if eq get cb_wb e 10 447 break 448 end 449 e = add e 1 450 end 451 p = i 452 while lt p e bound `9223372036854775807` 453 if eq get cb_wb p 32 454 p = add p 1 455 else 456 break 457 end 458 end 459 if lt p e 460 note check if starts with "note" followed by end-of-line or space 461 is_n = false 462 if ge sub e p 4 463 if eq get cb_wb p 110 464 if eq get cb_wb add p 1 111 465 if eq get cb_wb add p 2 116 466 if eq get cb_wb add p 3 101 467 if eq sub e p 4 468 is_n = true 469 else 470 if eq get cb_wb add p 4 32 471 is_n = true 472 end 473 end 474 end 475 end 476 end 477 end 478 end 479 if not is_n 480 if eq sub e i 3 481 if eq get cb_wb i 111 482 if eq get cb_wb add i 1 109 483 if eq get cb_wb add i 2 50 484 ret true 485 end 486 end 487 end 488 end 489 ret false 490 end 491 end 492 i = add e 1 493 end 494 ret false 495 end 496 497 fn un_append_file_to_file src_suf view uchar * dst_suf view uchar * to void 498 un_tpath src_suf 499 fdi = fopen cb_pa 0 get cb_n 3 524288 0 500 if lt fdi 0 501 un_die un_fail_io 1 502 end 503 un_tbpath dst_suf 504 fdo = fopen cb_pb 0 get cb_n 4 525377 420 505 if lt fdo 0 506 z0 = fclose int fdi 507 un_die un_fail_io 1 508 end 509 while true bound `9223372036854775807` 510 k = read int fdi cb_chunk1 0 65536 511 if lt k 0 512 un_die un_fail_io 1 513 end 514 if eq k 0 515 break 516 end 517 o = ulong 0 518 kl = ulong k 519 while lt o kl bound 65537 520 w = write int fdo cb_chunk1 o sub kl o 521 if le w 0 522 un_die un_fail_io 1 523 end 524 o = add o ulong w 525 end 526 end 527 z1 = fclose int fdi 528 z2 = fclose int fdo 529 end 530 531 fn un_run_native cmd view uchar * in_suf view uchar * out_suf view uchar * to void 532 un_tpath in_suf 533 fi = fopen cb_pa 0 get cb_n 3 524288 0 534 if lt fi 0 535 un_die un_fail_io 1 536 end 537 un_tbpath out_suf 538 z0 = unlink cb_pb 0 get cb_n 4 539 fo = fopen cb_pb 0 get cb_n 4 524865 420 540 if lt fo 0 541 z1 = fclose int fi 542 un_die un_fail_io 1 543 end 544 cb_av_clr 545 un_tpath un_tnat 546 cb_av_push_pa 547 cb_av_push_tx cmd 548 rc = cb_spawn_fds int fi int fo -1 false 549 if ne rc 0 550 un_die un_fail_io 1 551 end 552 end 553 554 fn un_run_native_app cmd view uchar * in_suf view uchar * out_suf view uchar * to void 555 un_tpath in_suf 556 fi = fopen cb_pa 0 get cb_n 3 524288 0 557 if lt fi 0 558 un_die un_fail_io 1 559 end 560 un_tbpath out_suf 561 fo = fopen cb_pb 0 get cb_n 4 525377 420 562 if lt fo 0 563 z1 = fclose int fi 564 un_die un_fail_io 1 565 end 566 cb_av_clr 567 un_tpath un_tnat 568 cb_av_push_pa 569 cb_av_push_tx cmd 570 rc = cb_spawn_fds int fi int fo -1 false 571 if ne rc 0 572 un_die un_fail_io 1 573 end 574 end 575 576 fn un_is_ident_eq c uchar to bool 577 if and ge c 48 le c 57 578 ret true 579 end 580 if and ge c 65 le c 90 581 ret true 582 end 583 if and ge c 97 le c 122 584 ret true 585 end 586 if or eq c 95 eq c 61 587 ret true 588 end 589 ret false 590 end 591 592 fn un_is_alnum_u c uchar to bool 593 if and ge c 48 le c 57 594 ret true 595 end 596 if and ge c 65 le c 90 597 ret true 598 end 599 if and ge c 97 le c 122 600 ret true 601 end 602 ret eq c 95 603 end 604 605 fn un_rb_is_ombr i ulong to bool 606 if ne get cb_rb i 111 607 ret false 608 end 609 if ne get cb_rb add i 1 109 610 ret false 611 end 612 if ne get cb_rb add i 2 98 613 ret false 614 end 615 ret eq get cb_rb add i 3 114 616 end 617 618 note Pure-Omega equivalent of: 619 note sed -E 's/(^|\n|[^[:alnum:]_=])ombr(2?_[[:alnum:]_]+)/\1ombr_leaf\2/g' 620 note Reads leaf.c into cb_rb and appends transformed bytes to omega_om_units.c 621 fn un_append_leaf_ns to void 622 un_tpath un_tleafc 623 if not cb_read_pa 624 un_die un_fail_io 1 625 end 626 n = get cb_n 0 627 cb_wb_clr 628 i = ulong 0 629 while lt i n bound `9223372036854775807` 630 matched = false 631 if le add i 6 n 632 if un_rb_is_ombr i 633 note check left boundary: start-of-line, or \n escape, or non-[[:alnum:]_=] 634 lb = false 635 if eq i 0 636 lb = true 637 else 638 prev = get cb_rb sub i 1 639 if eq prev 10 640 lb = true 641 else 642 if not un_is_ident_eq prev 643 lb = true 644 else 645 if and ge i 2 and eq get cb_rb sub i 2 92 eq prev 110 646 lb = true 647 end 648 end 649 end 650 end 651 if lb 652 note check right side: (2?_[[:alnum:]_]+) 653 k = add i 4 654 if and lt k n eq get cb_rb k 50 655 k = add k 1 656 end 657 if and lt add k 1 n and eq get cb_rb k 95 un_is_alnum_u get cb_rb add k 1 658 matched = true 659 end 660 end 661 end 662 end 663 if matched 664 cb_wb_tx un_ombr_leaf 665 i = add i 4 666 else 667 cb_wb_ch get cb_rb i 668 i = add i 1 669 end 670 end 671 un_tpath un_tc2 672 if not cb_write_wb_pa 420 673 un_die un_fail_io 1 674 end 675 un_append_file_to_file un_tc2 un_f_c 676 end 677 678 fn un_process_one to void 679 un_compose_unit 680 un_derive_name 681 is_om2 = un_detect_om2 682 un_tpath un_tsrc 683 if not cb_write_wb_pa 420 684 un_die un_fail_io 1 685 end 686 note Hash composed source 687 if not cb_sha_file_pa 688 un_die un_fail_io 1 689 end 690 note Save source hex in cb_pc[0..64) temporarily? No, use un_write_ident after compile; copy hex into cb_chunk2[0..64) 691 for j ulong 64 692 put cb_chunk2 j get cb_shex j 693 end 694 note Compile source with pinned OMC 695 for i ulong get un_omcl 0 bound 4096 696 put cb_pc i get un_omc i 697 end 698 un_tpath un_tsrc 699 un_tbpath un_tbin 700 rc = cb_run_omc get un_omcl 0 420 -1 701 if ne rc 0 702 un_die un_fail_io 1 703 end 704 note Build framed u.in: src + \0 + %08d(bin_len) + bin + (if om2: "omega-unit NAME OMC_PIN\n") 705 un_tpath un_tbin 706 bsz = cb_file_size_pa 707 if lt bsz 0 708 un_die un_fail_io 1 709 end 710 cb_wb_clr 711 un_tpath un_tsrc 712 if not cb_append_pa_to_wb 713 un_die un_fail_io 1 714 end 715 cb_wb_ch 0 716 note 8-digit zero-padded decimal bsz 717 d = ulong bsz 718 for q ulong 8 719 put cb_numbuf sub 7 q uchar add 48 rem d 10 720 d = div d 10 721 end 722 for q ulong 8 723 cb_wb_ch get cb_numbuf q 724 end 725 un_tpath un_tbin 726 if not cb_append_pa_to_wb 727 un_die un_fail_io 1 728 end 729 if is_om2 730 cb_wb_tx un_tag_pre 731 for j ulong get un_namel 0 bound 256 732 cb_wb_ch get un_name j 733 end 734 cb_wb_ch 32 735 for j ulong 64 736 cb_wb_ch get un_omcpin j 737 end 738 cb_wb_ch 10 739 end 740 un_tpath un_tuin 741 if not cb_write_wb_pa 420 742 un_die un_fail_io 1 743 end 744 un_append_file_to_file un_tuin un_tunits 745 if un_is_leaf 746 un_append_file_to_file un_tuin un_tleaf 747 put un_has_leaf 0 1 748 else 749 un_append_file_to_file un_tuin un_thost 750 put un_has_host 0 1 751 end 752 if un_is_fs 753 un_append_file_to_file un_tuin un_tfs 754 put un_has_fs 0 1 755 end 756 note Append ident line 757 cb_wb_clr 758 cb_wb_tx un_id_1 759 for j ulong get un_namel 0 bound 256 760 cb_wb_ch get un_name j 761 end 762 cb_wb_tx un_id_2 763 if is_om2 764 cb_wb_ch 50 765 else 766 cb_wb_ch 49 767 end 768 cb_wb_tx un_id_3 769 if is_om2 770 cb_wb_tx un_om2_p 771 else 772 cb_wb_tx un_om1_p 773 end 774 cb_wb_tx un_id_4 775 for j ulong 64 776 cb_wb_ch get cb_chunk2 j 777 end 778 cb_wb_tx un_id_5 779 for j ulong 64 780 cb_wb_ch get un_omcpin j 781 end 782 cb_wb_tx un_id_6 783 for j ulong get un_curl 0 bound 4096 784 cb_wb_ch get un_cur j 785 end 786 cb_wb_ch 10 787 un_tpath un_tc1 788 if not cb_write_wb_pa 420 789 un_die un_fail_io 1 790 end 791 un_append_file_to_file un_tc1 un_f_id 792 end 793 794 fn un_check_one name view uchar * to bool 795 cb_pa_clr 796 for i ulong get un_tmpl 0 bound 4096 797 cb_pa_ch get un_tmp i 798 end 799 cb_pa_tx name 800 un_dpath name 801 if not cb_cmp_pa_pb 802 cb_out un_fail_diff1 803 cb_wbuf_pb 1 804 cb_out un_fail_diff2 805 ret false 806 end 807 ret true 808 end 809 810 fn un_install_one name view uchar * to void 811 cb_pa_clr 812 for i ulong get un_tmpl 0 bound 4096 813 cb_pa_ch get un_tmp i 814 end 815 cb_pa_tx name 816 un_dpath name 817 if not cb_copy_pa_to_pb 420 818 un_die un_fail_io 1 819 end 820 end 821 822 fn un_load_pins to void 823 if cb_getenv un_env_omcpin 824 if eq get cb_n 4 64 825 for j ulong 64 826 put un_omcpin j get cb_pb j 827 end 828 else 829 un_die un_nr_omc 3 830 end 831 else 832 cb_pa_set un_pin_file 833 if not cb_read_pa 834 un_die un_nr_omc 3 835 end 836 if lt get cb_n 0 64 837 un_die un_nr_omc 3 838 end 839 for j ulong 64 840 put un_omcpin j get cb_rb j 841 end 842 end 843 if cb_getenv un_env_natpin 844 if eq get cb_n 4 64 845 for j ulong 64 846 put un_natpin j get cb_pb j 847 end 848 else 849 un_die un_nr_nat 3 850 end 851 else 852 for j ulong 64 853 put un_natpin j get un_def_natpin j 854 end 855 end 856 end 857 858 fn un_load_ulist to void 859 if cb_getenv un_env_units 860 vlen = get cb_n 4 861 if gt vlen 0 862 ze1 = enlarge un_ulist vlen 863 if ne ze1 0 864 un_die un_fail_io 1 865 end 866 for j ulong vlen bound 65536 867 put un_ulist j get cb_pb j 868 end 869 put un_uln 0 vlen 870 ret 871 end 872 end 873 dl = len un_def_units 874 ze2 = enlarge un_ulist dl 875 if ne ze2 0 876 un_die un_fail_io 1 877 end 878 for j ulong dl bound 65536 879 put un_ulist j get un_def_units j 880 end 881 put un_uln 0 dl 882 end 883 884 fn un_is_ws c uchar to bool 885 if eq c 32 886 ret true 887 end 888 if eq c 9 889 ret true 890 end 891 ret eq c 10 892 end 893 894 fn un_skip_ws p ulong uln ulong to ulong 895 x = p 896 while lt x uln bound `9223372036854775807` 897 if un_is_ws get un_ulist x 898 x = add x 1 899 else 900 break 901 end 902 end 903 ret x 904 end 905 906 fn un_scan_word p ulong uln ulong to ulong 907 x = p 908 while lt x uln bound `9223372036854775807` 909 if un_is_ws get un_ulist x 910 break 911 end 912 x = add x 1 913 end 914 ret x 915 end 916 917 fn un_process_all to void 918 un_load_ulist 919 uln = get un_uln 0 920 p = un_skip_ws 0 uln 921 while lt p uln bound `9223372036854775807` 922 q = un_scan_word p uln 923 ulen = sub q p 924 for i ulong ulen bound 4096 925 put un_cur i get un_ulist add p i 926 end 927 put un_curl 0 ulen 928 un_process_one 929 p = un_skip_ws q uln 930 end 931 end 932 933 fn un_init_tmp to void 934 cb_pa_set un_tdir 935 x = ulong getpid 936 k = ulong 32 937 for j ulong 21 938 k = sub k 1 939 put cb_numbuf k uchar add 48 rem x 10 940 x = div x 10 941 if eq x 0 942 break 943 end 944 end 945 for j ulong sub 32 k bound 32 946 cb_pa_ch get cb_numbuf add k j 947 end 948 for i ulong get cb_n 3 bound 4096 949 put un_tmp i get cb_pa i 950 end 951 put un_tmpl 0 get cb_n 3 952 if not cb_mkdir_p_pa 953 un_die un_fail_io 1 954 end 955 cb_wb_clr 956 un_tpath un_tunits 957 z0 = cb_write_wb_pa 420 958 un_tpath un_thost 959 z0 = cb_write_wb_pa 420 960 un_tpath un_tleaf 961 z0 = cb_write_wb_pa 420 962 un_tpath un_tfs 963 z0 = cb_write_wb_pa 420 964 un_tpath un_f_id 965 z0 = cb_write_wb_pa 420 966 un_tpath un_f_c 967 z0 = cb_write_wb_pa 420 968 put un_has_host 0 0 969 put un_has_leaf 0 0 970 put un_has_fs 0 0 971 end 972 973 fn un_compile_native to void 974 for i ulong get un_omcl 0 bound 4096 975 put cb_pc i get un_omc i 976 end 977 cb_pa_clr 978 for i ulong get un_brl 0 bound 4096 979 cb_pa_ch get un_br i 980 end 981 cb_pa_tx un_nat_rel 982 un_tbpath un_tnat 983 if ne cb_run_omc get un_omcl 0 493 -1 0 984 un_die un_fail_io 1 985 end 986 end 987 988 fn un_emit_all to void 989 if ne get un_has_host 0 0 990 un_run_native un_cmd_c un_thost un_f_c 991 un_run_native_app un_cmd_apic un_thost un_f_c 992 end 993 if ne get un_has_leaf 0 0 994 un_run_native un_cmd_freest un_tleaf un_tleafc 995 un_run_native_app un_cmd_fapic un_tleaf un_tleafc 996 un_append_leaf_ns 997 end 998 un_run_native un_cmd_h un_tunits un_f_h 999 un_run_native un_cmd_apih un_tunits un_f_apih 1000 if ne get un_has_fs 0 0 1001 un_run_native un_cmd_freest un_tfs un_f_fs 1002 un_run_native_app un_cmd_fapic un_tfs un_f_fs 1003 else 1004 cb_wb_clr 1005 cb_wb_tx un_nofs 1006 un_tpath un_f_fs 1007 z6 = cb_write_wb_pa 420 1008 end 1009 end 1010 1011 fn un_cleanup to void 1012 if eq get un_tmpl 0 0 1013 ret 1014 end 1015 cb_pa_clr 1016 for i ulong get un_tmpl 0 bound 4096 1017 cb_pa_ch get un_tmp i 1018 end 1019 cb_rm_flat_pa 1020 put un_tmpl 0 0 1021 end 1022 1023 fn main to int 1024 put un_chk 0 0 1025 if ge argcnt 2 1026 if cb_pa_arg 1 1027 if cb_pa_eq un_fcheck 1028 put un_chk 0 1 1029 end 1030 end 1031 end 1032 if not cb_getenv un_env_omc 1033 cb_out un_nr_env 1034 ret 3 1035 end 1036 if eq get cb_n 4 0 1037 cb_out un_nr_env 1038 ret 3 1039 end 1040 for i ulong get cb_n 4 bound 4096 1041 put un_omc i get cb_pb i 1042 end 1043 put un_omcl 0 get cb_n 4 1044 if not cb_getenv un_env_br 1045 cb_out un_nr_env 1046 ret 3 1047 end 1048 if eq get cb_n 4 0 1049 cb_out un_nr_env 1050 ret 3 1051 end 1052 for i ulong get cb_n 4 bound 4096 1053 put un_br i get cb_pb i 1054 end 1055 put un_brl 0 get cb_n 4 1056 if cb_getenv un_env_dest 1057 if gt get cb_n 4 0 1058 for i ulong get cb_n 4 bound 4096 1059 put un_dest i get cb_pb i 1060 end 1061 put un_destl 0 get cb_n 4 1062 end 1063 end 1064 if eq get un_destl 0 0 1065 for i ulong len un_def_dest bound 4096 1066 put un_dest i get un_def_dest i 1067 end 1068 put un_destl 0 len un_def_dest 1069 end 1070 1071 un_load_pins 1072 cb_pa_clr 1073 for i ulong get un_omcl 0 bound 4096 1074 cb_pa_ch get un_omc i 1075 end 1076 if not cb_sha_file_pa 1077 cb_out un_nr_omc 1078 ret 3 1079 end 1080 if not un_hex_eq_pin true 1081 cb_out un_nr_omc 1082 ret 3 1083 end 1084 cb_pa_clr 1085 for i ulong get un_brl 0 bound 4096 1086 cb_pa_ch get un_br i 1087 end 1088 cb_pa_tx un_nat_rel 1089 if not cb_sha_file_pa 1090 cb_out un_nr_nat 1091 ret 3 1092 end 1093 if not un_hex_eq_pin false 1094 cb_out un_nr_nat 1095 ret 3 1096 end 1097 1098 un_init_tmp 1099 un_compile_native 1100 un_process_all 1101 un_emit_all 1102 1103 if ne get un_chk 0 0 1104 bad = ulong 0 1105 if not un_check_one un_f_c 1106 bad = 1 1107 end 1108 if not un_check_one un_f_h 1109 bad = 1 1110 end 1111 if not un_check_one un_f_apih 1112 bad = 1 1113 end 1114 if not un_check_one un_f_id 1115 bad = 1 1116 end 1117 if not un_check_one un_f_fs 1118 bad = 1 1119 end 1120 un_cleanup 1121 if ne bad 0 1122 ret 1 1123 end 1124 cb_out un_pass_chk 1125 ret 0 1126 end 1127 1128 un_install_one un_f_c 1129 un_install_one un_f_h 1130 un_install_one un_f_apih 1131 un_install_one un_f_id 1132 un_install_one un_f_fs 1133 un_cleanup 1134 cb_out un_wrote1 1135 r = write 1 un_dest 0 get un_destl 0 1136 cb_out un_wrote2 1137 ret 0 1138 end