Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions crates/wasm-encoder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ And then you can encode WebAssembly binaries via:

```rust
use wasm_encoder::{
CodeSection, ExportKind, ExportSection, Function, FunctionSection, Instruction,
CodeSection, ExportKind, ExportSection, Function, FunctionSection,
Module, TypeSection, ValType,
};

Expand Down Expand Up @@ -54,10 +54,11 @@ module.section(&exports);
let mut codes = CodeSection::new();
let locals = vec![];
let mut f = Function::new(locals);
f.instruction(&Instruction::LocalGet(0));
f.instruction(&Instruction::LocalGet(1));
f.instruction(&Instruction::I32Add);
f.instruction(&Instruction::End);
f.instructions()
.local_get(0)
.local_get(1)
.i32_add()
.end();
codes.function(&f);
module.section(&codes);

Expand Down
2 changes: 2 additions & 0 deletions crates/wasm-encoder/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod exports;
mod functions;
mod globals;
mod imports;
mod instructions;
mod linking;
mod memories;
mod names;
Expand All @@ -27,6 +28,7 @@ pub use exports::*;
pub use functions::*;
pub use globals::*;
pub use imports::*;
pub use instructions::*;
pub use linking::*;
pub use memories::*;
pub use names::*;
Expand Down
9 changes: 5 additions & 4 deletions crates/wasm-encoder/src/core/branch_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ use alloc::vec::Vec;
/// let mut code = CodeSection::new();
/// let mut body = Function::new([]);
///
/// body.instruction(&Instruction::I32Const(1));
/// body.instructions().i32_const(1);
/// let if_offset = body.byte_len();
/// body.instruction(&Instruction::If(BlockType::Empty));
/// body.instruction(&Instruction::End);
/// body.instruction(&Instruction::End);
/// body.instructions()
/// .if_(BlockType::Empty)
/// .end()
/// .end();
/// code.function(&body);
///
/// let mut hints = BranchHints::new();
Expand Down
Loading