wasm

package
v0.42.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

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

View Source
const MemoryPageSize = 64 * 1024

MemoryPageSize is the size of a memory page: 64KiB

Variables

This section is empty.

Functions

func WASM2WAT added in v0.13.0

func WASM2WAT(binary []byte) string

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) Bytes added in v0.12.4

func (buf *Buffer) Bytes() []byte

func (*Buffer) PeekByte added in v0.12.4

func (buf *Buffer) PeekByte() (byte, error)

func (*Buffer) Read added in v0.12.4

func (buf *Buffer) Read(data []byte) (int, error)

func (*Buffer) ReadByte added in v0.12.4

func (buf *Buffer) ReadByte() (byte, error)

func (*Buffer) ReadBytesEqual added in v0.12.4

func (buf *Buffer) ReadBytesEqual(expected []byte) (bool, error)

func (*Buffer) WriteByte added in v0.12.4

func (buf *Buffer) WriteByte(b byte) error

func (*Buffer) WriteBytes added in v0.12.4

func (buf *Buffer) WriteBytes(data []byte) error

type Code

type Code struct {
	Locals       []ValueType
	Instructions []Instruction
}

Code represents the code of a function

type CodeSectionLocalsCountMismatchError

type CodeSectionLocalsCountMismatchError struct {
	Offset   int
	Expected uint32
	Actual   uint32
}

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

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 Function

type Function struct {
	Code      *Code
	Name      string
	TypeIndex uint32
}

Function represents a function

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

type FunctionExport added in v0.12.7

type FunctionExport struct {
	FunctionIndex uint32
}

FunctionExport represents the export of a function

type FunctionType

type FunctionType struct {
	Params  []ValueType
	Results []ValueType
}

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

func (Import) FullName added in v0.12.4

func (imp Import) FullName() string

type IncompleteNameError

type IncompleteNameError struct {
	Offset   int
	Expected uint32
	Actual   uint32
}

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

type InstructionBrTable struct {
	LabelIndices      []uint32
	DefaultLabelIndex uint32
}

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

type InstructionCallIndirect struct {
	TypeIndex  uint32
	TableIndex uint32
}

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

type InvalidBlockTypeTypeIndexError added in v0.12.4

type InvalidBlockTypeTypeIndexError struct {
	TypeIndex int64
	Offset    int
}

InvalidBlockTypeTypeIndexError is returned when the WASM binary specifies an invalid type index as a block type

func (InvalidBlockTypeTypeIndexError) Error added in v0.12.4

type InvalidCodeSectionCompressedLocalsCountError

type InvalidCodeSectionCompressedLocalsCountError struct {
	ReadError error
	Offset    int
}

InvalidCodeSectionCompressedLocalsCountError is returned when the WASM binary specifies an invalid local type in the code section

func (InvalidCodeSectionCompressedLocalsCountError) Error

func (InvalidCodeSectionCompressedLocalsCountError) Unwrap

type InvalidCodeSectionFunctionCountError

type InvalidCodeSectionFunctionCountError struct {
	ReadError error
	Offset    int
}

InvalidCodeSectionFunctionCountError is returned when the WASM binary specifies an invalid function count in the code section

func (InvalidCodeSectionFunctionCountError) Error

func (InvalidCodeSectionFunctionCountError) Unwrap

type InvalidCodeSectionLocalTypeError

type InvalidCodeSectionLocalTypeError struct {
	ReadError error
	Offset    int
}

InvalidCodeSectionLocalTypeError is returned when the WASM binary specifies an invalid local type in the code section

func (InvalidCodeSectionLocalTypeError) Error

func (InvalidCodeSectionLocalTypeError) Unwrap

type InvalidCodeSectionLocalsCountError

type InvalidCodeSectionLocalsCountError struct {
	ReadError error
	Offset    int
}

InvalidCodeSectionLocalsCountError is returned when the WASM binary specifies an invalid locals count in the code section

func (InvalidCodeSectionLocalsCountError) Error

func (InvalidCodeSectionLocalsCountError) Unwrap

type InvalidCodeSizeError

type InvalidCodeSizeError struct {
	ReadError error
	Offset    int
}

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

