wasm

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package wasm provides functions for reading and parsing WebAssembly modules.

Index

Constants

View Source
const (
	Magic   uint32 = 0x6d736100
	Version uint32 = 0x1
)
View Source
const (
	NameModule   = NameType(0)
	NameFunction = NameType(1)
	NameLocal    = NameType(2)
)
View Source
const (
	CustomSectionName = "name"
)

A list of well-known custom sections

View Source
const TypeFunc uint8 = 0x60

TypeFunc represents the value type of a function

Variables

View Source
var (
	ErrImportMutGlobal           = errors.New("wasm: cannot import global mutable variable")
	ErrNoExportsInImportedModule = errors.New("wasm: imported module has no exports")
)
View Source
var ErrEmptyInitExpr = errors.New("wasm: Initializer expression produces no value")
View Source
var ErrFunctionNoEnd = errors.New("Function body does not end with 0x0b (end)")
View Source
var ErrInvalidMagic = errors.New("wasm: Invalid magic number")
View Source
var ErrUnsupportedSection = errors.New("wasm: unsupported section")

Functions

func EncodeModule added in v0.2.0

func EncodeModule(w io.Writer, m *Module) error

EncodeModule writes a provided module to w using WASM binary encoding.

func ReadByte added in v0.7.1

func ReadByte(r io.Reader) (byte, error)

func SetDebugMode

func SetDebugMode(dbg bool)

Types

type BlockType

type BlockType ValueType // varint7

BlockType represents the signature of a structured block

const BlockTypeEmpty BlockType = 0x40

func (BlockType) String

func (b BlockType) String() string

type DataSegment

type DataSegment struct {
	Index  uint32 // The index into the global linear memory space, should always be 0 in the MVP.
	Offset []byte // initializer expression for computing the offset for placing elements, should return an i32 value
	Data   []byte
}

DataSegment describes a group of repeated elements that begin at a specified offset in the linear memory

func (*DataSegment) MarshalWASM added in v0.2.0

func (s *DataSegment) MarshalWASM(w io.Writer) error

func (*DataSegment) UnmarshalWASM added in v0.2.0

func (s *DataSegment) UnmarshalWASM(r io.Reader) error

type DuplicateExportError

type DuplicateExportError string

func (DuplicateExportError) Error

func (e DuplicateExportError) Error() string

type ElemType

type ElemType uint8 // varint7

ElemType describes the type of a table's elements

const ElemTypeAnyFunc ElemType = 0x70

ElemTypeAnyFunc descibres an any_func value

func (ElemType) MarshalWASM added in v0.2.0

func (t ElemType) MarshalWASM(w io.Writer) error

func (ElemType) String

func (t ElemType) String() string

func (*ElemType) UnmarshalWASM added in v0.2.0

func (t *ElemType) UnmarshalWASM(r io.Reader) error

type ElementSegment

type ElementSegment struct {
	Index  uint32 // The index into the global table space, should always be 0 in the MVP.
	Offset []byte // initializer expression for computing the offset for placing elements, should return an i32 value
	Elems  []uint32
}

ElementSegment describes a group of repeated elements that begin at a specified offset

func (*ElementSegment) MarshalWASM added in v0.2.0

func (s *ElementSegment) MarshalWASM(w io.Writer) error

func (*ElementSegment) UnmarshalWASM added in v0.2.0

func (s *ElementSegment) UnmarshalWASM(r io.Reader) error

type ExportEntry

type ExportEntry struct {
	FieldStr string
	Kind     External
	Index    uint32
}

ExportEntry represents an exported entry by the module

func (*ExportEntry) MarshalWASM added in v0.2.0

func (e *ExportEntry) MarshalWASM(w io.Writer) error

func (*ExportEntry) UnmarshalWASM added in v0.2.0

func (e *ExportEntry) UnmarshalWASM(r io.Reader) error

type ExportNotFoundError

type ExportNotFoundError struct {
	ModuleName string
	FieldName  string
}

func (ExportNotFoundError) Error

func (e ExportNotFoundError) Error() string

type External

type External uint8

External describes the kind of the entry being imported or exported.

