Expand description
Reading encoded instructions back as text.
§There is one printer, and it is crate::print
ADR 0041 decides this rather than leaving it open, and the reason is the
1:1 encoding. crate::print is already a disassembler for
Inst — one instruction per line, one fact per line, no
alignment that shifts when an unrelated line grows, written so that a test
which pins a lowering can diff it — and decode is lossless. So a
disassembly is decode and then that printer, and it cannot drift from
the IR’s own rendering, because it is the IR’s own rendering.
A second renderer would be a second thing to keep in step, for no reader’s benefit: the two would print the same instruction, and the day they disagreed the disagreement would be the bug rather than the report of one. It would also cost the property that makes this worth having — that lowered IR and executable bytecode are two views of one index, so a difference between the two panes of a debugger is a difference in the encoding and never in the prose.
§What this module is, then
The part print cannot do: the bytes. listing adds the program
counter, the byte offset pc << 4, and the raw sixteen bytes in front of
the text — issue #245’s debugger row — and one is the text alone.
Neither can panic on any sixteen bytes at all. A run that does not decode prints as its bytes and says so, because a disassembler is what somebody reaches for when the bytes are wrong.
Functions§
- bytes
- One encoded instruction’s sixteen bytes, in hex, low byte first.
- listing
- A whole run of encoded instructions, one to a line.
- one
- One encoded instruction as
crate::print::onerenders it.