Crate wasmparser

Source
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
Type definitions for maps and sets used by the wasmparser crate.
names
Definitions of name-related helpers and newtypes, primarily for the component model.
types
Types relating to type information provided by validation.

Macros§

for_each_operator
A helper macro to conveniently iterate over all opcodes recognized by this crate. This can be used to work with either the Operator enumeration or the VisitOperator trait if your use case uniformly handles all operators the same way.

Structs§

ArrayType
Represents a type of an array in a WebAssembly module.
BinaryReader
A binary reader of the WebAssembly structures and types.
BinaryReaderError
A binary reader for WebAssembly modules.
BrTable
A br_table entries representation.
BranchHint
A hint for a single branch.
BranchHintFunction
Branch hints for a single function.
Comdat
Represents COMDAT data in the linking custom section.
ComdatSymbol
Represents a symbol that is part of a comdat.
ComponentExport
Represents an export in a WebAssembly component.
ComponentExportName
Represents the name of a component export.
ComponentFuncType
Represents a type of a function in a WebAssembly component.
ComponentImport
Represents an import in a WebAssembly component
ComponentImportName
Represents the name of a component import.
ComponentInstantiationArg
Represents an argument to instantiating a WebAssembly component.
ComponentStartFunction
Represents the start function in a WebAssembly component.
CompositeType
Represents a composite type in a WebAssembly module.
ConstExpr
Represents an initialization expression.
CoreDumpInstance
A single instance from a coredump instances section
CoreDumpInstancesSection
A custom section representing the instances involved in a given coredump
CoreDumpModulesSection
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.
CoreDumpSection
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
CoreDumpStackFrame
A single stack frame from a core dump
CoreDumpStackSection
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
CustomSectionReader
A reader for custom sections of a WebAssembly module.
Data
Represents a data segment in a core WebAssembly module.
DefinedDataSymbol
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.
ExportInfo
FieldType
Represents a field type of an array or a struct.
Frame
A Wasm control flow block on the control flow stack during Wasm validation.
FuncToValidate
Resources necessary to perform validation of a function.
FuncType
Represents a type of a function in a WebAssembly module.
FuncValidator
Validation context for a WebAssembly function.
FuncValidatorAllocations
External handle to the internal allocations used during function validation.
FunctionBody
Represents a WebAssembly function body.
Global
Represents a core WebAssembly global.
GlobalType
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.
ImportInfo
IndirectNaming
Represents an indirect name in the names custom section.
InitFunc
Represents an init function in the linking custom section.
InstantiationArg
Represents an argument to instantiating a WebAssembly module.
LinkingSectionReader
A reader for the linking custom section of a WebAssembly module.
LocalsIterator
An iterator over locals in a function body.
LocalsReader
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
MemoryType
Represents a memory’s type.
Naming
Represents a name for an index from the names section.
OperatorsIterator
An iterator over a function’s operators.
OperatorsIteratorWithOffsets
An iterator over a function’s operators with offsets.
OperatorsReader
A reader for a core WebAssembly function’s operators.
PackedIndex
A packed representation of a type index.
Parser
An incremental parser of a binary WebAssembly module or component.
ProducersField
A field from the producers custom section.
ProducersFieldValue
Represents a field value in the producers custom section.
RecGroup
Represents a recursive type group in a WebAssembly module.
RefType
A reference type.
RelocSectionReader
Reader for reloc.* sections as defined by https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md#relocation-sections.
RelocationEntry
Single relocation entry within a reloc.* section, as defined at https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md#relocation-sections.
SectionLimited
A generic structure for reading a section of a WebAssembly binary which has a limited number of items within it.
SectionLimitedIntoIter
A consuming iterator of a SectionLimited.
SectionLimitedIntoIterWithOffsets
An iterator over a limited section iterator.
Segment
Represents extra metadata about the data segments.
SegmentFlags
Flags for WebAssembly segments.
StructType
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.
SymbolFlags
Flags for WebAssembly symbols.
Table
Type information about a table defined in the table section of a WebAssembly module.
TableType
Represents a table’s type.
TagType
A tag’s type.
TryTable
A try_table entries representation.
V128
Represents a 128-bit vector value.
Validator
Validator for a WebAssembly binary module or component.
ValidatorId
A unique identifier for a particular Validator.
ValidatorResources
The implementation of WasmModuleResources used by Validator.
VariantCase
Represents a case in a variant type.
WasmFeatures
Enabled WebAssembly proposals and features.

Enums§