const (
	ExternalFunction External = 0
	ExternalTable    External = 1
	ExternalMemory   External = 2
	ExternalGlobal   External = 3
)

func (External) MarshalWASM added in v0.2.0

func (e External) MarshalWASM(w io.Writer) error

func (External) String

func (e External) String() string

func (*External) UnmarshalWASM added in v0.2.0

func (e *External) UnmarshalWASM(r io.Reader) error

type FuncImport

type FuncImport struct {
	Type uint32
}

func (FuncImport) Kind added in v0.2.0

func (FuncImport) Kind() External

func (FuncImport) MarshalWASM added in v0.2.0

func (f FuncImport) MarshalWASM(w io.Writer) error

type Function

type Function struct {
	Sig        *FunctionSig
	Body       *FunctionBody
	Host       reflect.Value
	Name       string
	CheckGas   bool          // whether check gas out side of the function
	GasCounter reflect.Value // returns gas with params. same signature with function, but returns an uint64.
	FixedGas   uint64        // gas of function if GasCounter not available
}

Function represents an entry in the function index space of a module.

func (*Function) IsHost

func (fct *Function) IsHost() bool

IsHost indicates whether this function is a host function as defined in:

https://webassembly.github.io/spec/core/exec/modules.html#host-functions

func (*Function) String added in v0.7.1

func (fct *Function) String() string

type FunctionBody

type FunctionBody struct {
	Module *Module // The parent module containing this function body, for execution purposes
	Locals []LocalEntry
	Code   []byte
}

func (*FunctionBody) MarshalWASM added in v0.2.0

func (f *FunctionBody) MarshalWASM(w io.Writer) error

func (*FunctionBody) UnmarshalWASM added in v0.2.0

func (f *FunctionBody) UnmarshalWASM(r io.Reader) error

type FunctionNames added in v0.7.1

type FunctionNames struct {
	Names NameMap
}

FunctionNames is a set of names for functions.

func (*FunctionNames) MarshalWASM added in v0.7.1

func (s *FunctionNames) MarshalWASM(w io.Writer) error

func (*FunctionNames) UnmarshalWASM added in v0.7.1

func (s *FunctionNames) UnmarshalWASM(r io.Reader) error

type FunctionSig

type FunctionSig struct {
	// value for the 'func` type constructor
	Form uint8 // must be 0x60
	// The parameter types of the function
	ParamTypes  []ValueType
	ReturnTypes []ValueType
}

FunctionSig describes the signature of a declared function in a WASM module

func (*FunctionSig) MarshalWASM added in v0.2.0

func (f *FunctionSig) MarshalWASM(w io.Writer) error

func (FunctionSig) String

func (f FunctionSig) String() string

func (*FunctionSig) UnmarshalWASM added in v0.2.0

func (f *FunctionSig) UnmarshalWASM(r io.Reader) error

type GlobalEntry

type GlobalEntry struct {
	Type GlobalVar // Type holds information about the value type and mutability of the variable
	Init []byte    // Init is an initializer expression that computes the initial value of the variable
}

GlobalEntry declares a global variable.

func (*GlobalEntry) MarshalWASM added in v0.2.0

func (g *GlobalEntry) MarshalWASM(w io.Writer) error

func (*GlobalEntry) UnmarshalWASM added in v0.2.0

func (g *GlobalEntry) UnmarshalWASM(r io.Reader) error

type GlobalVar

type GlobalVar struct {
	Type    ValueType // Type of the value stored by the variable
	Mutable bool      // Whether the value of the variable can be changed by the set_global operator
}

GlobalVar describes the type and mutability of a declared global variable

func (*GlobalVar) MarshalWASM added in v0.2.0

func (g *GlobalVar) MarshalWASM(w io.Writer) error

func (*GlobalVar) UnmarshalWASM added in v0.2.0

func (g *GlobalVar) UnmarshalWASM(r io.Reader) error

type GlobalVarImport

type GlobalVarImport struct {
	Type GlobalVar
}

func (GlobalVarImport) Kind added in v0.2.0

func (GlobalVarImport) Kind() External

func (GlobalVarImport) MarshalWASM added in v0.2.0