type InvalidDataSectionInitByteCountError struct {
	ReadError error
	Offset    int
}

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 (InvalidDataSectionInitByteCountError) Unwrap added in v0.12.5

type InvalidDataSectionMemoryIndexError added in v0.12.5

type InvalidDataSectionMemoryIndexError struct {
	ReadError error
	Offset    int
}

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 (InvalidDataSectionMemoryIndexError) Unwrap added in v0.12.5

type InvalidDataSectionSegmentCountError added in v0.12.5

type InvalidDataSectionSegmentCountError struct {
	ReadError error
	Offset    int
}

InvalidDataSectionSegmentCountError is returned when the WASM binary specifies an invalid count in the data section

func (InvalidDataSectionSegmentCountError) Error added in v0.12.5

func (InvalidDataSectionSegmentCountError) Unwrap added in v0.12.5

type InvalidDataSegmentError added in v0.12.5

type InvalidDataSegmentError struct {
	ReadError error
	Index     int
}

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

type InvalidExportError added in v0.12.4

type InvalidExportError struct {
	ReadError error
	Index     int
}

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 (InvalidExportIndicatorError) Unwrap added in v0.12.4

type InvalidExportSectionExportCountError added in v0.12.4

type InvalidExportSectionExportCountError struct {
	ReadError error
	Offset    int
}

InvalidExportSectionExportCountError is returned when the WASM binary specifies an invalid count in the export section

func (InvalidExportSectionExportCountError) Error added in v0.12.4

func (InvalidExportSectionExportCountError) Unwrap added in v0.12.4

type InvalidExportSectionIndexError added in v0.12.7

type InvalidExportSectionIndexError struct {
	ReadError error
	Offset    int
}

InvalidExportSectionIndexError is returned when the WASM binary specifies an invalid index in the export section

func (InvalidExportSectionIndexError) Error added in v0.12.7

func (InvalidExportSectionIndexError) Unwrap added in v0.12.7

type InvalidFuncTypeIndicatorError

type InvalidFuncTypeIndicatorError struct {
	ReadError         error
	Offset            int
	FuncTypeIndicator byte
}

InvalidFuncTypeIndicatorError is returned when the WASM binary specifies an invalid function type indicator

func (InvalidFuncTypeIndicatorError) Error

func (InvalidFuncTypeIndicatorError) Unwrap

type InvalidFuncTypeParameterCountError

type InvalidFuncTypeParameterCountError struct {
	ReadError error
	Offset    int
}

InvalidFuncTypeParameterCountError is returned when the WASM binary specifies an invalid func type parameter count

func (InvalidFuncTypeParameterCountError) Error

func (InvalidFuncTypeParameterCountError) Unwrap

type InvalidFuncTypeParameterTypeError

type InvalidFuncTypeParameterTypeError struct {
	ReadError error
	Index     int
}

InvalidFuncTypeParameterTypeError is returned when the WASM binary specifies an invalid function type parameter type

func (InvalidFuncTypeParameterTypeError) Error

func (InvalidFuncTypeParameterTypeError) Unwrap

type InvalidFuncTypeResultCountError

type InvalidFuncTypeResultCountError struct {
	ReadError error
	Offset    int
}

InvalidFuncTypeResultCountError is returned when the WASM binary specifies an invalid func type result count

func (InvalidFuncTypeResultCountError) Error

func (InvalidFuncTypeResultCountError) Unwrap

type InvalidFuncTypeResultTypeError

type InvalidFuncTypeResultTypeError struct {
	ReadError error
	Index     int
}

InvalidFuncTypeResultTypeError is returned when the WASM binary specifies an invalid function type result type

func (InvalidFuncTypeResultTypeError) Error

func (InvalidFuncTypeResultTypeError) Unwrap

type InvalidFunctionCodeError

type InvalidFunctionCodeError struct {
	ReadError error
	Index     int
}

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

type InvalidFunctionSectionFunctionCountError struct {
	ReadError error
	Offset    int
}

InvalidFunctionSectionFunctionCountError is returned when the WASM binary specifies an invalid count in the function section

func (InvalidFunctionSectionFunctionCountError) Error

func (InvalidFunctionSectionFunctionCountError) Unwrap