AbstractHeapType
An abstract heap type.
BlockType
Represents a block type.
CanonicalFunction
Represents a canonical function in a WebAssembly component.
CanonicalOption
Represents options for component functions.
Catch
Catch clauses that can be specified in TryTable.
Chunk
A successful return payload from Parser::parse.
ComdatSymbolKind
Represents a symbol kind.
ComponentAlias
Represents an alias in a WebAssembly component.
ComponentDefinedType
Represents a defined type in a WebAssembly component.
ComponentExternalKind
Represents the kind of an external items of a WebAssembly component.
ComponentFuncResult
Represents the result type of a component function.
ComponentInstance
Represents an instance in a WebAssembly component.
ComponentName
Represents a name read from the names custom section.
ComponentOuterAliasKind
Represents the kind of an outer alias in a WebAssembly component.
ComponentType
Represents a type in a WebAssembly component.
ComponentTypeDeclaration
Represents part of a component type declaration in a WebAssembly component.
ComponentTypeRef
Represents a reference to a component type.
ComponentValType
Represents a value type in a WebAssembly component.
CompositeInnerType
A CompositeType can contain one of these types.
CoreDumpValue
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.
CoreType
Represents a core type in a WebAssembly component.
DataKind
The kind of data segment.
Dylink0Subsection
Possible subsections of the dylink.0 custom section.
ElementItems
Represents the items of an element segment.
ElementKind
The kind of element segment.
Encoding
The supported encoding formats for the parser.
ExternalKind
External types as defined here.
FrameKind
The kind of a control flow Frame.
HeapType
A heap type.
Instance
Represents an instance of a WebAssembly module.
InstanceTypeDeclaration
Represents an instance type declaration in a WebAssembly component.
InstantiationArgKind
Represents the kind of an instantiation argument for a core instance.
KnownCustom
Return value of CustomSectionReader::as_known.
Linking
Represents a subsection read from the linking custom section.
ModuleTypeDeclaration
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.
OuterAliasKind
Represents the kind of an outer core alias in a WebAssembly component.
Payload
Values that can be parsed from a WebAssembly module or component.
PrimitiveValType
Represents a primitive value type.
RelocAddendKind
Indicates the kind of addend that applies to a relocation entry.
RelocationType
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.
StorageType
Represents storage types introduced in the GC spec for array and struct fields.
SymbolInfo
Represents extra information about symbols in the linking custom section.
TableInit
Different modes of initializing a table.
TagKind
Represents a tag kind.
TypeBounds
Represents the type bounds for imports and exports.
TypeRef
Represents a reference to a type definition in a WebAssembly module.
UnpackedIndex
The uncompressed form of a PackedIndex.
ValType
Represents the types of values in a WebAssembly module.
ValidPayload
Possible return values from Validator::payload.

Traits§

FromReader
A trait implemented for items that can be decoded directly from a BinaryReader, or that which can be parsed from the WebAssembly binary format.
Subsection
A trait implemented for subsections of another outer section.
VisitOperator
Trait implemented by types that can visit all Operator variants.
WasmModuleResources
Types that qualify as Wasm validation database.

Functions§

validate
Test whether the given buffer contains a valid WebAssembly module or component, analogous to WebAssembly.validate in the JS API.

Type Aliases§

BranchHintSectionReader
A reader for the metadata.code.branch_hint custom section.
CodeSectionReader
A reader for the code section of a WebAssembly module.
ComdatMap
Represents a reader for COMDAT data from the linking custom section.
ComponentAliasSectionReader
Section reader for the component alias section
ComponentCanonicalSectionReader
A reader for the canonical section of a WebAssembly component.
ComponentExportSectionReader
A reader for the export section of a WebAssembly component.
ComponentImportSectionReader
A reader for the import section of a WebAssembly component.
ComponentInstanceSectionReader
A reader for the component instance section of a WebAssembly component.
ComponentNameSectionReader
Type used to iterate and parse the contents of the component-name custom section in compnents, similar to the name section of core modules.
ComponentTypeSectionReader
A reader for the type section of a WebAssembly component.
CoreTypeSectionReader
A reader for the core type section of a WebAssembly component.
DataSectionReader
A reader for the data section of a WebAssembly module.
Dylink0SectionReader
Parser for the dynamic linking dylink.0 custom section.
ElementSectionReader
A reader for the element section of a WebAssembly module.
ExportSectionReader
A reader for the export section of a WebAssembly module.
FunctionSectionReader
A reader for the function section of a WebAssembly module.
GlobalSectionReader
A reader for the global section of a WebAssembly module.
ImportSectionReader
A reader for the import section of a WebAssembly module.
IndirectNameMap
Represents a reader for indirect names from the names custom section.
InitFuncMap
Represents a reader for init functions from the linking custom section.
InstanceSectionReader
A reader for the core instance section of a WebAssembly component.
MemorySectionReader
A reader for the memory section of a WebAssembly module.
NameMap
Represents a name map from the names custom section.
NameSectionReader
A reader for the name custom section of a WebAssembly module.
ProducersSectionReader
A reader for the producers custom section of a WebAssembly module.
RelocationEntryReader
Reader for relocation entries within a reloc.* section.
Result
The result for BinaryReader operations.
SegmentMap
Represents a reader for segments from the linking custom section.
SymbolInfoMap
Represents a reader for symbol info from the linking custom section.
TableSectionReader
A reader for the table section of a WebAssembly module.
TagSectionReader
A reader for the tags section of a WebAssembly module.
TypeSectionReader
A reader for the type section of a WebAssembly module.