func (t GlobalVarImport) MarshalWASM(w io.Writer) error

type Import

type Import interface {
	Kind() External
	Marshaler
	// contains filtered or unexported methods
}

Import is an interface implemented by types that can be imported by a WebAssembly module.

type ImportEntry

type ImportEntry struct {
	ModuleName string // module name string
	FieldName  string // field name string

	// If Kind is Function, Type is a FuncImport containing the type index of the function signature
	// If Kind is Table, Type is a TableImport containing the type of the imported table
	// If Kind is Memory, Type is a MemoryImport containing the type of the imported memory
	// If the Kind is Global, Type is a GlobalVarImport
	Type Import
}

ImportEntry describes an import statement in a Wasm module.

func (*ImportEntry) UnmarshalWASM added in v0.2.0

func (i *ImportEntry) UnmarshalWASM(r io.Reader) error

type InvalidCodeIndexError

type InvalidCodeIndexError int

func (InvalidCodeIndexError) Error

func (e InvalidCodeIndexError) Error() string

type InvalidExternalError

type InvalidExternalError uint8

func (InvalidExternalError) Error

func (e InvalidExternalError) Error() string

type InvalidFunctionIndexError

type InvalidFunctionIndexError uint32

func (InvalidFunctionIndexError) Error

type InvalidGlobalIndexError

type InvalidGlobalIndexError uint32

func (InvalidGlobalIndexError) Error

func (e InvalidGlobalIndexError) Error() string

type InvalidImportError added in v0.7.1

type InvalidImportError struct {
	ModuleName string
	FieldName  string
	TypeIndex  uint32
}

InvalidImportError is returned when the export of a resolved module doesn't match the signature of its import declaration.

func (InvalidImportError) Error added in v0.7.1

func (e InvalidImportError) Error() string

type InvalidInitExprOpError

type InvalidInitExprOpError byte

func (InvalidInitExprOpError) Error

func (e InvalidInitExprOpError) Error() string

type InvalidLinearMemoryIndexError

type InvalidLinearMemoryIndexError uint32

func (InvalidLinearMemoryIndexError) Error

type InvalidSectionIDError

type InvalidSectionIDError SectionID

func (InvalidSectionIDError) Error

func (e InvalidSectionIDError) Error() string

type InvalidTableIndexError

type InvalidTableIndexError uint32

func (InvalidTableIndexError) Error

func (e InvalidTableIndexError) Error() string

type InvalidTypeConstructorError

type InvalidTypeConstructorError struct {
	Wanted int
	Got    int
}

func (InvalidTypeConstructorError) Error

type InvalidValueTypeInitExprError

type InvalidValueTypeInitExprError struct {
	Wanted reflect.Kind
	Got    reflect.Kind
}

func (InvalidValueTypeInitExprError) Error

type KindMismatchError

type KindMismatchError struct {
	ModuleName string
	FieldName  string
	Import     External
	Export     External
}

func (KindMismatchError) Error

func (e KindMismatchError) Error() string

type LocalEntry

type LocalEntry struct {
	Count uint32    // The total number of local variables of the given Type used in the function body
	Type  ValueType // The type of value stored by the variable
}

func (*LocalEntry) MarshalWASM added in v0.2.0

func (l *LocalEntry) MarshalWASM(w io.Writer) error

func (*LocalEntry) UnmarshalWASM added in v0.2.0

func (l *LocalEntry) UnmarshalWASM(r io.Reader) error

type LocalNames added in v0.7.1

type LocalNames struct {
	// Funcs maps a function index to a set of variable names.
	Funcs map[uint32]NameMap
}

LocalNames is a set of local variable names for functions.

func (*LocalNames) MarshalWASM added in v0.7.1

func (s *LocalNames) MarshalWASM(w io.Writer) error

func (*LocalNames) UnmarshalWASM added in v0.7.1

func (s *LocalNames) UnmarshalWASM(r io.Reader) error

type Marshaler added in v0.2.0

type Marshaler interface {
	// MarshalWASM encodes an object into w using WASM binary encoding.
	MarshalWASM(w io.Writer) error
}

type Memory