type InvalidFunctionSectionTypeIndexError added in v0.12.4

type InvalidFunctionSectionTypeIndexError struct {
	ReadError error
	Offset    int
	Index     int
}

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 (InvalidFunctionSectionTypeIndexError) Unwrap added in v0.12.4

type InvalidImportError

type InvalidImportError struct {
	ReadError error
	Index     int
}

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 (InvalidImportIndicatorError) Unwrap added in v0.12.4

type InvalidImportSectionImportCountError

type InvalidImportSectionImportCountError struct {
	ReadError error
	Offset    int
}

InvalidImportSectionImportCountError is returned when the WASM binary specifies an invalid count in the import section

func (InvalidImportSectionImportCountError) Error

func (InvalidImportSectionImportCountError) Unwrap

type InvalidImportSectionTypeIndexError added in v0.12.4

type InvalidImportSectionTypeIndexError struct {
	ReadError error
	Offset    int
}

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 (InvalidImportSectionTypeIndexError) Unwrap added in v0.12.4

type InvalidInstructionArgumentError

type InvalidInstructionArgumentError struct {
	ReadError error
	Offset    int
}

InvalidInstructionArgumentError is returned when the WASM binary specifies an invalid argument for an instruction in the code section

func (InvalidInstructionArgumentError) Error

func (InvalidInstructionArgumentError) Unwrap

type InvalidInstructionVectorArgumentCountError added in v0.12.4

type InvalidInstructionVectorArgumentCountError struct {
	ReadError error
	Offset    int
}

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 (InvalidInstructionVectorArgumentCountError) Unwrap added in v0.12.4

type InvalidLimitIndicatorError added in v0.12.5

type InvalidLimitIndicatorError struct {
	ReadError      error
	Offset         int
	LimitIndicator byte
}

InvalidLimitIndicatorError is returned when the WASM binary specifies an invalid limit indicator

func (InvalidLimitIndicatorError) Error added in v0.12.5

func (InvalidLimitIndicatorError) Unwrap added in v0.12.5

func (e InvalidLimitIndicatorError) Unwrap() error

type InvalidLimitMaxError added in v0.12.5

type InvalidLimitMaxError struct {
	ReadError error
	Offset    int
}

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

type InvalidLimitMinError struct {
	ReadError error
	Offset    int
}

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

type InvalidMagicError struct {
	ReadError error
	Offset    int
}

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

type InvalidMemoryError struct {
	ReadError error
	Index     int
}

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

type InvalidMemorySectionMemoryCountError struct {
	ReadError error
	Offset    int
}

InvalidMemorySectionMemoryCountError is returned when the WASM binary specifies an invalid count in the memory section

func (InvalidMemorySectionMemoryCountError) Error added in v0.12.5

func (InvalidMemorySectionMemoryCountError) Unwrap added in v0.12.5

type InvalidNameError

type InvalidNameError struct {
	ReadError error
	Offset    int
}

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

type InvalidNameLengthError struct {
	ReadError error
	Offset    int
}

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

type InvalidNonUTF8NameError struct {
	Name   string
	Offset int
}

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

type InvalidOpcodeError struct {
	ReadError error
	Offset    int
	Opcode    opcode
}

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

type InvalidSectionIDError struct {
	ReadError error
	Offset    int
	SectionID sectionID
}

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

type InvalidSectionSizeError struct {
	ReadError error
	Offset    int
}

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

type InvalidStartSectionFunctionIndexError struct {
	ReadError error
	Offset    int
}

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 (InvalidStartSectionFunctionIndexError) Unwrap added in v0.12.7

type InvalidTypeSectionTypeCountError

type InvalidTypeSectionTypeCountError struct {
	ReadError error
	Offset    int
}

InvalidTypeSectionTypeCountError is returned when the WASM binary specifies an invalid count in the type section

func (InvalidTypeSectionTypeCountError) Error

func (InvalidTypeSectionTypeCountError) Unwrap

type InvalidValTypeError

type InvalidValTypeError struct {
	ReadError error
	Offset    int
	ValType   ValueType
}

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

type InvalidVersionError struct {
	ReadError error
	Offset    int
}

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

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

func AsValueType(b byte) ValueType

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL