From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/wasm-encoder/README.md | 80 +++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 third_party/rust/wasm-encoder/README.md (limited to 'third_party/rust/wasm-encoder/README.md') diff --git a/third_party/rust/wasm-encoder/README.md b/third_party/rust/wasm-encoder/README.md new file mode 100644 index 0000000000..5f2efbe210 --- /dev/null +++ b/third_party/rust/wasm-encoder/README.md @@ -0,0 +1,80 @@ +
+

wasm-encoder

+ +A Bytecode Alliance project + +

+ A WebAssembly encoder for Rust. +

+ +

+ Crates.io version + Download + docs.rs docs +

+
+ +## Usage + +Add `wasm-encoder` to your `Cargo.toml` + +```sh +$ cargo add wasm-encoder +``` + +And then you can encode WebAssembly binaries via: + +```rust +use wasm_encoder::{ + CodeSection, ExportKind, ExportSection, Function, FunctionSection, Instruction, + Module, TypeSection, ValType, +}; + +let mut module = Module::new(); + +// Encode the type section. +let mut types = TypeSection::new(); +let params = vec![ValType::I32, ValType::I32]; +let results = vec![ValType::I32]; +types.function(params, results); +module.section(&types); + +// Encode the function section. +let mut functions = FunctionSection::new(); +let type_index = 0; +functions.function(type_index); +module.section(&functions); + +// Encode the export section. +let mut exports = ExportSection::new(); +exports.export("f", ExportKind::Func, 0); +module.section(&exports); + +// Encode the code section. +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); +codes.function(&f); +module.section(&codes); + +// Extract the encoded Wasm bytes for this module. +let wasm_bytes = module.finish(); + +// We generated a valid Wasm module! +assert!(wasmparser::validate(&wasm_bytes).is_ok()); +``` + +# License + +This project is licensed under the Apache 2.0 license with the LLVM exception. +See [LICENSE](LICENSE) for more details. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in this project by you, as defined in the Apache-2.0 license, +shall be licensed as above, without any additional terms or conditions. -- cgit v1.2.3