type Memory struct {
	Limits ResizableLimits
}

func (*Memory) MarshalWASM added in v0.2.0

func (m *Memory) MarshalWASM(w io.Writer) error

func (*Memory) UnmarshalWASM added in v0.2.0

func (m *Memory) UnmarshalWASM(r io.Reader) error

type MemoryImport

type MemoryImport struct {
	Type Memory
}

func (MemoryImport) Kind added in v0.2.0

func (MemoryImport) Kind() External

func (MemoryImport) MarshalWASM added in v0.2.0

func (t MemoryImport) MarshalWASM(w io.Writer) error

type MissingSectionError

type MissingSectionError SectionID

func (MissingSectionError) Error

func (e MissingSectionError) Error() string

type Module

type Module struct {
	Version  uint32
	Sections []Section

	Types    *SectionTypes
	Import   *SectionImports
	Function *SectionFunctions
	Table    *SectionTables
	Memory   *SectionMemories
	Global   *SectionGlobals
	Export   *SectionExports
	Start    *SectionStartFunction
	Elements *SectionElements
	Code     *SectionCode
	Data     *SectionData
	Customs  []*SectionCustom

	// The function index space of the module
	FunctionIndexSpace []Function
	GlobalIndexSpace   []GlobalEntry

	// function indices into the global function space
	// the limit of each table is its capacity (cap)
	TableIndexSpace        [][]TableEntry
	LinearMemoryIndexSpace [][]byte
	// contains filtered or unexported fields
}

Module represents a parsed WebAssembly module: http://webassembly.org/docs/modules/

func DecodeModule added in v0.2.0

func DecodeModule(r io.Reader) (*Module, error)

DecodeModule is the same as ReadModule, but it only decodes the module without initializing the index space or resolving imports.

func NewModule

func NewModule() *Module

NewModule creates a new empty module

func ReadModule

func ReadModule(r io.Reader, resolvePath ResolveFunc) (*Module, error)

ReadModule reads a module from the reader r. resolvePath must take a string and a return a reader to the module pointed to by the string.

func (*Module) Custom added in v0.7.1

func (m *Module) Custom(name string) *SectionCustom

Custom returns a custom section with a specific name, if it exists.

func (*Module) ExecInitExpr

func (m *Module) ExecInitExpr(expr []byte) (interface{}, error)

ExecInitExpr executes an initializer expression and returns an interface{} value which can either be int32, int64, float32 or float64. It returns an error if the expression is invalid, and nil when the expression yields no value.

func (*Module) GetFunction

func (m *Module) GetFunction(i int) *Function

GetFunction returns a *Function, based on the function's index in the function index space. Returns nil when the index is invalid

func (*Module) GetFunctionSig added in v0.7.1

func (m *Module) GetFunctionSig(i uint32) (*FunctionSig, error)

func (*Module) GetGlobal

func (m *Module) GetGlobal(i int) *GlobalEntry

GetGlobal returns a *GlobalEntry, based on the global index space. Returns nil when the index is invalid

func (*Module) GetGlobalType added in v0.7.1

func (m *Module) GetGlobalType(i uint32) (*GlobalVar, error)

func (*Module) GetLinearMemoryData

func (m *Module) GetLinearMemoryData(index int) (byte, error)

func (*Module) GetTableElement

func (m *Module) GetTableElement(index int) (uint32, error)

GetTableElement returns an element from the tableindex space indexed by the integer index. It returns an error if index is invalid.

type ModuleName added in v0.7.1

type ModuleName struct {
	Name string
}

ModuleName is the name of a module.

func (*ModuleName) MarshalWASM added in v0.7.1

func (s *ModuleName) MarshalWASM(w io.Writer) error

func (*ModuleName) UnmarshalWASM added in v0.7.1

func (s *ModuleName) UnmarshalWASM(r io.Reader) error

type NameMap added in v0.7.1

type NameMap map[uint32]string

NameMap maps an index of the entry to a name.

func (NameMap) MarshalWASM added in v0.7.1

func (m NameMap) MarshalWASM(w io.Writer) error

func (NameMap) UnmarshalWASM added in v0.7.1

