Skip to content

bloqade.lanes.bytecode.encode

encode

bloqade.lanes.bytecode.encode

BytecodeEncoder -- stack_move ir.Method → syntactic Program.

The encoder assumes the input ir.Method is stack-consistent: every SSA value is used exactly once and the defining statements appear in the order that satisfies the bytecode stack discipline (deepest arg defined first, top-of-stack arg defined last). load_program (decode.py) always produces stack-consistent IR, so round-trips work unconditionally. IR produced by compiler rewrites (e.g. RewriteMoveToStackMove) may violate the ordering invariant and must be normalised by stackify before encoding.

Implemented as a kirin EmitABC pass: each dialect registers its own MethodTable under the key "emit.bytecode", and the encoder dispatches via the standard kirin interpreter machinery. The encoded instructions accumulate in BytecodeEncoder.instructions; call dump_program for the one-shot public API.