Expand description
A simple event-driven library for parsing WebAssembly binary files (or streams).
The parser library reports events as they happen and only stores parsing information for a brief period of time, making it very fast and memory-efficient. The event-driven model, however, has some drawbacks. If you need random access to the entire WebAssembly data-structure, this is not the right library for you. You could however, build such a data-structure using this library.
To get started, create a Parser
using Parser::new
and then follow
the examples documented for Parser::parse
or Parser::parse_all
.
Modules§
- collections
validate
- Type definitions for maps and sets used by the
wasmparser
crate. - component_
types validate
andcomponent-model
- Types relating to type information provided by validation.
- names
validate
andcomponent-model
- Definitions of name-related helpers and newtypes, primarily for the component model.
- types
validate
- Types relating to type information provided by validation.
Macros§
- for_
each_ operator - Used to implement routines for the
Operator
enum. - for_
each_ visit_ operator - Used to implement the
VisitOperator
trait. - for_
each_ visit_ simd_ operator simd
- Used to implement the
VisitSimdOperator
trait.
Structs§
- Array
Type - Represents a type of an array in a WebAssembly module.
- Binary
Reader - A binary reader of the WebAssembly structures and types.
- Binary
Reader Error - A binary reader for WebAssembly modules.
- BrTable
- A br_table entries representation.
- BrTable
Targets - An iterator over the targets of a
BrTable
. - Branch
Hint - A hint for a single branch.
- Branch
Hint Function - Branch hints for a single function.
- Comdat
- Represents COMDAT data in the linking custom section.
- Comdat
Symbol - Represents a symbol that is part of a comdat.
- Component
Export component-model
- Represents an export in a WebAssembly component.
- Component
Export Name component-model
- Represents the name of a component export.
- Component
Func Type component-model
- Represents a type of a function in a WebAssembly component.
- Component
Import component-model
- Represents an import in a WebAssembly component
- Component
Import Name component-model
- Represents the name of a component import.
- Component
Instantiation Arg component-model
- Represents an argument to instantiating a WebAssembly component.
- Component
Start Function component-model
- Represents the start function in a WebAssembly component.
- Composite
Type - Represents a composite type in a WebAssembly module.
- Const
Expr - Represents an initialization expression.
- Cont
Type - Represents a type of a continuation in a WebAssembly module.
- Control
Stack - The Wasm control stack for the
OperatorsReader
. - Core
Dump Instance - A single instance from a coredump instances section
- Core
Dump Instances Section - A custom section representing the instances involved in a given coredump
- Core
Dump Modules Section - The data portion of a “coremodules” custom section. This contains a vec of module names that will be referenced by index by other coredump sections.
- Core
Dump Section - The data portion of a custom section representing a core dump. Per the tool-conventions repo, this section just specifies the executable name that the core dump came from while the rest of the core dump information is contained in a corestack custom section
- Core
Dump Stack Frame - A single stack frame from a core dump
- Core
Dump Stack Section - The data portion of a custom section representing a core dump stack. The structure of this follows the coredump spec in the tool-conventions repo
- Custom
Section Reader - A reader for custom sections of a WebAssembly module.
- Data
- Represents a data segment in a core WebAssembly module.
- Defined
Data Symbol - Represents the metadata about a data symbol defined in the wasm file.
- Element
- Represents a core WebAssembly element segment.
- Export
- Represents an export in a WebAssembly module.
- Export
Info - Field
Type - Represents a field type of an array or a struct.
- Frame
validate
- A Wasm control flow block on the control flow stack during Wasm validation.
- Func
ToValidate validate
- Resources necessary to perform validation of a function.
- Func
Type - Represents a type of a function in a WebAssembly module.
- Func
Validator validate
- Validation context for a WebAssembly function.
- Func
Validator Allocations validate
- External handle to the internal allocations used during function validation.
- Function
Body - Represents a WebAssembly function body.
- Global
- Represents a core WebAssembly global.
- Global
Type - Represents a global’s type.
- Ieee32
- An IEEE binary32 immediate floating point value, represented as a u32 containing the bit pattern.
- Ieee64
- An IEEE binary64 immediate floating point value, represented as a u64 containing the bit pattern.
- Import
- Represents an import in a WebAssembly module.
- Import
Info - Indirect
Naming - Represents an indirect name in the names custom section.
- Init
Func - Represents an init function in the linking custom section.
- Instantiation
Arg component-model
- Represents an argument to instantiating a WebAssembly module.
- Linking
Section Reader - A reader for the
linking
custom section of a WebAssembly module. - Locals
Iterator - An iterator over locals in a function body.
- Locals
Reader - A reader for a function body’s locals.
- MemArg
- Represents a memory immediate in a WebAssembly memory instruction.
- MemInfo
- Represents a
WASM_DYLINK_MEM_INFO
field - Memory
Type - Represents a memory’s type.
- Naming
- Represents a name for an index from the names section.
- Operators
Iterator - An iterator over a function’s operators.
- Operators
Iterator With Offsets - An iterator over a function’s operators with offsets.
- Operators
Reader - A reader for a core WebAssembly function’s operators. The
OperatorsReader
internally maintains a stack of the kinds of frames within an expression or function body. This is necessary to enforce the syntactic requirements of the binary format. The BinaryReader can also be used to read the operators by providing an externalFrameStack
instance. - Operators
Reader Allocations - External handle to the internal allocations used by the OperatorsReader
- Packed
Index - A packed representation of a type index.
- Parser
- An incremental parser of a binary WebAssembly module or component.
- Producers
Field - A field from the producers custom section.
- Producers
Field Value - Represents a field value in the producers custom section.
- RecGroup
- Represents a recursive type group in a WebAssembly module.
- RefType
- A reference type.
- Reloc
Section Reader - Reader for reloc.* sections as defined by https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md#relocation-sections.
- Relocation
Entry - Single relocation entry within a
reloc.*
section, as defined at https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md#relocation-sections. - Resume
Table - A representation of dispatch tables on
resume
andresume_throw
instructions. - Section
Limited - A generic structure for reading a section of a WebAssembly binary which has a limited number of items within it.
- Section
Limited Into Iter - A consuming iterator of a
SectionLimited
. - Section
Limited Into Iter With Offsets - An iterator over a limited section iterator.
- Segment
- Represents extra metadata about the data segments.
- Segment
Flags - Flags for WebAssembly segments.
- Struct
Type - Represents a type of a struct in a WebAssembly module.
- SubType
- Represents a subtype of possible other types in a WebAssembly module.
- Subsections
- Iterator/reader over the contents of a section which is composed of subsections.
- Symbol
Flags - Flags for WebAssembly symbols.
- Table
- Type information about a table defined in the table section of a WebAssembly module.
- Table
Type - Represents a table’s type.
- TagType
- A tag’s type.
- TryTable
- A
try_table
entries representation. - V128
- Represents a 128-bit vector value.
- Validator
validate
- Validator for a WebAssembly binary module or component.
- Validator
Id validate
- A unique identifier for a particular
Validator
. - Validator
Resources validate
- The implementation of
WasmModuleResources
used byValidator
. - Variant
Case component-model
- Represents a case in a variant type.
- Wasm
Features - Flags for features that are enabled for validation.
- Wasm
Features Inflated features
- Inflated version of
WasmFeatures
that allows for exhaustive matching on fields.
Enums§
- Abstract
Heap Type - An abstract heap type.
- Block
Type - Represents a block type.
- Canonical
Function component-model
- Represents a canonical function in a WebAssembly component.
- Canonical
Option component-model
- Represents options for component functions.
- Catch
- Catch clauses that can be specified in
TryTable
. - Chunk
- A successful return payload from
Parser::parse
. - Comdat
Symbol Kind - Represents a symbol kind.
- Component
Alias component-model
- Represents an alias in a WebAssembly component.
- Component
Defined Type component-model
- Represents a defined type in a WebAssembly component.
- Component
External Kind component-model
- Represents the kind of an external items of a WebAssembly component.
- Component
Instance component-model
- Represents an instance in a WebAssembly component.
- Component
Name component-model
- Represents a name read from the names custom section.
- Component
Outer Alias Kind component-model
- Represents the kind of an outer alias in a WebAssembly component.
- Component
Type component-model
- Represents a type in a WebAssembly component.
- Component
Type Declaration component-model
- Represents part of a component type declaration in a WebAssembly component.
- Component
Type Ref component-model
- Represents a reference to a component type.
- Component
ValType component-model
- Represents a value type in a WebAssembly component.
- Composite
Inner Type - A
CompositeType
can contain one of these types. - Core
Dump Value - Local and stack values are encoded using one byte for the type (similar to Wasm’s Number Types) followed by bytes representing the actual value See the tool-conventions repo for more details.
- Core
Type component-model
- Represents a core type in a WebAssembly component.
- Data
Kind - The kind of data segment.
- Dylink0
Subsection - Possible subsections of the
dylink.0
custom section. - Element
Items - Represents the items of an element segment.
- Element
Kind - The kind of element segment.
- Encoding
- The supported encoding formats for the parser.
- External
Kind - External types as defined here.
- Frame
Kind - The kind of a control flow
Frame
. - Handle
- Handle clauses that can be specified in
ResumeTable
. - Heap
Type - A heap type.
- Instance
component-model
- Represents an instance of a WebAssembly module.
- Instance
Type Declaration component-model
- Represents an instance type declaration in a WebAssembly component.
- Instantiation
ArgKind component-model
- Represents the kind of an instantiation argument for a core instance.
- Known
Custom - Return value of
CustomSectionReader::as_known
. - Linking
- Represents a subsection read from the linking custom section.
- Module
Type Declaration component-model
- Represents a module type declaration in a WebAssembly component.
- Name
- Represents a name read from the names custom section.
- Operator
- Instructions as defined here.
- Ordering
- Represents the memory ordering for atomic instructions.
- Outer
Alias Kind component-model
- Represents the kind of an outer core alias in a WebAssembly component.
- Payload
- Values that can be parsed from a WebAssembly module or component.
- Primitive
ValType component-model
- Represents a primitive value type.
- Reloc
Addend Kind - Indicates the kind of addend that applies to a relocation entry.
- Relocation
Type - Relocation entry type. Each entry type corresponds to one of the
R_WASM_*
constants defined at https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/BinaryFormat/WasmRelocs.def and https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md#relocation-sections. - Storage
Type - Represents storage types introduced in the GC spec for array and struct fields.
- Symbol
Info - Represents extra information about symbols in the linking custom section.
- Table
Init - Different modes of initializing a table.
- TagKind
- Represents a tag kind.
- Type
Bounds component-model
- Represents the type bounds for imports and exports.
- TypeRef
- Represents a reference to a type definition in a WebAssembly module.
- Unpacked
Index - The uncompressed form of a
PackedIndex
. - ValType
- Represents the types of values in a WebAssembly module.
- Valid
Payload validate
- Possible return values from
Validator::payload
.
Traits§
- Frame
Stack - A trait representing the stack of frames within a function.
- From
Reader - A trait implemented for items that can be decoded directly from a
BinaryReader
, or that which can be parsed from the WebAssembly binary format. - Module
Arity - To compute the arity (param and result counts) of “variable-arity” operators, the operator_arity macro needs information about the module’s types and the current control stack. The ModuleArity trait exposes this information.
- Subsection
- A trait implemented for subsections of another outer section.
- Visit
Operator - Trait implemented by types that can visit all
Operator
variants. - Visit
Simd Operator simd
- Trait implemented by types that can visit all Wasm
simd
andrelaxed-simd
Operator
s. - Wasm
Module Resources validate
- Types that qualify as Wasm validation database.
Functions§
- validate
validate
- Test whether the given buffer contains a valid WebAssembly module or component,
analogous to
WebAssembly.validate
in the JS API.
Type Aliases§
- Branch
Hint Section Reader - A reader for the
metadata.code.branch_hint
custom section. - Code
Section Reader - A reader for the code section of a WebAssembly module.
- Comdat
Map - Represents a reader for COMDAT data from the linking custom section.
- Component
Alias Section Reader component-model
- Section reader for the component alias section
- Component
Canonical Section Reader component-model
- A reader for the canonical section of a WebAssembly component.
- Component
Export Section Reader component-model
- A reader for the export section of a WebAssembly component.
- Component
Import Section Reader component-model
- A reader for the import section of a WebAssembly component.
- Component
Instance Section Reader component-model
- A reader for the component instance section of a WebAssembly component.
- Component
Name Section Reader component-model
- Type used to iterate and parse the contents of the
component-name
custom section in components, similar to thename
section of core modules. - Component
Type Section Reader component-model
- A reader for the type section of a WebAssembly component.
- Core
Type Section Reader component-model
- A reader for the core type section of a WebAssembly component.
- Data
Section Reader - A reader for the data section of a WebAssembly module.
- Dylink0
Section Reader - Parser for the dynamic linking
dylink.0
custom section. - Element
Section Reader - A reader for the element section of a WebAssembly module.
- Export
Section Reader - A reader for the export section of a WebAssembly module.
- Function
Section Reader - A reader for the function section of a WebAssembly module.
- Global
Section Reader - A reader for the global section of a WebAssembly module.
- Import
Section Reader - A reader for the import section of a WebAssembly module.
- Indirect
Name Map - Represents a reader for indirect names from the names custom section.
- Init
Func Map - Represents a reader for init functions from the linking custom section.
- Instance
Section Reader component-model
- A reader for the core instance section of a WebAssembly component.
- Memory
Section Reader - A reader for the memory section of a WebAssembly module.
- NameMap
- Represents a name map from the names custom section.
- Name
Section Reader - A reader for the name custom section of a WebAssembly module.
- Producers
Section Reader - A reader for the producers custom section of a WebAssembly module.
- Relocation
Entry Reader - Reader for relocation entries within a
reloc.*
section. - Result
- The result for
BinaryReader
operations. - Segment
Map - Represents a reader for segments from the linking custom section.
- Symbol
Info Map - Represents a reader for symbol info from the linking custom section.
- Table
Section Reader - A reader for the table section of a WebAssembly module.
- TagSection
Reader - A reader for the tags section of a WebAssembly module.
- Type
Section Reader - A reader for the type section of a WebAssembly module.