func (m NameMap) UnmarshalWASM(r io.Reader) error

type NameSection added in v0.7.1

type NameSection struct {
	Types map[NameType][]byte
}

NameSection is a custom section that stores names of modules, functions and locals for debugging purposes. See https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#name-section for more details.

func (*NameSection) Decode added in v0.7.1

func (s *NameSection) Decode(typ NameType) (NameSubsection, error)

Decode finds a specific subsection type and decodes it.

func (*NameSection) MarshalWASM added in v0.7.1

func (s *NameSection) MarshalWASM(w io.Writer) error

func (*NameSection) UnmarshalWASM added in v0.7.1

func (s *NameSection) UnmarshalWASM(r io.Reader) error

type NameSubsection added in v0.7.1

type NameSubsection interface {
	Marshaler
	Unmarshaler
	// contains filtered or unexported methods
}

NameSubsection is an interface for subsections of NameSection.

Valid types:

  • ModuleName
  • FunctionNames
  • LocalNames

type NameType added in v0.7.1

type NameType byte

NameType is the type of name subsection.

type OutsizeError added in v0.7.1

type OutsizeError struct {
	ImmType string
	Size    uint64
	Max     uint64
}

func (OutsizeError) Error added in v0.7.1

func (e OutsizeError) Error() string

type RawSection added in v0.2.0

type RawSection struct {
	Start int64
	End   int64

	ID    SectionID
	Bytes []byte
}

RawSection is a declared section in a WASM module.

func (*RawSection) GetRawSection added in v0.2.0

func (s *RawSection) GetRawSection() *RawSection

func (*RawSection) SectionID added in v0.2.0

func (s *RawSection) SectionID() SectionID

type ResizableLimits

type ResizableLimits struct {
	Flags   uint8  // 1 if the Maximum field is valid, 0 otherwise
	Initial uint32 // initial length (in units of table elements or wasm pages)
	Maximum uint32 // If flags is 1, it describes the maximum size of the table or memory
}

ResizableLimits describe the limit of a table or linear memory.

func (*ResizableLimits) MarshalWASM added in v0.2.0

func (lim *ResizableLimits) MarshalWASM(w io.Writer) error

func (*ResizableLimits) UnmarshalWASM added in v0.2.0

func (lim *ResizableLimits) UnmarshalWASM(r io.Reader) error

type ResolveFunc

type ResolveFunc func(name string) (*Module, error)

ResolveFunc is a function that takes a module name and returns a valid resolved module.

type Section

type Section interface {
	// SectionID returns a section ID for WASM encoding. Should be unique across types.
	SectionID() SectionID
	// GetRawSection Returns an embedded RawSection pointer to populate generic fields.
	GetRawSection() *RawSection
	// ReadPayload reads a section payload, assuming the size was already read, and reader is limited to it.
	ReadPayload(r io.Reader) error
	// WritePayload writes a section payload without the size.
	// Caller should calculate written size and add it before the payload.
	WritePayload(w io.Writer) error
}

Section is a generic WASM section interface.

type SectionCode

type SectionCode struct {
	RawSection
	Bodies []FunctionBody
}

SectionCode describes the body for every function declared inside a module.

func (*SectionCode) ReadPayload added in v0.2.0

func (s *SectionCode) ReadPayload(r io.Reader) error

func (*SectionCode) SectionID added in v0.2.0

func (*SectionCode) SectionID() SectionID

func (*SectionCode) WritePayload added in v0.2.0

func (s *SectionCode) WritePayload(w io.Writer) error

type SectionCustom added in v0.7.1

type SectionCustom struct {
	RawSection
	Name string
	Data []byte
}

func (*SectionCustom) ReadPayload added in v0.7.1

func (s *SectionCustom) ReadPayload(r io.Reader) error

func (*SectionCustom) SectionID added in v0.7.1

func (s *SectionCustom) SectionID() SectionID

func (*SectionCustom) WritePayload added in v0.7.1

func (s *SectionCustom) WritePayload(w io.Writer) error

type SectionData

type SectionData struct {
	RawSection
	Entries []DataSegment
}

SectionData describes the initial values of a module's linear memory

