Skip to main content

Module print

Module print 

Source
Expand description

A disassembly, for reading a lowering and for a test to assert on.

The format is one instruction per line, pc opcode operands, with slot numbers written s0, s1.

An operand is one of two things and the line says which. A word is annotated with what that one word holds — s3:int, s5:tag — and a word is what arithmetic, a branch’s condition and a field offset take. A value location is annotated with its layouts3:Point — because a value is a run of words and the layout is what says how many. Where the run is wider than one word the whole of it is named: s5..s7:Result is the three words s5, s6 and s7.

Naming the run is what makes the calling convention visible. A call-host s5..s7:Result console.println (s4:String) writes three words, and until issue #299 the same line read call-host s5:tag console.println (s4:String) Result: a destination that looked like one word, the width parked at the end of the line, and s6 and s7 reading as registers with nothing to do with it. The width was there; which slots it covered was not.

So the layout is written once, on the location it describes, and a copy, a clear, a return and a call no longer repeat it after their operands. That includes Inst::CallClosure, whose callee is a function id read out of an object at run time but whose answer is not: the checker settles a call through a value against the callee’s function type, so the instruction carries the layout the destination has to be, and the line reads like every other call’s.

Which operands are locations is not a second opinion. It is where crate::verify asks whether a run of words fits — the same layout, on the same slot — so a listing and the check disagreeing is a bug in one of them rather than a matter of taste. A layout the table does not hold prints as its id and no range, s5:layout7, because nothing then says how wide the location is.

Before the code come the frame’s names, one to a line — local count -> s3:Int [4, 11) — because a slot number is not an answer to what the source called something and a slot is reused by several variables in turn. The pair is the half-open range of program counters the name denotes that slot over; see crate::Local. The frame line above them is the one place that is per word throughout: it is the ground truth every range indexes into.

A test that pins a lowering pins this text, so it is written to be diffed: one fact per line, and no alignment that changes when an unrelated line grows.

Functions§

function
Renders one function: its boundary, its frame, the names bound in it, then its code.
one
Renders one instruction.
program
Renders every function of program.