wasm

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 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

func WASM2WAT(binary []byte) string

Types

type Block

type Block struct {
	BlockType     BlockType
	Instructions1 []Instruction
	Instructions2 []Instruction
}

type BlockType

type BlockType interface {
	// contains filtered or unexported methods
}

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is a byte buffer, which allows reading and writing.

func (*Buffer) Bytes

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

func (*Buffer) PeekByte

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

func (*Buffer) Read

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

func (*Buffer) ReadByte

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

func (*Buffer) ReadBytesEqual

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

func (*Buffer) WriteByte

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

func (*Buffer) WriteBytes

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

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 Function

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

Function represents a function

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

type FunctionExport

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

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

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

type InstructionBrTable struct {
	LabelIndices      []uint32
	DefaultLabelIndex uint32
}

InstructionBrTable is the 'br_table' instruction

type InstructionCall

type InstructionCall struct {
	FuncIndex uint32
}

InstructionCall is the 'call' instruction

type InstructionCallIndirect

type InstructionCallIndirect struct {
	TypeIndex  uint32
	TableIndex uint32
}

InstructionCallIndirect is the 'call_indirect' instruction

type InstructionDrop

type InstructionDrop struct{}

InstructionDrop is the 'drop' instruction

type InstructionEnd

type InstructionEnd struct{}

InstructionEnd is the 'end' 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 InstructionI32Eq

type InstructionI32Eq struct{}

InstructionI32Eq is the 'i32.eq' 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 InstructionI32Ne

type InstructionI32Ne struct{}

InstructionI32Ne is the 'i32.ne' instruction

type InstructionI32Or

type InstructionI32Or struct{}

InstructionI32Or is the 'i32.or' 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 InstructionI64Eq

type InstructionI64Eq struct{}

InstructionI64Eq is the 'i64.eq' 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 InstructionI64Ne

type InstructionI64Ne struct{}

InstructionI64Ne is the 'i64.ne' instruction

type InstructionI64Or

type InstructionI64Or struct{}

InstructionI64Or is the 'i64.or' 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 InstructionNop

type InstructionNop struct{}

InstructionNop is the 'nop' 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

type InvalidBlockTypeTypeIndexError

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

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

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

func (InvalidDataSectionInitByteCountError) Unwrap

type InvalidDataSectionMemoryIndexError

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

func (InvalidDataSectionMemoryIndexError) Unwrap

type InvalidDataSectionSegmentCountError

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

func (InvalidDataSectionSegmentCountError) Unwrap

type InvalidDataSegmentError

type InvalidDataSegmentError struct {
	ReadError error
	Index     int
}

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

type InvalidExportError

type InvalidExportError struct {
	ReadError error
	Index     int
}

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 (InvalidExportIndicatorError) Unwrap

type InvalidExportSectionExportCountError

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

func (InvalidExportSectionExportCountError) Unwrap

type InvalidExportSectionIndexError

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

func (InvalidExportSectionIndexError) Unwrap

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

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

func (InvalidFunctionSectionTypeIndexError) Unwrap

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

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 (InvalidImportIndicatorError) Unwrap

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

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

func (InvalidImportSectionTypeIndexError) Unwrap

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

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

func (InvalidInstructionVectorArgumentCountError) Unwrap

type InvalidLimitIndicatorError

type InvalidLimitIndicatorError struct {
	ReadError      error
	Offset         int
	LimitIndicator byte
}

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

func (InvalidLimitIndicatorError) Error

func (InvalidLimitIndicatorError) Unwrap

func (e InvalidLimitIndicatorError) Unwrap() error

type InvalidLimitMaxError

type InvalidLimitMaxError struct {
	ReadError error
	Offset    int
}

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

type InvalidLimitMinError struct {
	ReadError error
	Offset    int
}

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

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

type InvalidMemoryError struct {
	ReadError error
	Index     int
}

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

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

func (InvalidMemorySectionMemoryCountError) Unwrap

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

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

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

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

func (InvalidStartSectionFunctionIndexError) Unwrap

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

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

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

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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