mirror of
https://github.com/odin-lang/Odin.git
synced 2026-09-02 10:13:35 +00:00
Internal label ids are allocation-order handles: the encoder's creation
order, or the decoder's branch-DISCOVERY order (a loop's latch names the
header before an earlier forward target). Printing labels by raw id leaked
that accident into listings — label numbers appeared out of order down the
page — and the printers' `label_names: ^map[u32]string` keyed the caller's
names by those synthesized ids, which a decode consumer cannot know without
re-deriving them (the practical result: naming "label 0" could caption a
random interior branch target).
Naming is now derived at the presentation seam, shared by every ISA
(`isa.Label_Display` in isa/print.odin):
- display numbers are assigned in ASCENDING ADDRESS order, so a listing
reads L0, L1, L2 … top to bottom regardless of id allocation;
- caller names are keyed by BYTE OFFSET (`isa.Label_Names`, with a
`distinct` Label_Offset key so an id-keyed map from the old contract
fails to compile instead of silently mis-naming);
- a named offset is guaranteed a label row even when no Label_Definition
points at it — `names[0] = "factorial"` heads a function's listing.
All ten ISA printers (x86, mips, rsp, arm32, arm64, riscv, ppc, ppc_vle,
mos6502, mos65816) drop their per-printer offset_to_label maps and
write_label helpers for the shared display; each arch re-exports
Label_Offset/Label_Names beside Label_Definition. En route this fixes an
arm32/ppc/ppc_vle bug where passing ANY names map suppressed the default
L<n> label rows for unnamed labels. Decode-side id assignment is untouched:
the reloc round-trip contract (encoder ids surviving decode) and the
sparse-id padding it relies on stay exactly as they were.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Riok9vMpkLmo78wsVKJHhz
24 lines
940 B
Odin
24 lines
940 B
Odin
// rexcode · Brendan Punsky (dotbmp@github), original author
|
|
|
|
package rexcode_x86
|
|
|
|
// =============================================================================
|
|
// x86 LABELS
|
|
// =============================================================================
|
|
//
|
|
// Type aliases to the array-index label model in `isa/labels.odin`, so
|
|
// callers can construct values like `x86.Label_Definition(3)` without
|
|
// importing `isa`. The label-construction procedures themselves
|
|
// (`label`, `label_forward`, `label_set_at`, `label_named`,
|
|
// `label_reserve`, `label_set`, `label_map_init/destroy`) are parametric
|
|
// over the Instruction type and live in `isa/labels.odin` -- callers
|
|
// invoke them directly as `isa.<proc>(...)`.
|
|
|
|
import "core:rexcode/isa"
|
|
|
|
Label_Definition :: isa.Label_Definition
|
|
Label_Map :: isa.Label_Map
|
|
LABEL_UNDEFINED :: isa.LABEL_UNDEFINED
|
|
Label_Offset :: isa.Label_Offset
|
|
Label_Names :: isa.Label_Names
|