wasm

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: Apache-2.0 Imports: 3 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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 Function

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

Function represents 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
	TypeID uint32
}

Import represents an import

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
}

type InstructionI32Add

type InstructionI32Add struct{}

InstructionI32Add is the 'i32.add' instruction

type InstructionLocalGet

type InstructionLocalGet struct {
	Index uint32
}

InstructionLocalGet is the 'local.get' instruction

type InvalidCodeSectionCompressedLocalsCountError

type InvalidCodeSectionCompressedLocalsCountError struct {
	Offset    int
	ReadError error
}

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 {
	Offset    int
	ReadError error
}

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 {
	Offset    int
	ReadError error
}

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 {
	Offset    int
	ReadError error
}

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 {
	Offset    int
	ReadError error
}

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 InvalidDuplicateSectionError

type InvalidDuplicateSectionError struct {
	Offset    int
	SectionID sectionID
}

InvalidDuplicateSectionError is returned when the WASM binary specifies a duplicate section

func (InvalidDuplicateSectionError) Error

type InvalidFuncTypeIndicatorError

type InvalidFuncTypeIndicatorError struct {
	Offset            int
	FuncTypeIndicator byte
	ReadError         error
}

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

func (InvalidFuncTypeIndicatorError) Error

func (InvalidFuncTypeIndicatorError) Unwrap

type InvalidFuncTypeParameterCountError

type InvalidFuncTypeParameterCountError struct {
	Offset    int
	ReadError error
}

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 {
	Index     int
	ReadError error
}

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 {
	Offset    int
	ReadError error
}

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 {
	Index     int
	ReadError error
}

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 {
	Index     int
	ReadError error
}

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 {
	Offset    int
	ReadError error
}

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

func (InvalidFunctionSectionFunctionCountError) Error

func (InvalidFunctionSectionFunctionCountError) Unwrap

type InvalidFunctionSectionFunctionTypeIDError

type InvalidFunctionSectionFunctionTypeIDError struct {
	Offset    int
	Index     int
	ReadError error
}

InvalidFunctionSectionFunctionTypeIDError is returned when the WASM binary specifies an invalid function type ID in the function section

func (InvalidFunctionSectionFunctionTypeIDError) Error

func (InvalidFunctionSectionFunctionTypeIDError) Unwrap

type InvalidImportError

type InvalidImportError struct {
	Index     int
	ReadError error
}

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 InvalidImportSectionFunctionTypeIDError

type InvalidImportSectionFunctionTypeIDError struct {
	Offset    int
	ReadError error
}

InvalidImportSectionFunctionTypeIDError is returned when the WASM binary specifies an invalid function type ID in the import section

func (InvalidImportSectionFunctionTypeIDError) Error

func (InvalidImportSectionFunctionTypeIDError) Unwrap

type InvalidImportSectionImportCountError

type InvalidImportSectionImportCountError struct {
	Offset    int
	ReadError error
}

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

func (InvalidImportSectionImportCountError) Error

func (InvalidImportSectionImportCountError) Unwrap

type InvalidImportTypeIndicatorError

type InvalidImportTypeIndicatorError struct {
	Offset        int
	TypeIndicator importTypeIndicator
	ReadError     error
}

InvalidImportTypeIndicatorError is returned when the WASM binary specifies an invalid type indicator in the import section

func (InvalidImportTypeIndicatorError) Error

func (InvalidImportTypeIndicatorError) Unwrap

type InvalidInstructionArgumentError

type InvalidInstructionArgumentError struct {
	Offset    int
	Opcode    opcode
	ReadError error
}

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 InvalidMagicError

type InvalidMagicError struct {
	Offset    int
	ReadError error
}

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 InvalidNameError

type InvalidNameError struct {
	Offset    int
	ReadError error
}

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 {
	Offset    int
	ReadError error
}

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 {
	Offset    int
	Opcode    opcode
	ReadError error
}

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 {
	Offset    int
	SectionID sectionID
	ReadError error
}

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 InvalidSectionSizeError

type InvalidSectionSizeError struct {
	Offset    int
	ReadError error
}

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 InvalidTypeSectionTypeCountError

type InvalidTypeSectionTypeCountError struct {
	Offset    int
	ReadError error
}

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 {
	Offset    int
	ValType   ValueType
	ReadError error
}

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 {
	Offset    int
	ReadError error
}

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 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 {
	Types []*FunctionType

	Imports []*Import
	// contains filtered or unexported fields
}

Module represents a module

type ValueType

type ValueType byte

ValueType is the type of a value

const (
	// ValueTypeI32 is the i32 type
	// The value is the byte used in the WASM binary
	ValueTypeI32 ValueType = 0x7F
	// ValueTypeI64 is the i64 type.
	// The value is the byte used in the WASM binary
	ValueTypeI64 ValueType = 0x7E
)

type WASMReader

type WASMReader struct {
	Module Module
	// contains filtered or unexported fields
}

WASMReader allows reading WASM binaries

type WASMWriter

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

WASMWriter allows writing WASM binaries

Jump to

Keyboard shortcuts

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