pub struct BranchHints { /* private fields */ }
Expand description
Helper structure to encode the metadata.code.branch_hint
custom section.
This section was defined in the branch-hinting proposal for WebAssembly: https://github.com/WebAssembly/branch-hinting.
§Example
use wasm_encoder::*;
let mut module = Module::new();
let mut types = TypeSection::new();
types.ty().function([], []);
module.section(&types);
let mut funcs = FunctionSection::new();
funcs.function(0);
module.section(&funcs);
let mut code = CodeSection::new();
let mut body = Function::new([]);
body.instruction(&Instruction::I32Const(1));
let if_offset = body.byte_len();
body.instruction(&Instruction::If(BlockType::Empty));
body.instruction(&Instruction::End);
body.instruction(&Instruction::End);
code.function(&body);
let mut hints = BranchHints::new();
hints.function_hints(0, [BranchHint {
branch_func_offset: if_offset as u32,
branch_hint_value: 1, // taken
}]);
module.section(&hints);
module.section(&code);
let wasm = module.finish();
let wat = wasmprinter::print_bytes(&wasm).unwrap();
assert_eq!(wat, r#"(module
(type (;0;) (func))
(func (;0;) (type 0)
i32.const 1
(@metadata.code.branch_hint "\01")
if ;; label = @1
end
)
)
"#);
Implementations§
source§impl BranchHints
impl BranchHints
sourcepub fn function_hints<I>(&mut self, func: u32, hints: I)
pub fn function_hints<I>(&mut self, func: u32, hints: I)
Adds a new set of function hints for the func
specified.
Trait Implementations§
source§impl Debug for BranchHints
impl Debug for BranchHints
source§impl Default for BranchHints
impl Default for BranchHints
source§fn default() -> BranchHints
fn default() -> BranchHints
Returns the “default value” for a type. Read more
source§impl Encode for BranchHints
impl Encode for BranchHints
Auto Trait Implementations§
impl Freeze for BranchHints
impl RefUnwindSafe for BranchHints
impl Send for BranchHints
impl Sync for BranchHints
impl Unpin for BranchHints
impl UnwindSafe for BranchHints
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more