func (*SectionData) ReadPayload added in v0.2.0

func (s *SectionData) ReadPayload(r io.Reader) error

func (*SectionData) SectionID added in v0.2.0

func (*SectionData) SectionID() SectionID

func (*SectionData) WritePayload added in v0.2.0

func (s *SectionData) WritePayload(w io.Writer) error

type SectionElements

type SectionElements struct {
	RawSection
	Entries []ElementSegment
}

SectionElements describes the initial contents of a table's elements.

func (*SectionElements) ReadPayload added in v0.2.0

func (s *SectionElements) ReadPayload(r io.Reader) error

func (*SectionElements) SectionID added in v0.2.0

func (*SectionElements) SectionID() SectionID

func (*SectionElements) WritePayload added in v0.2.0

func (s *SectionElements) WritePayload(w io.Writer) error

type SectionExports

type SectionExports struct {
	RawSection
	Entries map[string]ExportEntry
	Names   []string
}

SectionExports declares the export section of a module

func (*SectionExports) ReadPayload added in v0.2.0

func (s *SectionExports) ReadPayload(r io.Reader) error

func (*SectionExports) SectionID added in v0.2.0

func (*SectionExports) SectionID() SectionID

func (*SectionExports) WritePayload added in v0.2.0

func (s *SectionExports) WritePayload(w io.Writer) error

type SectionFunctions

type SectionFunctions struct {
	RawSection
	// Sequences of indices into (FunctionSignatues).Entries
	Types []uint32
}

SectionFunction declares the signature of all functions defined in the module (in the code section)

func (*SectionFunctions) ReadPayload added in v0.2.0

func (s *SectionFunctions) ReadPayload(r io.Reader) error

func (*SectionFunctions) SectionID added in v0.2.0

func (*SectionFunctions) SectionID() SectionID

func (*SectionFunctions) WritePayload added in v0.2.0

func (s *SectionFunctions) WritePayload(w io.Writer) error

type SectionGlobals

type SectionGlobals struct {
	RawSection
	Globals []GlobalEntry
}

SectionGlobals defines the value of all global variables declared in a module.

func (*SectionGlobals) ReadPayload added in v0.2.0

func (s *SectionGlobals) ReadPayload(r io.Reader) error

func (*SectionGlobals) SectionID added in v0.2.0

func (*SectionGlobals) SectionID() SectionID

func (*SectionGlobals) WritePayload added in v0.2.0

func (s *SectionGlobals) WritePayload(w io.Writer) error

type SectionID

type SectionID uint8

SectionID is a 1-byte code that encodes the section code of both known and custom sections.

const (
	SectionIDCustom   SectionID = 0
	SectionIDType     SectionID = 1
	SectionIDImport   SectionID = 2
	SectionIDFunction SectionID = 3
	SectionIDTable    SectionID = 4
	SectionIDMemory   SectionID = 5
	SectionIDGlobal   SectionID = 6
	SectionIDExport   SectionID = 7
	SectionIDStart    SectionID = 8
	SectionIDElement  SectionID = 9
	SectionIDCode     SectionID = 10
	SectionIDData     SectionID = 11
)

func (SectionID) String

func (s SectionID) String() string

type SectionImports

type SectionImports struct {
	RawSection
	Entries []ImportEntry
}

SectionImports declares all imports that will be used in the module.

func (*SectionImports) ReadPayload added in v0.2.0

func (s *SectionImports) ReadPayload(r io.Reader) error

func (*SectionImports) SectionID added in v0.2.0

func (*SectionImports) SectionID() SectionID

func (*SectionImports) WritePayload added in v0.2.0

func (s *SectionImports) WritePayload(w io.Writer) error

type SectionMemories

type SectionMemories struct {
	RawSection
	Entries []Memory
}

SectionMemories describes all linear memories used by a module.

func (*SectionMemories) ReadPayload added in v0.2.0

func (s *SectionMemories) ReadPayload(r io.Reader) error

func (*SectionMemories) SectionID added in v0.2.0

func (*SectionMemories) SectionID() SectionID

func (*SectionMemories) WritePayload added in v0.2.0

