instruction_table!() { /* proc-macro */ }Expand description
The main procedural macro for generating instruction decoders.
This macro takes an instruction table definition and generates an optimized dispatcher function with compile-time branch elimination.
§Syntax
ⓘ
instruction_table! {
type Opcode = u8; // Opcode type (u8, u16, u32, or u64)
dispatcher = dispatch; // Name of generated function
context = Cpu; // Type passed to handlers
"pattern" => handler<{var}> where {
var: Type = mapping_or_const_fn
};
...
}§Generated Code
Generates a function with signature:
ⓘ
pub fn dispatcher_name(ctx: &mut ContextType, opcode: OpcodeType)The function contains a match expression that:
- Matches exact opcodes for patterns without wildcards
- Uses masked matching (
op & mask == value) for patterns with wildcards - Calls handlers with const generic arguments based on variable bindings
- Panics on unhandled opcodes