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 ¶
type Block struct { BlockType BlockType Instructions1 []Instruction Instructions2 []Instruction }
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a byte buffer, which allows reading and writing.
func (*Buffer) WriteBytes ¶
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 ¶
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 ¶
type Export struct { Descriptor ExportDescriptor Name string }
Exports represents an export
type ExportDescriptor ¶
type ExportDescriptor interface {
// contains filtered or unexported methods
}
ExportDescriptor represents an export (e.g. a function, memory, etc.)
type FunctionCountMismatchError ¶
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 ¶
func (e FunctionCountMismatchError) Error() string
type FunctionExport ¶
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 ¶
type InstructionBlock struct {
Block Block
}
InstructionBlock is the 'block' instruction
type InstructionBr ¶
type InstructionBr struct {
LabelIndex uint32
}
InstructionBr is the 'br' instruction
type InstructionBrIf ¶
type InstructionBrIf struct {
LabelIndex uint32
}
InstructionBrIf is the 'br_if' instruction
type InstructionBrTable ¶
InstructionBrTable is the 'br_table' instruction
type InstructionCall ¶
type InstructionCall struct {
FuncIndex uint32
}
InstructionCall is the 'call' instruction
type InstructionCallIndirect ¶
InstructionCallIndirect is the 'call_indirect' instruction
type InstructionGlobalGet ¶
type InstructionGlobalGet struct {
GlobalIndex uint32
}
InstructionGlobalGet is the 'global.get' instruction
type InstructionGlobalSet ¶
type InstructionGlobalSet struct {
GlobalIndex uint32
}
InstructionGlobalSet is the 'global.set' instruction
type InstructionI32Add ¶
type InstructionI32Add struct{}
InstructionI32Add is the 'i32.add' instruction
type InstructionI32And ¶
type InstructionI32And struct{}
InstructionI32And is the 'i32.and' instruction
type InstructionI32Clz ¶
type InstructionI32Clz struct{}
InstructionI32Clz is the 'i32.clz' instruction
type InstructionI32Const ¶
type InstructionI32Const struct {
Value int32
}
InstructionI32Const is the 'i32.const' instruction
type InstructionI32Ctz ¶
type InstructionI32Ctz struct{}
InstructionI32Ctz is the 'i32.ctz' instruction
type InstructionI32DivS ¶
type InstructionI32DivS struct{}
InstructionI32DivS is the 'i32.div_s' instruction
type InstructionI32DivU ¶
type InstructionI32DivU struct{}
InstructionI32DivU is the 'i32.div_u' instruction
type InstructionI32Eqz ¶
type InstructionI32Eqz struct{}
InstructionI32Eqz is the 'i32.eqz' instruction
type InstructionI32GeS ¶
type InstructionI32GeS struct{}
InstructionI32GeS is the 'i32.ge_s' instruction
type InstructionI32GeU ¶
type InstructionI32GeU struct{}
InstructionI32GeU is the 'i32.ge_u' instruction
type InstructionI32GtS ¶
type InstructionI32GtS struct{}
InstructionI32GtS is the 'i32.gt_s' instruction
type InstructionI32GtU ¶
type InstructionI32GtU struct{}
InstructionI32GtU is the 'i32.gt_u' instruction
type InstructionI32LeS ¶
type InstructionI32LeS struct{}
InstructionI32LeS is the 'i32.le_s' instruction
type InstructionI32LeU ¶
type InstructionI32LeU struct{}
InstructionI32LeU is the 'i32.le_u' instruction
type InstructionI32LtS ¶
type InstructionI32LtS struct{}
InstructionI32LtS is the 'i32.lt_s' instruction
type InstructionI32LtU ¶
type InstructionI32LtU struct{}
InstructionI32LtU is the 'i32.lt_u' instruction
type InstructionI32Mul ¶
type InstructionI32Mul struct{}
InstructionI32Mul is the 'i32.mul' instruction
type InstructionI32Popcnt ¶
type InstructionI32Popcnt struct{}
InstructionI32Popcnt is the 'i32.popcnt' instruction
type InstructionI32RemS ¶
type InstructionI32RemS struct{}
InstructionI32RemS is the 'i32.rem_s' instruction
type InstructionI32RemU ¶
type InstructionI32RemU struct{}
InstructionI32RemU is the 'i32.rem_u' instruction
type InstructionI32Rotl ¶
type InstructionI32Rotl struct{}
InstructionI32Rotl is the 'i32.rotl' instruction
type InstructionI32Rotr ¶
type InstructionI32Rotr struct{}
InstructionI32Rotr is the 'i32.rotr' instruction
type InstructionI32Shl ¶
type InstructionI32Shl struct{}
InstructionI32Shl is the 'i32.shl' instruction
type InstructionI32ShrS ¶
type InstructionI32ShrS struct{}
InstructionI32ShrS is the 'i32.shr_s' instruction
type InstructionI32ShrU ¶
type InstructionI32ShrU struct{}
InstructionI32ShrU is the 'i32.shr_u' instruction
type InstructionI32Sub ¶
type InstructionI32Sub struct{}
InstructionI32Sub is the 'i32.sub' instruction
type InstructionI32WrapI64 ¶
type InstructionI32WrapI64 struct{}
InstructionI32WrapI64 is the 'i32.wrap_i64' instruction
type InstructionI32Xor ¶
type InstructionI32Xor struct{}
InstructionI32Xor is the 'i32.xor' instruction
type InstructionI64Add ¶
type InstructionI64Add struct{}
InstructionI64Add is the 'i64.add' instruction
type InstructionI64And ¶
type InstructionI64And struct{}
InstructionI64And is the 'i64.and' instruction
type InstructionI64Clz ¶
type InstructionI64Clz struct{}
InstructionI64Clz is the 'i64.clz' instruction
type InstructionI64Const ¶
type InstructionI64Const struct {
Value int64
}
InstructionI64Const is the 'i64.const' instruction
type InstructionI64Ctz ¶
type InstructionI64Ctz struct{}
InstructionI64Ctz is the 'i64.ctz' instruction
type InstructionI64DivS ¶
type InstructionI64DivS struct{}
InstructionI64DivS is the 'i64.div_s' instruction
type InstructionI64DivU ¶
type InstructionI64DivU struct{}
InstructionI64DivU is the 'i64.div_u' instruction
type InstructionI64Eqz ¶
type InstructionI64Eqz struct{}
InstructionI64Eqz is the 'i64.eqz' instruction
type InstructionI64ExtendI32S ¶
type InstructionI64ExtendI32S struct{}
InstructionI64ExtendI32S is the 'i64.extend_i32_s' instruction
type InstructionI64ExtendI32U ¶
type InstructionI64ExtendI32U struct{}
InstructionI64ExtendI32U is the 'i64.extend_i32_u' instruction
type InstructionI64GeS ¶
type InstructionI64GeS struct{}
InstructionI64GeS is the 'i64.ge_s' instruction
type InstructionI64GeU ¶
type InstructionI64GeU struct{}
InstructionI64GeU is the 'i64.ge_u' instruction
type InstructionI64GtS ¶
type InstructionI64GtS struct{}
InstructionI64GtS is the 'i64.gt_s' instruction
type InstructionI64GtU ¶
type InstructionI64GtU struct{}
InstructionI64GtU is the 'i64.gt_u' instruction
type InstructionI64LeS ¶
type InstructionI64LeS struct{}
InstructionI64LeS is the 'i64.le_s' instruction
type InstructionI64LeU ¶
type InstructionI64LeU struct{}
InstructionI64LeU is the 'i64.le_u' instruction
type InstructionI64LtS ¶
type InstructionI64LtS struct{}
InstructionI64LtS is the 'i64.lt_s' instruction
type InstructionI64LtU ¶
type InstructionI64LtU struct{}
InstructionI64LtU is the 'i64.lt_u' instruction
type InstructionI64Mul ¶
type InstructionI64Mul struct{}
InstructionI64Mul is the 'i64.mul' instruction
type InstructionI64Popcnt ¶
type InstructionI64Popcnt struct{}
InstructionI64Popcnt is the 'i64.popcnt' instruction
type InstructionI64RemS ¶
type InstructionI64RemS struct{}
InstructionI64RemS is the 'i64.rem_s' instruction
type InstructionI64RemU ¶
type InstructionI64RemU struct{}
InstructionI64RemU is the 'i64.rem_u' instruction
type InstructionI64Rotl ¶
type InstructionI64Rotl struct{}
InstructionI64Rotl is the 'i64.rotl' instruction
type InstructionI64Rotr ¶
type InstructionI64Rotr struct{}
InstructionI64Rotr is the 'i64.rotr' instruction
type InstructionI64Shl ¶
type InstructionI64Shl struct{}
InstructionI64Shl is the 'i64.shl' instruction
type InstructionI64ShrS ¶
type InstructionI64ShrS struct{}
InstructionI64ShrS is the 'i64.shr_s' instruction
type InstructionI64ShrU ¶
type InstructionI64ShrU struct{}
InstructionI64ShrU is the 'i64.shr_u' instruction
type InstructionI64Sub ¶
type InstructionI64Sub struct{}
InstructionI64Sub is the 'i64.sub' instruction
type InstructionI64Xor ¶
type InstructionI64Xor struct{}
InstructionI64Xor is the 'i64.xor' instruction
type InstructionIf ¶
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 ¶
type InstructionLocalSet struct {
LocalIndex uint32
}
InstructionLocalSet is the 'local.set' instruction
type InstructionLocalTee ¶
type InstructionLocalTee struct {
LocalIndex uint32
}
InstructionLocalTee is the 'local.tee' instruction
type InstructionLoop ¶
type InstructionLoop struct {
Block Block
}
InstructionLoop is the 'loop' instruction
type InstructionRefFunc ¶
type InstructionRefFunc struct {
FuncIndex uint32
}
InstructionRefFunc is the 'ref.func' instruction
type InstructionRefIsNull ¶
type InstructionRefIsNull struct{}
InstructionRefIsNull is the 'ref.is_null' instruction
type InstructionRefNull ¶
type InstructionRefNull struct {
TypeIndex uint32
}
InstructionRefNull is the 'ref.null' instruction
type InstructionReturn ¶
type InstructionReturn struct{}
InstructionReturn is the 'return' instruction
type InstructionSelect ¶
type InstructionSelect struct{}
InstructionSelect is the 'select' instruction
type InstructionUnreachable ¶
type InstructionUnreachable struct{}
InstructionUnreachable is the 'unreachable' instruction
type InvalidBlockSecondInstructionsError ¶
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 ¶
func (e InvalidBlockSecondInstructionsError) Error() string
type InvalidBlockTypeTypeIndexError ¶
InvalidBlockTypeTypeIndexError is returned when the WASM binary specifies an invalid type index as a block type
func (InvalidBlockTypeTypeIndexError) Error ¶
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 ¶
InvalidDataSectionInitByteCountError is returned when the WASM binary specifies an invalid init byte count in the data section
func (InvalidDataSectionInitByteCountError) Error ¶
func (e InvalidDataSectionInitByteCountError) Error() string
func (InvalidDataSectionInitByteCountError) Unwrap ¶
func (e InvalidDataSectionInitByteCountError) Unwrap() error
type InvalidDataSectionMemoryIndexError ¶
InvalidDataSectionMemoryIndexError is returned when the WASM binary specifies an invalid memory index in the data section
func (InvalidDataSectionMemoryIndexError) Error ¶
func (e InvalidDataSectionMemoryIndexError) Error() string
func (InvalidDataSectionMemoryIndexError) Unwrap ¶
func (e InvalidDataSectionMemoryIndexError) Unwrap() error
type InvalidDataSectionSegmentCountError ¶
InvalidDataSectionSegmentCountError is returned when the WASM binary specifies an invalid count in the data section
func (InvalidDataSectionSegmentCountError) Error ¶
func (e InvalidDataSectionSegmentCountError) Error() string
func (InvalidDataSectionSegmentCountError) Unwrap ¶
func (e InvalidDataSectionSegmentCountError) Unwrap() error
type InvalidDataSegmentError ¶
InvalidDataSegmentError is returned when the WASM binary specifies invalid segment in the data section
func (InvalidDataSegmentError) Error ¶
func (e InvalidDataSegmentError) Error() string
func (InvalidDataSegmentError) Unwrap ¶
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 ¶
InvalidExportError is returned when the WASM binary specifies invalid export in the export section
func (InvalidExportError) Error ¶
func (e InvalidExportError) Error() string
func (InvalidExportError) Unwrap ¶
func (e InvalidExportError) Unwrap() error
type InvalidExportIndicatorError ¶
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 ¶
func (e InvalidExportIndicatorError) Error() string
func (InvalidExportIndicatorError) Unwrap ¶
func (e InvalidExportIndicatorError) Unwrap() error
type InvalidExportSectionExportCountError ¶
InvalidExportSectionExportCountError is returned when the WASM binary specifies an invalid count in the export section
func (InvalidExportSectionExportCountError) Error ¶
func (e InvalidExportSectionExportCountError) Error() string
func (InvalidExportSectionExportCountError) Unwrap ¶
func (e InvalidExportSectionExportCountError) Unwrap() error
type InvalidExportSectionIndexError ¶
InvalidExportSectionIndexError is returned when the WASM binary specifies an invalid index in the export section
func (InvalidExportSectionIndexError) Error ¶
func (e InvalidExportSectionIndexError) Error() string
func (InvalidExportSectionIndexError) Unwrap ¶
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 ¶
InvalidFunctionSectionTypeIndexError is returned when the WASM binary specifies an invalid type index in the function section
func (InvalidFunctionSectionTypeIndexError) Error ¶
func (e InvalidFunctionSectionTypeIndexError) Error() string
func (InvalidFunctionSectionTypeIndexError) Unwrap ¶
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 ¶
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 ¶
func (e InvalidImportIndicatorError) Error() string
func (InvalidImportIndicatorError) Unwrap ¶
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 ¶
InvalidImportSectionTypeIndexError is returned when the WASM binary specifies an invalid type index in the import section
func (InvalidImportSectionTypeIndexError) Error ¶
func (e InvalidImportSectionTypeIndexError) Error() string
func (InvalidImportSectionTypeIndexError) Unwrap ¶
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 ¶
InvalidInstructionVectorArgumentCountError is returned when the WASM binary specifies an invalid count for a vector argument of an instruction
func (InvalidInstructionVectorArgumentCountError) Error ¶
func (e InvalidInstructionVectorArgumentCountError) Error() string
func (InvalidInstructionVectorArgumentCountError) Unwrap ¶
func (e InvalidInstructionVectorArgumentCountError) Unwrap() error
type InvalidLimitIndicatorError ¶
InvalidLimitIndicatorError is returned when the WASM binary specifies an invalid limit indicator
func (InvalidLimitIndicatorError) Error ¶
func (e InvalidLimitIndicatorError) Error() string
func (InvalidLimitIndicatorError) Unwrap ¶
func (e InvalidLimitIndicatorError) Unwrap() error
type InvalidLimitMaxError ¶
InvalidLimitMaxError is returned when the WASM binary specifies an invalid limit maximum
func (InvalidLimitMaxError) Error ¶
func (e InvalidLimitMaxError) Error() string
func (InvalidLimitMaxError) Unwrap ¶
func (e InvalidLimitMaxError) Unwrap() error
type InvalidLimitMinError ¶
InvalidLimitMinError is returned when the WASM binary specifies an invalid limit minimum
func (InvalidLimitMinError) Error ¶
func (e InvalidLimitMinError) Error() string
func (InvalidLimitMinError) Unwrap ¶
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 ¶
InvalidMemoryError is returned when the WASM binary specifies invalid memory in the memory section
func (InvalidMemoryError) Error ¶
func (e InvalidMemoryError) Error() string
func (InvalidMemoryError) Unwrap ¶
func (e InvalidMemoryError) Unwrap() error
type InvalidMemorySectionMemoryCountError ¶
InvalidMemorySectionMemoryCountError is returned when the WASM binary specifies an invalid count in the memory section
func (InvalidMemorySectionMemoryCountError) Error ¶
func (e InvalidMemorySectionMemoryCountError) Error() string
func (InvalidMemorySectionMemoryCountError) Unwrap ¶
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 ¶
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 ¶
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 ¶
InvalidStartSectionFunctionIndexError is returned when the WASM binary specifies an invalid function index in the start section
func (InvalidStartSectionFunctionIndexError) Error ¶
func (e InvalidStartSectionFunctionIndexError) Error() string
func (InvalidStartSectionFunctionIndexError) Unwrap ¶
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 ¶
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 ¶
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 ¶
type ModuleBuilder struct {
// contains filtered or unexported fields
}
ModuleBuilder allows building modules
func (*ModuleBuilder) AddData ¶
func (b *ModuleBuilder) AddData(offset uint32, value []byte)
func (*ModuleBuilder) AddExport ¶
func (b *ModuleBuilder) AddExport(export *Export)
func (*ModuleBuilder) AddFunction ¶
func (b *ModuleBuilder) AddFunction(name string, functionType *FunctionType, code *Code) uint32
func (*ModuleBuilder) AddFunctionImport ¶
func (b *ModuleBuilder) AddFunctionImport(module string, name string, functionType *FunctionType) (uint32, error)
func (*ModuleBuilder) Build ¶
func (b *ModuleBuilder) Build() *Module
func (*ModuleBuilder) ExportMemory ¶
func (b *ModuleBuilder) ExportMemory(name string)
func (*ModuleBuilder) RequireMemory ¶
func (b *ModuleBuilder) RequireMemory(size uint32) uint32
type TypeIndexBlockType ¶
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 ¶
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 ¶
func NewWASMReader(buf *Buffer) *WASMReader
func (*WASMReader) ReadModule ¶
func (r *WASMReader) ReadModule() error
type WASMWriter ¶
type WASMWriter struct { WriteNames bool // contains filtered or unexported fields }
WASMWriter allows writing WASM binaries
func NewWASMWriter ¶
func NewWASMWriter(buf *Buffer) *WASMWriter
func (*WASMWriter) WriteModule ¶
func (w *WASMWriter) WriteModule(module *Module) error