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 ¶
- Constants
- func WASM2WAT(binary []byte) string
- type Block
- type BlockType
- type Buffer
- func (buf *Buffer) Bytes() []byte
- func (buf *Buffer) PeekByte() (byte, error)
- func (buf *Buffer) Read(data []byte) (int, error)
- func (buf *Buffer) ReadByte() (byte, error)
- func (buf *Buffer) ReadBytesEqual(expected []byte) (bool, error)
- func (buf *Buffer) WriteByte(b byte) error
- func (buf *Buffer) WriteBytes(data []byte) error
- type Code
- type CodeSectionLocalsCountMismatchError
- type Data
- type Export
- type ExportDescriptor
- type Function
- type FunctionCountMismatchError
- type FunctionExport
- type FunctionType
- type Import
- type IncompleteNameError
- type Instruction
- type InstructionBlock
- type InstructionBr
- type InstructionBrIf
- type InstructionBrTable
- type InstructionCall
- type InstructionCallIndirect
- type InstructionDrop
- type InstructionEnd
- type InstructionGlobalGet
- type InstructionGlobalSet
- type InstructionI32Add
- type InstructionI32And
- type InstructionI32Clz
- type InstructionI32Const
- type InstructionI32Ctz
- type InstructionI32DivS
- type InstructionI32DivU
- type InstructionI32Eq
- type InstructionI32Eqz
- type InstructionI32GeS
- type InstructionI32GeU
- type InstructionI32GtS
- type InstructionI32GtU
- type InstructionI32LeS
- type InstructionI32LeU
- type InstructionI32LtS
- type InstructionI32LtU
- type InstructionI32Mul
- type InstructionI32Ne
- type InstructionI32Or
- type InstructionI32Popcnt
- type InstructionI32RemS
- type InstructionI32RemU
- type InstructionI32Rotl
- type InstructionI32Rotr
- type InstructionI32Shl
- type InstructionI32ShrS
- type InstructionI32ShrU
- type InstructionI32Sub
- type InstructionI32WrapI64
- type InstructionI32Xor
- type InstructionI64Add
- type InstructionI64And
- type InstructionI64Clz
- type InstructionI64Const
- type InstructionI64Ctz
- type InstructionI64DivS
- type InstructionI64DivU
- type InstructionI64Eq
- type InstructionI64Eqz
- type InstructionI64ExtendI32S
- type InstructionI64ExtendI32U
- type InstructionI64GeS
- type InstructionI64GeU
- type InstructionI64GtS
- type InstructionI64GtU
- type InstructionI64LeS
- type InstructionI64LeU
- type InstructionI64LtS
- type InstructionI64LtU
- type InstructionI64Mul
- type InstructionI64Ne
- type InstructionI64Or
- type InstructionI64Popcnt
- type InstructionI64RemS
- type InstructionI64RemU
- type InstructionI64Rotl
- type InstructionI64Rotr
- type InstructionI64Shl
- type InstructionI64ShrS
- type InstructionI64ShrU
- type InstructionI64Sub
- type InstructionI64Xor
- type InstructionIf
- type InstructionLocalGet
- type InstructionLocalSet
- type InstructionLocalTee
- type InstructionLoop
- type InstructionNop
- type InstructionRefFunc
- type InstructionRefIsNull
- type InstructionRefNull
- type InstructionReturn
- type InstructionSelect
- type InstructionUnreachable
- type InvalidBlockSecondInstructionsError
- type InvalidBlockTypeTypeIndexError
- type InvalidCodeSectionCompressedLocalsCountError
- type InvalidCodeSectionFunctionCountError
- type InvalidCodeSectionLocalTypeError
- type InvalidCodeSectionLocalsCountError
- type InvalidCodeSizeError
- type InvalidDataSectionInitByteCountError
- type InvalidDataSectionMemoryIndexError
- type InvalidDataSectionSegmentCountError
- type InvalidDataSegmentError
- type InvalidDuplicateSectionError
- type InvalidExportError
- type InvalidExportIndicatorError
- type InvalidExportSectionExportCountError
- type InvalidExportSectionIndexError
- type InvalidFuncTypeIndicatorError
- type InvalidFuncTypeParameterCountError
- type InvalidFuncTypeParameterTypeError
- type InvalidFuncTypeResultCountError
- type InvalidFuncTypeResultTypeError
- type InvalidFunctionCodeError
- type InvalidFunctionSectionFunctionCountError
- type InvalidFunctionSectionTypeIndexError
- type InvalidImportError
- type InvalidImportIndicatorError
- type InvalidImportSectionImportCountError
- type InvalidImportSectionTypeIndexError
- type InvalidInstructionArgumentError
- type InvalidInstructionVectorArgumentCountError
- type InvalidLimitIndicatorError
- type InvalidLimitMaxError
- type InvalidLimitMinError
- type InvalidMagicError
- type InvalidMemoryError
- type InvalidMemorySectionMemoryCountError
- type InvalidNameError
- type InvalidNameLengthError
- type InvalidNonUTF8NameError
- type InvalidOpcodeError
- type InvalidSectionIDError
- type InvalidSectionOrderError
- type InvalidSectionSizeError
- type InvalidStartSectionFunctionIndexError
- type InvalidTypeSectionTypeCountError
- type InvalidValTypeError
- type InvalidVersionError
- type Memory
- type MemoryExport
- type MissingEndInstructionError
- type Module
- type ModuleBuilder
- func (b *ModuleBuilder) AddData(offset uint32, value []byte)
- func (b *ModuleBuilder) AddExport(export *Export)
- func (b *ModuleBuilder) AddFunction(name string, functionType *FunctionType, code *Code) uint32
- func (b *ModuleBuilder) AddFunctionImport(module string, name string, functionType *FunctionType) (uint32, error)
- func (b *ModuleBuilder) Build() *Module
- func (b *ModuleBuilder) ExportMemory(name string)
- func (b *ModuleBuilder) RequireMemory(size uint32) uint32
- type TypeIndexBlockType
- type ValueType
- type WASMReader
- type WASMWriter
Constants ¶
const MemoryPageSize = 64 * 1024
MemoryPageSize is the size of a memory page: 64KiB
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶ added in v0.12.4
type Block struct { BlockType BlockType Instructions1 []Instruction Instructions2 []Instruction }
type BlockType ¶ added in v0.12.4
type BlockType interface {
// contains filtered or unexported methods
}
type Buffer ¶ added in v0.12.4
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a byte buffer, which allows reading and writing.
func (*Buffer) ReadBytesEqual ¶ added in v0.12.4
func (*Buffer) WriteBytes ¶ added in v0.12.4
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 Data ¶ added in v0.12.5
type Data struct { // must be constant, as defined in the spec // (https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions) Offset []Instruction Init []byte MemoryIndex uint32 }
Data represents a data segment, which initializes a range of memory, at a given offset, with a static vector of bytes.
type Export ¶ added in v0.12.4
type Export struct { Descriptor ExportDescriptor Name string }
Exports represents an export
type ExportDescriptor ¶ added in v0.12.7
type ExportDescriptor interface {
// contains filtered or unexported methods
}
ExportDescriptor represents an export (e.g. a function, memory, etc.)
type FunctionCountMismatchError ¶ added in v0.12.4
type FunctionCountMismatchError struct {
Offset int
}
FunctionCountMismatchError is returned when the WASM binary specifies information for a different number of functions than previously specified
func (FunctionCountMismatchError) Error ¶ added in v0.12.4
func (e FunctionCountMismatchError) Error() string
type FunctionExport ¶ added in v0.12.7
type FunctionExport struct {
FunctionIndex uint32
}
FunctionExport represents the export of a function
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. adjust name section! TypeIndex 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
}
Instruction represents an instruction in the code of a WASM binary
type InstructionBlock ¶ added in v0.12.4
type InstructionBlock struct {
Block Block
}
InstructionBlock is the 'block' instruction
type InstructionBr ¶ added in v0.12.4
type InstructionBr struct {
LabelIndex uint32
}
InstructionBr is the 'br' instruction
type InstructionBrIf ¶ added in v0.12.4
type InstructionBrIf struct {
LabelIndex uint32
}
InstructionBrIf is the 'br_if' instruction
type InstructionBrTable ¶ added in v0.12.4
InstructionBrTable is the 'br_table' instruction
type InstructionCall ¶ added in v0.12.4
type InstructionCall struct {
FuncIndex uint32
}
InstructionCall is the 'call' instruction
type InstructionCallIndirect ¶ added in v0.12.4
InstructionCallIndirect is the 'call_indirect' instruction
type InstructionDrop ¶ added in v0.12.4
type InstructionDrop struct{}
InstructionDrop is the 'drop' instruction
type InstructionEnd ¶ added in v0.12.4
type InstructionEnd struct{}
InstructionEnd is the 'end' instruction
type InstructionGlobalGet ¶ added in v0.12.4
type InstructionGlobalGet struct {
GlobalIndex uint32
}
InstructionGlobalGet is the 'global.get' instruction
type InstructionGlobalSet ¶ added in v0.12.4
type InstructionGlobalSet struct {
GlobalIndex uint32
}
InstructionGlobalSet is the 'global.set' instruction
type InstructionI32Add ¶
type InstructionI32Add struct{}
InstructionI32Add is the 'i32.add' instruction
type InstructionI32And ¶ added in v0.12.4
type InstructionI32And struct{}
InstructionI32And is the 'i32.and' instruction
type InstructionI32Clz ¶ added in v0.12.4
type InstructionI32Clz struct{}
InstructionI32Clz is the 'i32.clz' instruction
type InstructionI32Const ¶ added in v0.12.4
type InstructionI32Const struct {
Value int32
}
InstructionI32Const is the 'i32.const' instruction
type InstructionI32Ctz ¶ added in v0.12.4
type InstructionI32Ctz struct{}
InstructionI32Ctz is the 'i32.ctz' instruction
type InstructionI32DivS ¶ added in v0.12.4
type InstructionI32DivS struct{}
InstructionI32DivS is the 'i32.div_s' instruction
type InstructionI32DivU ¶ added in v0.12.4
type InstructionI32DivU struct{}
InstructionI32DivU is the 'i32.div_u' instruction
type InstructionI32Eq ¶ added in v0.12.4
type InstructionI32Eq struct{}
InstructionI32Eq is the 'i32.eq' instruction
type InstructionI32Eqz ¶ added in v0.12.4
type InstructionI32Eqz struct{}
InstructionI32Eqz is the 'i32.eqz' instruction
type InstructionI32GeS ¶ added in v0.12.4
type InstructionI32GeS struct{}
InstructionI32GeS is the 'i32.ge_s' instruction
type InstructionI32GeU ¶ added in v0.12.4
type InstructionI32GeU struct{}
InstructionI32GeU is the 'i32.ge_u' instruction
type InstructionI32GtS ¶ added in v0.12.4
type InstructionI32GtS struct{}
InstructionI32GtS is the 'i32.gt_s' instruction
type InstructionI32GtU ¶ added in v0.12.4
type InstructionI32GtU struct{}
InstructionI32GtU is the 'i32.gt_u' instruction
type InstructionI32LeS ¶ added in v0.12.4
type InstructionI32LeS struct{}
InstructionI32LeS is the 'i32.le_s' instruction
type InstructionI32LeU ¶ added in v0.12.4
type InstructionI32LeU struct{}
InstructionI32LeU is the 'i32.le_u' instruction
type InstructionI32LtS ¶ added in v0.12.4
type InstructionI32LtS struct{}
InstructionI32LtS is the 'i32.lt_s' instruction
type InstructionI32LtU ¶ added in v0.12.4
type InstructionI32LtU struct{}
InstructionI32LtU is the 'i32.lt_u' instruction
type InstructionI32Mul ¶ added in v0.12.4
type InstructionI32Mul struct{}
InstructionI32Mul is the 'i32.mul' instruction
type InstructionI32Ne ¶ added in v0.12.4
type InstructionI32Ne struct{}
InstructionI32Ne is the 'i32.ne' instruction
type InstructionI32Or ¶ added in v0.12.4
type InstructionI32Or struct{}
InstructionI32Or is the 'i32.or' instruction
type InstructionI32Popcnt ¶ added in v0.12.4
type InstructionI32Popcnt struct{}
InstructionI32Popcnt is the 'i32.popcnt' instruction
type InstructionI32RemS ¶ added in v0.12.4
type InstructionI32RemS struct{}
InstructionI32RemS is the 'i32.rem_s' instruction
type InstructionI32RemU ¶ added in v0.12.4
type InstructionI32RemU struct{}
InstructionI32RemU is the 'i32.rem_u' instruction
type InstructionI32Rotl ¶ added in v0.12.4
type InstructionI32Rotl struct{}
InstructionI32Rotl is the 'i32.rotl' instruction
type InstructionI32Rotr ¶ added in v0.12.4
type InstructionI32Rotr struct{}
InstructionI32Rotr is the 'i32.rotr' instruction
type InstructionI32Shl ¶ added in v0.12.4
type InstructionI32Shl struct{}
InstructionI32Shl is the 'i32.shl' instruction
type InstructionI32ShrS ¶ added in v0.12.4
type InstructionI32ShrS struct{}
InstructionI32ShrS is the 'i32.shr_s' instruction
type InstructionI32ShrU ¶ added in v0.12.4
type InstructionI32ShrU struct{}
InstructionI32ShrU is the 'i32.shr_u' instruction
type InstructionI32Sub ¶ added in v0.12.4
type InstructionI32Sub struct{}
InstructionI32Sub is the 'i32.sub' instruction
type InstructionI32WrapI64 ¶ added in v0.12.4
type InstructionI32WrapI64 struct{}
InstructionI32WrapI64 is the 'i32.wrap_i64' instruction
type InstructionI32Xor ¶ added in v0.12.4
type InstructionI32Xor struct{}
InstructionI32Xor is the 'i32.xor' instruction
type InstructionI64Add ¶ added in v0.12.4
type InstructionI64Add struct{}
InstructionI64Add is the 'i64.add' instruction
type InstructionI64And ¶ added in v0.12.4
type InstructionI64And struct{}
InstructionI64And is the 'i64.and' instruction
type InstructionI64Clz ¶ added in v0.12.4
type InstructionI64Clz struct{}
InstructionI64Clz is the 'i64.clz' instruction
type InstructionI64Const ¶ added in v0.12.4
type InstructionI64Const struct {
Value int64
}
InstructionI64Const is the 'i64.const' instruction
type InstructionI64Ctz ¶ added in v0.12.4
type InstructionI64Ctz struct{}
InstructionI64Ctz is the 'i64.ctz' instruction
type InstructionI64DivS ¶ added in v0.12.4
type InstructionI64DivS struct{}
InstructionI64DivS is the 'i64.div_s' instruction
type InstructionI64DivU ¶ added in v0.12.4
type InstructionI64DivU struct{}
InstructionI64DivU is the 'i64.div_u' instruction
type InstructionI64Eq ¶ added in v0.12.4
type InstructionI64Eq struct{}
InstructionI64Eq is the 'i64.eq' instruction
type InstructionI64Eqz ¶ added in v0.12.4
type InstructionI64Eqz struct{}
InstructionI64Eqz is the 'i64.eqz' instruction
type InstructionI64ExtendI32S ¶ added in v0.12.4
type InstructionI64ExtendI32S struct{}
InstructionI64ExtendI32S is the 'i64.extend_i32_s' instruction
type InstructionI64ExtendI32U ¶ added in v0.12.4
type InstructionI64ExtendI32U struct{}
InstructionI64ExtendI32U is the 'i64.extend_i32_u' instruction
type InstructionI64GeS ¶ added in v0.12.4
type InstructionI64GeS struct{}
InstructionI64GeS is the 'i64.ge_s' instruction
type InstructionI64GeU ¶ added in v0.12.4
type InstructionI64GeU struct{}
InstructionI64GeU is the 'i64.ge_u' instruction
type InstructionI64GtS ¶ added in v0.12.4
type InstructionI64GtS struct{}
InstructionI64GtS is the 'i64.gt_s' instruction
type InstructionI64GtU ¶ added in v0.12.4
type InstructionI64GtU struct{}
InstructionI64GtU is the 'i64.gt_u' instruction
type InstructionI64LeS ¶ added in v0.12.4
type InstructionI64LeS struct{}
InstructionI64LeS is the 'i64.le_s' instruction
type InstructionI64LeU ¶ added in v0.12.4
type InstructionI64LeU struct{}
InstructionI64LeU is the 'i64.le_u' instruction
type InstructionI64LtS ¶ added in v0.12.4
type InstructionI64LtS struct{}
InstructionI64LtS is the 'i64.lt_s' instruction
type InstructionI64LtU ¶ added in v0.12.4
type InstructionI64LtU struct{}
InstructionI64LtU is the 'i64.lt_u' instruction
type InstructionI64Mul ¶ added in v0.12.4
type InstructionI64Mul struct{}
InstructionI64Mul is the 'i64.mul' instruction
type InstructionI64Ne ¶ added in v0.12.4
type InstructionI64Ne struct{}
InstructionI64Ne is the 'i64.ne' instruction
type InstructionI64Or ¶ added in v0.12.4
type InstructionI64Or struct{}
InstructionI64Or is the 'i64.or' instruction
type InstructionI64Popcnt ¶ added in v0.12.4
type InstructionI64Popcnt struct{}
InstructionI64Popcnt is the 'i64.popcnt' instruction
type InstructionI64RemS ¶ added in v0.12.4
type InstructionI64RemS struct{}
InstructionI64RemS is the 'i64.rem_s' instruction
type InstructionI64RemU ¶ added in v0.12.4
type InstructionI64RemU struct{}
InstructionI64RemU is the 'i64.rem_u' instruction
type InstructionI64Rotl ¶ added in v0.12.4
type InstructionI64Rotl struct{}
InstructionI64Rotl is the 'i64.rotl' instruction
type InstructionI64Rotr ¶ added in v0.12.4
type InstructionI64Rotr struct{}
InstructionI64Rotr is the 'i64.rotr' instruction
type InstructionI64Shl ¶ added in v0.12.4
type InstructionI64Shl struct{}
InstructionI64Shl is the 'i64.shl' instruction
type InstructionI64ShrS ¶ added in v0.12.4
type InstructionI64ShrS struct{}
InstructionI64ShrS is the 'i64.shr_s' instruction
type InstructionI64ShrU ¶ added in v0.12.4
type InstructionI64ShrU struct{}
InstructionI64ShrU is the 'i64.shr_u' instruction
type InstructionI64Sub ¶ added in v0.12.4
type InstructionI64Sub struct{}
InstructionI64Sub is the 'i64.sub' instruction
type InstructionI64Xor ¶ added in v0.12.4
type InstructionI64Xor struct{}
InstructionI64Xor is the 'i64.xor' instruction
type InstructionIf ¶ added in v0.12.4
type InstructionIf struct {
Block Block
}
InstructionIf is the 'if' instruction
type InstructionLocalGet ¶
type InstructionLocalGet struct {
LocalIndex uint32
}
InstructionLocalGet is the 'local.get' instruction
type InstructionLocalSet ¶ added in v0.12.4
type InstructionLocalSet struct {
LocalIndex uint32
}
InstructionLocalSet is the 'local.set' instruction
type InstructionLocalTee ¶ added in v0.12.4
type InstructionLocalTee struct {
LocalIndex uint32
}
InstructionLocalTee is the 'local.tee' instruction
type InstructionLoop ¶ added in v0.12.4
type InstructionLoop struct {
Block Block
}
InstructionLoop is the 'loop' instruction
type InstructionNop ¶ added in v0.12.4
type InstructionNop struct{}
InstructionNop is the 'nop' instruction
type InstructionRefFunc ¶ added in v0.12.4
type InstructionRefFunc struct {
FuncIndex uint32
}
InstructionRefFunc is the 'ref.func' instruction
type InstructionRefIsNull ¶ added in v0.12.4
type InstructionRefIsNull struct{}
InstructionRefIsNull is the 'ref.is_null' instruction
type InstructionRefNull ¶ added in v0.12.4
type InstructionRefNull struct {
TypeIndex uint32
}
InstructionRefNull is the 'ref.null' instruction
type InstructionReturn ¶ added in v0.12.4
type InstructionReturn struct{}
InstructionReturn is the 'return' instruction
type InstructionSelect ¶ added in v0.12.4
type InstructionSelect struct{}
InstructionSelect is the 'select' instruction
type InstructionUnreachable ¶ added in v0.12.4
type InstructionUnreachable struct{}
InstructionUnreachable is the 'unreachable' instruction
type InvalidBlockSecondInstructionsError ¶ added in v0.12.4
type InvalidBlockSecondInstructionsError struct {
Offset int
}
InvalidBlockSecondInstructionsError is returned when the WASM binary specifies or the writer is given a second set of instructions in a block that is not allowed to have it (only the 'if' instruction may have it)
func (InvalidBlockSecondInstructionsError) Error ¶ added in v0.12.4
func (e InvalidBlockSecondInstructionsError) Error() string
type InvalidBlockTypeTypeIndexError ¶ added in v0.12.4
InvalidBlockTypeTypeIndexError is returned when the WASM binary specifies an invalid type index as a block type
func (InvalidBlockTypeTypeIndexError) Error ¶ added in v0.12.4
func (e InvalidBlockTypeTypeIndexError) Error() string
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 InvalidDataSectionInitByteCountError ¶ added in v0.12.5
InvalidDataSectionInitByteCountError is returned when the WASM binary specifies an invalid init byte count in the data section
func (InvalidDataSectionInitByteCountError) Error ¶ added in v0.12.5
func (e InvalidDataSectionInitByteCountError) Error() string
func (InvalidDataSectionInitByteCountError) Unwrap ¶ added in v0.12.5
func (e InvalidDataSectionInitByteCountError) Unwrap() error
type InvalidDataSectionMemoryIndexError ¶ added in v0.12.5
InvalidDataSectionMemoryIndexError is returned when the WASM binary specifies an invalid memory index in the data section
func (InvalidDataSectionMemoryIndexError) Error ¶ added in v0.12.5
func (e InvalidDataSectionMemoryIndexError) Error() string
func (InvalidDataSectionMemoryIndexError) Unwrap ¶ added in v0.12.5
func (e InvalidDataSectionMemoryIndexError) Unwrap() error
type InvalidDataSectionSegmentCountError ¶ added in v0.12.5
InvalidDataSectionSegmentCountError is returned when the WASM binary specifies an invalid count in the data section
func (InvalidDataSectionSegmentCountError) Error ¶ added in v0.12.5
func (e InvalidDataSectionSegmentCountError) Error() string
func (InvalidDataSectionSegmentCountError) Unwrap ¶ added in v0.12.5
func (e InvalidDataSectionSegmentCountError) Unwrap() error
type InvalidDataSegmentError ¶ added in v0.12.5
InvalidDataSegmentError is returned when the WASM binary specifies invalid segment in the data section
func (InvalidDataSegmentError) Error ¶ added in v0.12.5
func (e InvalidDataSegmentError) Error() string
func (InvalidDataSegmentError) Unwrap ¶ added in v0.12.5
func (e InvalidDataSegmentError) Unwrap() error
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 InvalidExportError ¶ added in v0.12.4
InvalidExportError is returned when the WASM binary specifies invalid export in the export section
func (InvalidExportError) Error ¶ added in v0.12.4
func (e InvalidExportError) Error() string
func (InvalidExportError) Unwrap ¶ added in v0.12.4
func (e InvalidExportError) Unwrap() error
type InvalidExportIndicatorError ¶ added in v0.12.4
type InvalidExportIndicatorError struct { ReadError error Offset int ExportIndicator exportIndicator }
InvalidExportIndicatorError is returned when the WASM binary specifies an invalid type indicator in the export section
func (InvalidExportIndicatorError) Error ¶ added in v0.12.4
func (e InvalidExportIndicatorError) Error() string
func (InvalidExportIndicatorError) Unwrap ¶ added in v0.12.4
func (e InvalidExportIndicatorError) Unwrap() error
type InvalidExportSectionExportCountError ¶ added in v0.12.4
InvalidExportSectionExportCountError is returned when the WASM binary specifies an invalid count in the export section
func (InvalidExportSectionExportCountError) Error ¶ added in v0.12.4
func (e InvalidExportSectionExportCountError) Error() string
func (InvalidExportSectionExportCountError) Unwrap ¶ added in v0.12.4
func (e InvalidExportSectionExportCountError) Unwrap() error
type InvalidExportSectionIndexError ¶ added in v0.12.7
InvalidExportSectionIndexError is returned when the WASM binary specifies an invalid index in the export section
func (InvalidExportSectionIndexError) Error ¶ added in v0.12.7
func (e InvalidExportSectionIndexError) Error() string
func (InvalidExportSectionIndexError) Unwrap ¶ added in v0.12.7
func (e InvalidExportSectionIndexError) Unwrap() error
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 InvalidFunctionSectionTypeIndexError ¶ added in v0.12.4
InvalidFunctionSectionTypeIndexError is returned when the WASM binary specifies an invalid type index in the function section
func (InvalidFunctionSectionTypeIndexError) Error ¶ added in v0.12.4
func (e InvalidFunctionSectionTypeIndexError) Error() string
func (InvalidFunctionSectionTypeIndexError) Unwrap ¶ added in v0.12.4
func (e InvalidFunctionSectionTypeIndexError) 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 InvalidImportIndicatorError ¶ added in v0.12.4
type InvalidImportIndicatorError struct { ReadError error Offset int ImportIndicator importIndicator }
InvalidImportIndicatorError is returned when the WASM binary specifies an invalid type indicator in the import section
func (InvalidImportIndicatorError) Error ¶ added in v0.12.4
func (e InvalidImportIndicatorError) Error() string
func (InvalidImportIndicatorError) Unwrap ¶ added in v0.12.4
func (e InvalidImportIndicatorError) 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 InvalidImportSectionTypeIndexError ¶ added in v0.12.4
InvalidImportSectionTypeIndexError is returned when the WASM binary specifies an invalid type index in the import section
func (InvalidImportSectionTypeIndexError) Error ¶ added in v0.12.4
func (e InvalidImportSectionTypeIndexError) Error() string
func (InvalidImportSectionTypeIndexError) Unwrap ¶ added in v0.12.4
func (e InvalidImportSectionTypeIndexError) 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 InvalidInstructionVectorArgumentCountError ¶ added in v0.12.4
InvalidInstructionVectorArgumentCountError is returned when the WASM binary specifies an invalid count for a vector argument of an instruction
func (InvalidInstructionVectorArgumentCountError) Error ¶ added in v0.12.4
func (e InvalidInstructionVectorArgumentCountError) Error() string
func (InvalidInstructionVectorArgumentCountError) Unwrap ¶ added in v0.12.4
func (e InvalidInstructionVectorArgumentCountError) Unwrap() error
type InvalidLimitIndicatorError ¶ added in v0.12.5
InvalidLimitIndicatorError is returned when the WASM binary specifies an invalid limit indicator
func (InvalidLimitIndicatorError) Error ¶ added in v0.12.5
func (e InvalidLimitIndicatorError) Error() string
func (InvalidLimitIndicatorError) Unwrap ¶ added in v0.12.5
func (e InvalidLimitIndicatorError) Unwrap() error
type InvalidLimitMaxError ¶ added in v0.12.5
InvalidLimitMaxError is returned when the WASM binary specifies an invalid limit maximum
func (InvalidLimitMaxError) Error ¶ added in v0.12.5
func (e InvalidLimitMaxError) Error() string
func (InvalidLimitMaxError) Unwrap ¶ added in v0.12.5
func (e InvalidLimitMaxError) Unwrap() error
type InvalidLimitMinError ¶ added in v0.12.5
InvalidLimitMinError is returned when the WASM binary specifies an invalid limit minimum
func (InvalidLimitMinError) Error ¶ added in v0.12.5
func (e InvalidLimitMinError) Error() string
func (InvalidLimitMinError) Unwrap ¶ added in v0.12.5
func (e InvalidLimitMinError) 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 InvalidMemoryError ¶ added in v0.12.5
InvalidMemoryError is returned when the WASM binary specifies invalid memory in the memory section
func (InvalidMemoryError) Error ¶ added in v0.12.5
func (e InvalidMemoryError) Error() string
func (InvalidMemoryError) Unwrap ¶ added in v0.12.5
func (e InvalidMemoryError) Unwrap() error
type InvalidMemorySectionMemoryCountError ¶ added in v0.12.5
InvalidMemorySectionMemoryCountError is returned when the WASM binary specifies an invalid count in the memory section
func (InvalidMemorySectionMemoryCountError) Error ¶ added in v0.12.5
func (e InvalidMemorySectionMemoryCountError) Error() string
func (InvalidMemorySectionMemoryCountError) Unwrap ¶ added in v0.12.5
func (e InvalidMemorySectionMemoryCountError) 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 InvalidSectionOrderError ¶ added in v0.12.4
type InvalidSectionOrderError struct { Offset int SectionID sectionID }
InvalidSectionOrderError is returned when the WASM binary specifies a non-custom section out-of-order
func (InvalidSectionOrderError) Error ¶ added in v0.12.4
func (e InvalidSectionOrderError) Error() string
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 InvalidStartSectionFunctionIndexError ¶ added in v0.12.7
InvalidStartSectionFunctionIndexError is returned when the WASM binary specifies an invalid function index in the start section
func (InvalidStartSectionFunctionIndexError) Error ¶ added in v0.12.7
func (e InvalidStartSectionFunctionIndexError) Error() string
func (InvalidStartSectionFunctionIndexError) Unwrap ¶ added in v0.12.7
func (e InvalidStartSectionFunctionIndexError) 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 Memory ¶ added in v0.12.5
type Memory struct { // maximum number of pages (each one is 64KiB in size). optional, unlimited if nil Max *uint32 // minimum number of pages (each one is 64KiB in size) Min uint32 }
Memory represents a memory
type MemoryExport ¶ added in v0.12.7
type MemoryExport struct {
MemoryIndex uint32
}
MemoryExport represents the export of a memory
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 { Name string Types []*FunctionType Imports []*Import Functions []*Function Memories []*Memory Exports []*Export StartFunctionIndex *uint32 Data []*Data }
Module represents a module
type ModuleBuilder ¶ added in v0.12.4
type ModuleBuilder struct {
// contains filtered or unexported fields
}
ModuleBuilder allows building modules
func (*ModuleBuilder) AddData ¶ added in v0.13.0
func (b *ModuleBuilder) AddData(offset uint32, value []byte)
func (*ModuleBuilder) AddExport ¶ added in v0.13.0
func (b *ModuleBuilder) AddExport(export *Export)
func (*ModuleBuilder) AddFunction ¶ added in v0.12.4
func (b *ModuleBuilder) AddFunction(name string, functionType *FunctionType, code *Code) uint32
func (*ModuleBuilder) AddFunctionImport ¶ added in v0.13.0
func (b *ModuleBuilder) AddFunctionImport(module string, name string, functionType *FunctionType) (uint32, error)
func (*ModuleBuilder) Build ¶ added in v0.12.4
func (b *ModuleBuilder) Build() *Module
func (*ModuleBuilder) ExportMemory ¶ added in v0.13.0
func (b *ModuleBuilder) ExportMemory(name string)
func (*ModuleBuilder) RequireMemory ¶ added in v0.13.0
func (b *ModuleBuilder) RequireMemory(size uint32) uint32
type TypeIndexBlockType ¶ added in v0.12.4
type TypeIndexBlockType struct {
TypeIndex uint32
}
type ValueType ¶
type ValueType byte
ValueType is the type of a value
const ( // ValueTypeI32 is the `i32` type, // the type of 32 bit integers. // The value is the byte used in the WASM binary ValueTypeI32 ValueType = 0x7F // ValueTypeI64 is the `i64` type, // the type of 64 bit integers. // The value is the byte used in the WASM binary ValueTypeI64 ValueType = 0x7E // ValueTypeFuncRef is the `funcref` type, // the type of first-class references to functions. // The value is the byte used in the WASM binary ValueTypeFuncRef ValueType = 0x70 // ValueTypeExternRef is the `funcref` type, // the type of first-class references to objects owned by the embedder. // The value is the byte used in the WASM binary ValueTypeExternRef ValueType = 0x6F )
func AsValueType ¶ added in v0.12.4
AsValueType returns the value type for the given byte, or 0 if the byte is not a valid value type
type WASMReader ¶
type WASMReader struct { Module Module // contains filtered or unexported fields }
WASMReader allows reading WASM binaries
func NewWASMReader ¶ added in v0.12.4
func NewWASMReader(buf *Buffer) *WASMReader
func (*WASMReader) ReadModule ¶ added in v0.12.4
func (r *WASMReader) ReadModule() error
type WASMWriter ¶
type WASMWriter struct { WriteNames bool // contains filtered or unexported fields }
WASMWriter allows writing WASM binaries
func NewWASMWriter ¶ added in v0.12.4
func NewWASMWriter(buf *Buffer) *WASMWriter
func (*WASMWriter) WriteModule ¶ added in v0.12.4
func (w *WASMWriter) WriteModule(module *Module) error