Documentation ¶
Overview ¶
WebAssembly (https://webassembly.org/) is an open standard for portable executable programs. It is designed to be a portable compilation target for programming languages.
The standard defines two formats for encoding WebAssembly programs ("modules"):
- A machine-optimized binary format (WASM, https://webassembly.github.io/spec/core/binary/index.html), which is not designed to be used by humans
- A human-readable text format (WAT, https://webassembly.github.io/spec/core/text/index.html)
WebAssembly modules in either format can be converted into the other format.
There exists also another textual format, WAST, which is a superset of WAT, but is not part of the official standard.
Package wasm implements a representation of WebAssembly modules (Module) and related types, e.g. instructions (Instruction).
Package wasm also implements a reader and writer for the binary format:
- The reader (WASMReader) allows parsing a WebAssembly module in binary form ([]byte) into an representation of the module (Module).
- The writer (WASMWriter) allows encoding the representation of the module (Module) to a WebAssembly program in binary form ([]byte).
Package wasm does not currently provide a reader and writer for the textual format (WAT).
Package wasm is not a compiler for Cadence programs, but rather a building block that allows reading and writing WebAssembly modules.
Index ¶
- type Code
- type CodeSectionLocalsCountMismatchError
- type Function
- type FunctionType
- type Import
- type IncompleteNameError
- type Instruction
- type InstructionI32Add
- type InstructionLocalGet
- type InvalidCodeSectionCompressedLocalsCountError
- type InvalidCodeSectionFunctionCountError
- type InvalidCodeSectionLocalTypeError
- type InvalidCodeSectionLocalsCountError
- type InvalidCodeSizeError
- type InvalidDuplicateSectionError
- type InvalidFuncTypeIndicatorError
- type InvalidFuncTypeParameterCountError
- type InvalidFuncTypeParameterTypeError
- type InvalidFuncTypeResultCountError
- type InvalidFuncTypeResultTypeError
- type InvalidFunctionCodeError
- type InvalidFunctionSectionFunctionCountError
- type InvalidFunctionSectionFunctionTypeIDError
- type InvalidImportError
- type InvalidImportSectionFunctionTypeIDError
- type InvalidImportSectionImportCountError
- type InvalidImportTypeIndicatorError
- type InvalidInstructionArgumentError
- type InvalidMagicError
- type InvalidNameError
- type InvalidNameLengthError
- type InvalidNonUTF8NameError
- type InvalidOpcodeError
- type InvalidSectionIDError
- type InvalidSectionSizeError
- type InvalidTypeSectionTypeCountError
- type InvalidValTypeError
- type InvalidVersionError
- type MissingEndInstructionError
- type Module
- type ValueType
- type WASMReader
- type WASMWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code struct { Locals []ValueType Instructions []Instruction }
Code represents the code of a function
type CodeSectionLocalsCountMismatchError ¶
CodeSectionLocalsCountMismatchError is returned when the sum of the compressed locals locals count in the code section does not match the number of locals in the code section of the WASM binary
func (CodeSectionLocalsCountMismatchError) Error ¶
func (e CodeSectionLocalsCountMismatchError) Error() string
type FunctionType ¶
FunctionType is the type of a function. It may have multiple parameters and return values
type Import ¶
type Import struct { Module string Name string // TODO: add support for tables, memories, and globals TypeID uint32 }
Import represents an import
type IncompleteNameError ¶
IncompleteNameError is returned the WASM binary specifies an incomplete name
func (IncompleteNameError) Error ¶
func (e IncompleteNameError) Error() string
type Instruction ¶
type Instruction interface {
// contains filtered or unexported methods
}
type InstructionI32Add ¶
type InstructionI32Add struct{}
InstructionI32Add is the 'i32.add' instruction
type InstructionLocalGet ¶
type InstructionLocalGet struct {
Index uint32
}
InstructionLocalGet is the 'local.get' instruction
type InvalidCodeSectionCompressedLocalsCountError ¶
InvalidCodeSectionCompressedLocalsCountError is returned when the WASM binary specifies an invalid local type in the code section
func (InvalidCodeSectionCompressedLocalsCountError) Error ¶
func (e InvalidCodeSectionCompressedLocalsCountError) Error() string
func (InvalidCodeSectionCompressedLocalsCountError) Unwrap ¶
func (e InvalidCodeSectionCompressedLocalsCountError) Unwrap() error
type InvalidCodeSectionFunctionCountError ¶
InvalidCodeSectionFunctionCountError is returned when the WASM binary specifies an invalid function count in the code section
func (InvalidCodeSectionFunctionCountError) Error ¶
func (e InvalidCodeSectionFunctionCountError) Error() string
func (InvalidCodeSectionFunctionCountError) Unwrap ¶
func (e InvalidCodeSectionFunctionCountError) Unwrap() error
type InvalidCodeSectionLocalTypeError ¶
InvalidCodeSectionLocalTypeError is returned when the WASM binary specifies an invalid local type in the code section
func (InvalidCodeSectionLocalTypeError) Error ¶
func (e InvalidCodeSectionLocalTypeError) Error() string
func (InvalidCodeSectionLocalTypeError) Unwrap ¶
func (e InvalidCodeSectionLocalTypeError) Unwrap() error
type InvalidCodeSectionLocalsCountError ¶
InvalidCodeSectionLocalsCountError is returned when the WASM binary specifies an invalid locals count in the code section
func (InvalidCodeSectionLocalsCountError) Error ¶
func (e InvalidCodeSectionLocalsCountError) Error() string
func (InvalidCodeSectionLocalsCountError) Unwrap ¶
func (e InvalidCodeSectionLocalsCountError) Unwrap() error
type InvalidCodeSizeError ¶
InvalidCodeSizeError is returned when the WASM binary specifies an invalid code size in the code section
func (InvalidCodeSizeError) Error ¶
func (e InvalidCodeSizeError) Error() string
type InvalidDuplicateSectionError ¶
type InvalidDuplicateSectionError struct { Offset int SectionID sectionID }
InvalidDuplicateSectionError is returned when the WASM binary specifies a duplicate section
func (InvalidDuplicateSectionError) Error ¶
func (e InvalidDuplicateSectionError) Error() string
type InvalidFuncTypeIndicatorError ¶
InvalidFuncTypeIndicatorError is returned when the WASM binary specifies an invalid function type indicator
func (InvalidFuncTypeIndicatorError) Error ¶
func (e InvalidFuncTypeIndicatorError) Error() string
func (InvalidFuncTypeIndicatorError) Unwrap ¶
func (e InvalidFuncTypeIndicatorError) Unwrap() error
type InvalidFuncTypeParameterCountError ¶
InvalidFuncTypeParameterCountError is returned when the WASM binary specifies an invalid func type parameter count
func (InvalidFuncTypeParameterCountError) Error ¶
func (e InvalidFuncTypeParameterCountError) Error() string
func (InvalidFuncTypeParameterCountError) Unwrap ¶
func (e InvalidFuncTypeParameterCountError) Unwrap() error
type InvalidFuncTypeParameterTypeError ¶
InvalidFuncTypeParameterTypeError is returned when the WASM binary specifies an invalid function type parameter type
func (InvalidFuncTypeParameterTypeError) Error ¶
func (e InvalidFuncTypeParameterTypeError) Error() string
func (InvalidFuncTypeParameterTypeError) Unwrap ¶
func (e InvalidFuncTypeParameterTypeError) Unwrap() error
type InvalidFuncTypeResultCountError ¶
InvalidFuncTypeResultCountError is returned when the WASM binary specifies an invalid func type result count
func (InvalidFuncTypeResultCountError) Error ¶
func (e InvalidFuncTypeResultCountError) Error() string
func (InvalidFuncTypeResultCountError) Unwrap ¶
func (e InvalidFuncTypeResultCountError) Unwrap() error
type InvalidFuncTypeResultTypeError ¶
InvalidFuncTypeResultTypeError is returned when the WASM binary specifies an invalid function type result type
func (InvalidFuncTypeResultTypeError) Error ¶
func (e InvalidFuncTypeResultTypeError) Error() string
func (InvalidFuncTypeResultTypeError) Unwrap ¶
func (e InvalidFuncTypeResultTypeError) Unwrap() error
type InvalidFunctionCodeError ¶
InvalidFunctionCodeError is returned when the WASM binary specifies invalid code for a function in the code section
func (InvalidFunctionCodeError) Error ¶
func (e InvalidFunctionCodeError) Error() string
func (InvalidFunctionCodeError) Unwrap ¶
func (e InvalidFunctionCodeError) Unwrap() error
type InvalidFunctionSectionFunctionCountError ¶
InvalidFunctionSectionFunctionCountError is returned when the WASM binary specifies an invalid count in the function section
func (InvalidFunctionSectionFunctionCountError) Error ¶
func (e InvalidFunctionSectionFunctionCountError) Error() string
func (InvalidFunctionSectionFunctionCountError) Unwrap ¶
func (e InvalidFunctionSectionFunctionCountError) Unwrap() error
type InvalidFunctionSectionFunctionTypeIDError ¶
InvalidFunctionSectionFunctionTypeIDError is returned when the WASM binary specifies an invalid function type ID in the function section
func (InvalidFunctionSectionFunctionTypeIDError) Error ¶
func (e InvalidFunctionSectionFunctionTypeIDError) Error() string
func (InvalidFunctionSectionFunctionTypeIDError) Unwrap ¶
func (e InvalidFunctionSectionFunctionTypeIDError) Unwrap() error
type InvalidImportError ¶
InvalidImportError is returned when the WASM binary specifies invalid import in the import section
func (InvalidImportError) Error ¶
func (e InvalidImportError) Error() string
func (InvalidImportError) Unwrap ¶
func (e InvalidImportError) Unwrap() error
type InvalidImportSectionFunctionTypeIDError ¶
InvalidImportSectionFunctionTypeIDError is returned when the WASM binary specifies an invalid function type ID in the import section
func (InvalidImportSectionFunctionTypeIDError) Error ¶
func (e InvalidImportSectionFunctionTypeIDError) Error() string
func (InvalidImportSectionFunctionTypeIDError) Unwrap ¶
func (e InvalidImportSectionFunctionTypeIDError) Unwrap() error
type InvalidImportSectionImportCountError ¶
InvalidImportSectionImportCountError is returned when the WASM binary specifies an invalid count in the import section
func (InvalidImportSectionImportCountError) Error ¶
func (e InvalidImportSectionImportCountError) Error() string
func (InvalidImportSectionImportCountError) Unwrap ¶
func (e InvalidImportSectionImportCountError) Unwrap() error
type InvalidImportTypeIndicatorError ¶
type InvalidImportTypeIndicatorError struct { Offset int TypeIndicator importTypeIndicator ReadError error }
InvalidImportTypeIndicatorError is returned when the WASM binary specifies an invalid type indicator in the import section
func (InvalidImportTypeIndicatorError) Error ¶
func (e InvalidImportTypeIndicatorError) Error() string
func (InvalidImportTypeIndicatorError) Unwrap ¶
func (e InvalidImportTypeIndicatorError) Unwrap() error
type InvalidInstructionArgumentError ¶
InvalidInstructionArgumentError is returned when the WASM binary specifies an invalid argument for an instruction in the code section
func (InvalidInstructionArgumentError) Error ¶
func (e InvalidInstructionArgumentError) Error() string
func (InvalidInstructionArgumentError) Unwrap ¶
func (e InvalidInstructionArgumentError) Unwrap() error
type InvalidMagicError ¶
InvalidMagicError is returned when the WASM binary does not start with the magic byte sequence
func (InvalidMagicError) Error ¶
func (e InvalidMagicError) Error() string
func (InvalidMagicError) Unwrap ¶
func (e InvalidMagicError) Unwrap() error
type InvalidNameError ¶
InvalidNameError is returned the WASM binary specifies an invalid name
func (InvalidNameError) Error ¶
func (e InvalidNameError) Error() string
func (InvalidNameError) Unwrap ¶
func (e InvalidNameError) Unwrap() error
type InvalidNameLengthError ¶
InvalidNameLengthError is returned the WASM binary specifies an invalid name length
func (InvalidNameLengthError) Error ¶
func (e InvalidNameLengthError) Error() string
func (InvalidNameLengthError) Unwrap ¶
func (e InvalidNameLengthError) Unwrap() error
type InvalidNonUTF8NameError ¶
InvalidNonUTF8NameError is returned when the WASM binary specifies or the writer is given a name which is not properly UTF-8 encoded
func (InvalidNonUTF8NameError) Error ¶
func (e InvalidNonUTF8NameError) Error() string
type InvalidOpcodeError ¶
InvalidOpcodeError is returned when the WASM binary specifies an invalid opcode in the code section
func (InvalidOpcodeError) Error ¶
func (e InvalidOpcodeError) Error() string
func (InvalidOpcodeError) Unwrap ¶
func (e InvalidOpcodeError) Unwrap() error
type InvalidSectionIDError ¶
InvalidSectionIDError is returned when the WASM binary specifies an invalid section ID
func (InvalidSectionIDError) Error ¶
func (e InvalidSectionIDError) Error() string
func (InvalidSectionIDError) Unwrap ¶
func (e InvalidSectionIDError) Unwrap() error
type InvalidSectionSizeError ¶
InvalidSectionSizeError is returned when the WASM binary specifies an invalid section size
func (InvalidSectionSizeError) Error ¶
func (e InvalidSectionSizeError) Error() string
func (InvalidSectionSizeError) Unwrap ¶
func (e InvalidSectionSizeError) Unwrap() error
type InvalidTypeSectionTypeCountError ¶
InvalidTypeSectionTypeCountError is returned when the WASM binary specifies an invalid count in the type section
func (InvalidTypeSectionTypeCountError) Error ¶
func (e InvalidTypeSectionTypeCountError) Error() string
func (InvalidTypeSectionTypeCountError) Unwrap ¶
func (e InvalidTypeSectionTypeCountError) Unwrap() error
type InvalidValTypeError ¶
InvalidValTypeError is returned when the WASM binary specifies an invalid value type
func (InvalidValTypeError) Error ¶
func (e InvalidValTypeError) Error() string
func (InvalidValTypeError) Unwrap ¶
func (e InvalidValTypeError) Unwrap() error
type InvalidVersionError ¶
InvalidMagicError is returned when the WASM binary does not have the expected version
func (InvalidVersionError) Error ¶
func (e InvalidVersionError) Error() string
func (InvalidVersionError) Unwrap ¶
func (e InvalidVersionError) Unwrap() error
type MissingEndInstructionError ¶
type MissingEndInstructionError struct {
Offset int
}
MissingEndInstructionError is returned when the WASM binary misses an end instruction for a function in the code section
func (MissingEndInstructionError) Error ¶
func (e MissingEndInstructionError) Error() string
type Module ¶
type Module struct { Types []*FunctionType Imports []*Import // contains filtered or unexported fields }
Module represents a module
type WASMReader ¶
type WASMReader struct { Module Module // contains filtered or unexported fields }
WASMReader allows reading WASM binaries
type WASMWriter ¶
type WASMWriter struct {
// contains filtered or unexported fields
}
WASMWriter allows writing WASM binaries