Skip to content

wasmi_ir: Add proper IrEncoder to encode Instructions as bytes #1324

@Robbepop

Description

@Robbepop

Blocked by: #1439

Currently Wasmi uses slices of Instructions to represent function bodies.
This is a very low level usage. A much better, more flexible and higher-level approach is build up these function bodies or instruction sequences with so-called IR-builders.

The wasmi_ir::for_each_op macro can be used to generate such an IrBuilder. The IrBuilder will have one builder function per Wasmi IR instruction in the form of:

pub fn $instr_name(&mut self, $args: ..) -> Result<Instr, Errror> { ... }

Which allows to incrementally build-up the instruction sequence.
This is more flexible than a slice or array of instructions because this also allows to later replace the underlying build-up mechanism to use a byte-encoding similar to what Wasmtime's pulley interpreter is doing.

The main work item is probably to convert all the many Wasmi translation unit tests and the Wasmi translator to use this new API.
The currently existing Instruction constructors will no longer be needed after this has been implemented.

A simiar InstrSequence type has existed in wasmi_ir for some time but was removed in #1323.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debtAn issue to resolve some technical debt.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions