bytecodealliance / wasm-tools

CLI and Rust libraries for low-level manipulation of WebAssembly modules
Apache License 2.0
1.21k stars 224 forks source link

Converting certain component types from `wasmparser` to `wasm_encoder` #1638

Closed thesuhas closed 6 days ago

thesuhas commented 6 days ago

FYI: Saw that there was a discussion tab and started a discussion there as I wasn't sure if it qualifies as an issue

Hi,

I'm writing a WebAssembly Manipulation Library for the Component Model in Rust called Orca.

Not sure if this qualifies as an issue but I'm converting the ComponentTypeSection from the wasmparser to the wasm_encoder and had a few questions.

  1. To convert wasmparser::HeapType::Concrete to wasm_encoder::HeapType which is necessary for ComponentType::Resource, how do the indices map? I see that wasm_encoder::HeapType::Concrete takes a u32 index but in wasm_encoder::HeapType::Concrete it is an UnpackedIndex where each variant represents a index into a particular type space or elements. For now I've directly converted them here.
  2. To convert ComponentType::Func from wasmparser to wasm_encoder, we need to convert wasmparser::ComponentFuncResult using the wasm_encoder::ComponentFuncTypeEncoder, where we need to convert both the named and unnamed types. The FuncTypeEncoder's results method expects (&str, ComponentValType) but ComponentFuncResult::Unnamed does not have a &str field. In this case would passing an empty string suffice for the encoder?