func (s *SectionMemories) WritePayload(w io.Writer) error

type SectionStartFunction

type SectionStartFunction struct {
	RawSection
	Index uint32 // The index of the start function into the global index space.
}

SectionStartFunction represents the start function section.

func (*SectionStartFunction) ReadPayload added in v0.2.0

func (s *SectionStartFunction) ReadPayload(r io.Reader) error

func (*SectionStartFunction) SectionID added in v0.2.0

func (*SectionStartFunction) SectionID() SectionID

func (*SectionStartFunction) WritePayload added in v0.2.0

func (s *SectionStartFunction) WritePayload(w io.Writer) error

type SectionTables

type SectionTables struct {
	RawSection
	Entries []Table
}

SectionTables describes all tables declared by a module.

func (*SectionTables) ReadPayload added in v0.2.0

func (s *SectionTables) ReadPayload(r io.Reader) error

func (*SectionTables) SectionID added in v0.2.0

func (*SectionTables) SectionID() SectionID

func (*SectionTables) WritePayload added in v0.2.0

func (s *SectionTables) WritePayload(w io.Writer) error

type SectionTypes

type SectionTypes struct {
	RawSection
	Entries []FunctionSig
}

SectionTypes declares all function signatures that will be used in a module.

func (*SectionTypes) ReadPayload added in v0.2.0

func (s *SectionTypes) ReadPayload(r io.Reader) error

func (*SectionTypes) SectionID added in v0.2.0

func (*SectionTypes) SectionID() SectionID

func (*SectionTypes) WritePayload added in v0.2.0

func (s *SectionTypes) WritePayload(w io.Writer) error

type Table

type Table struct {
	// The type of elements
	ElementType ElemType
	Limits      ResizableLimits
}

Table describes a table in a Wasm module.

func (*Table) MarshalWASM added in v0.2.0

func (t *Table) MarshalWASM(w io.Writer) error

func (*Table) UnmarshalWASM added in v0.2.0

func (t *Table) UnmarshalWASM(r io.Reader) error

type TableEntry added in v0.7.1

type TableEntry struct {
	Index       uint32
	Initialized bool
}

TableEntry represents a table index and tracks its initialized state.

type TableImport

type TableImport struct {
	Type Table
}

func (TableImport) Kind added in v0.2.0

func (TableImport) Kind() External

func (TableImport) MarshalWASM added in v0.2.0

func (t TableImport) MarshalWASM(w io.Writer) error

type UninitializedTableEntryError added in v0.7.1

type UninitializedTableEntryError uint32

func (UninitializedTableEntryError) Error added in v0.7.1

type Unmarshaler added in v0.2.0

type Unmarshaler interface {
	// UnmarshalWASM decodes an object from r using WASM binary encoding.
	UnmarshalWASM(r io.Reader) error
}

type ValueType

type ValueType uint8

ValueType represents the type of a valid value in Wasm

const (
	ValueTypeI32 ValueType = 0x7f
	ValueTypeI64 ValueType = 0x7e
	ValueTypeF32 ValueType = 0x7d
	ValueTypeF64 ValueType = 0x7c
)

func (ValueType) MarshalWASM added in v0.2.0

func (t ValueType) MarshalWASM(w io.Writer) error

func (ValueType) String

func (t ValueType) String() string

func (*ValueType) UnmarshalWASM added in v0.2.0

func (t *ValueType) UnmarshalWASM(r io.Reader) error

type ValueTypes added in v0.7.1

type ValueTypes []ValueType

func (ValueTypes) String added in v0.7.1

func (ts ValueTypes) String() string

Directories

Path Synopsis
internal
Package leb128 provides functions for reading integer values encoded in the Little Endian Base 128 (LEB128) format: https://en.wikipedia.org/wiki/LEB128
Package leb128 provides functions for reading integer values encoded in the Little Endian Base 128 (LEB128) format: https://en.wikipedia.org/wiki/LEB128
Package operators provides all operators used by WebAssembly bytecode, together with their parameter and return type(s).
Package operators provides all operators used by WebAssembly bytecode, together with their parameter and return type(s).

Jump to

Keyboard shortcuts

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