code

package
v0.0.0-...-3940e3f Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockTypeSpecial = 0x8000000000000000
	BlockTypeMask    = 0x80000000ffffffff
	StackHeightMask  = 0x7fffffff00000000

	BlockTypeEmpty = 0x40 | BlockTypeSpecial
	BlockTypeI32   = 0x7f | BlockTypeSpecial
	BlockTypeI64   = 0x7e | BlockTypeSpecial
	BlockTypeF32   = 0x7d | BlockTypeSpecial
	BlockTypeF64   = 0x7c | BlockTypeSpecial
)
View Source
const (
	OpUnreachable  = 0x00
	OpNop          = 0x01
	OpBlock        = 0x02
	OpLoop         = 0x03
	OpIf           = 0x04
	OpElse         = 0x05
	OpEnd          = 0x0b
	OpBr           = 0x0c
	OpBrIf         = 0x0d
	OpBrTable      = 0x0e
	OpReturn       = 0x0f
	OpCall         = 0x10
	OpCallIndirect = 0x11

	OpDrop   = 0x1a
	OpSelect = 0x1b

	OpLocalGet  = 0x20
	OpLocalSet  = 0x21
	OpLocalTee  = 0x22
	OpGlobalGet = 0x23
	OpGlobalSet = 0x24

	OpI32Load    = 0x28
	OpI64Load    = 0x29
	OpF32Load    = 0x2a
	OpF64Load    = 0x2b
	OpI32Load8S  = 0x2c
	OpI32Load8U  = 0x2d
	OpI32Load16S = 0x2e
	OpI32Load16U = 0x2f
	OpI64Load8S  = 0x30
	OpI64Load8U  = 0x31
	OpI64Load16S = 0x32
	OpI64Load16U = 0x33
	OpI64Load32S = 0x34
	OpI64Load32U = 0x35
	OpI32Store   = 0x36
	OpI64Store   = 0x37
	OpF32Store   = 0x38
	OpF64Store   = 0x39
	OpI32Store8  = 0x3a
	OpI32Store16 = 0x3b
	OpI64Store8  = 0x3c
	OpI64Store16 = 0x3d
	OpI64Store32 = 0x3e
	OpMemorySize = 0x3f
	OpMemoryGrow = 0x40

	OpI32Const = 0x41
	OpI64Const = 0x42
	OpF32Const = 0x43
	OpF64Const = 0x44

	OpI32Eqz = 0x45
	OpI32Eq  = 0x46
	OpI32Ne  = 0x47
	OpI32LtS = 0x48
	OpI32LtU = 0x49
	OpI32GtS = 0x4a
	OpI32GtU = 0x4b
	OpI32LeS = 0x4c
	OpI32LeU = 0x4d
	OpI32GeS = 0x4e
	OpI32GeU = 0x4f

	OpI64Eqz = 0x50
	OpI64Eq  = 0x51
	OpI64Ne  = 0x52
	OpI64LtS = 0x53
	OpI64LtU = 0x54
	OpI64GtS = 0x55
	OpI64GtU = 0x56
	OpI64LeS = 0x57
	OpI64LeU = 0x58
	OpI64GeS = 0x59
	OpI64GeU = 0x5a

	OpF32Eq = 0x5b
	OpF32Ne = 0x5c
	OpF32Lt = 0x5d
	OpF32Gt = 0x5e
	OpF32Le = 0x5f
	OpF32Ge = 0x60

	OpF64Eq = 0x61
	OpF64Ne = 0x62
	OpF64Lt = 0x63
	OpF64Gt = 0x64
	OpF64Le = 0x65
	OpF64Ge = 0x66

	OpI32Clz    = 0x67
	OpI32Ctz    = 0x68
	OpI32Popcnt = 0x69
	OpI32Add    = 0x6a
	OpI32Sub    = 0x6b
	OpI32Mul    = 0x6c
	OpI32DivS   = 0x6d
	OpI32DivU   = 0x6e
	OpI32RemS   = 0x6f
	OpI32RemU   = 0x70
	OpI32And    = 0x71
	OpI32Or     = 0x72
	OpI32Xor    = 0x73
	OpI32Shl    = 0x74
	OpI32ShrS   = 0x75
	OpI32ShrU   = 0x76
	OpI32Rotl   = 0x77
	OpI32Rotr   = 0x78

	OpI64Clz    = 0x79
	OpI64Ctz    = 0x7a
	OpI64Popcnt = 0x7b
	OpI64Add    = 0x7c
	OpI64Sub    = 0x7d
	OpI64Mul    = 0x7e
	OpI64DivS   = 0x7f
	OpI64DivU   = 0x80
	OpI64RemS   = 0x81
	OpI64RemU   = 0x82
	OpI64And    = 0x83
	OpI64Or     = 0x84
	OpI64Xor    = 0x85
	OpI64Shl    = 0x86
	OpI64ShrS   = 0x87
	OpI64ShrU   = 0x88
	OpI64Rotl   = 0x89
	OpI64Rotr   = 0x8a

	OpF32Abs      = 0x8b
	OpF32Neg      = 0x8c
	OpF32Ceil     = 0x8d
	OpF32Floor    = 0x8e
	OpF32Trunc    = 0x8f
	OpF32Nearest  = 0x90
	OpF32Sqrt     = 0x91
	OpF32Add      = 0x92
	OpF32Sub      = 0x93
	OpF32Mul      = 0x94
	OpF32Div      = 0x95
	OpF32Min      = 0x96
	OpF32Max      = 0x97
	OpF32Copysign = 0x98

	OpF64Abs      = 0x99
	OpF64Neg      = 0x9a
	OpF64Ceil     = 0x9b
	OpF64Floor    = 0x9c
	OpF64Trunc    = 0x9d
	OpF64Nearest  = 0x9e
	OpF64Sqrt     = 0x9f
	OpF64Add      = 0xa0
	OpF64Sub      = 0xa1
	OpF64Mul      = 0xa2
	OpF64Div      = 0xa3
	OpF64Min      = 0xa4
	OpF64Max      = 0xa5
	OpF64Copysign = 0xa6

	OpI32WrapI64        = 0xa7
	OpI32TruncF32S      = 0xa8
	OpI32TruncF32U      = 0xa9
	OpI32TruncF64S      = 0xaa
	OpI32TruncF64U      = 0xab
	OpI64ExtendI32S     = 0xac
	OpI64ExtendI32U     = 0xad
	OpI64TruncF32S      = 0xae
	OpI64TruncF32U      = 0xaf
	OpI64TruncF64S      = 0xb0
	OpI64TruncF64U      = 0xb1
	OpF32ConvertI32S    = 0xb2
	OpF32ConvertI32U    = 0xb3
	OpF32ConvertI64S    = 0xb4
	OpF32ConvertI64U    = 0xb5
	OpF32DemoteF64      = 0xb6
	OpF64ConvertI32S    = 0xb7
	OpF64ConvertI32U    = 0xb8
	OpF64ConvertI64S    = 0xb9
	OpF64ConvertI64U    = 0xba
	OpF64PromoteF32     = 0xbb
	OpI32ReinterpretF32 = 0xbc
	OpI64ReinterpretF64 = 0xbd
	OpF32ReinterpretI32 = 0xbe
	OpF64ReinterpretI64 = 0xbf

	OpI32Extend8S  = 0xc0
	OpI32Extend16S = 0xc1
	OpI64Extend8S  = 0xc2
	OpI64Extend16S = 0xc3
	OpI64Extend32S = 0xc4

	OpPrefix = 0xfc

	OpI32TruncSatF32S = 0
	OpI32TruncSatF32U = 1
	OpI32TruncSatF64S = 2
	OpI32TruncSatF64U = 3
	OpI64TruncSatF32S = 4
	OpI64TruncSatF32U = 5
	OpI64TruncSatF64S = 6
	OpI64TruncSatF64U = 7
)

Variables

View Source
var ErrInvalidInstruction = errors.New("wasm: invalid instruction")
View Source
var UnknownScope = unknownScope(0)
View Source
var UnknownTypes = []wasm.ValueType{}

Functions

func BlockType

func BlockType(typeidx uint32) uint64

func Encode

func Encode(w io.Writer, body []Instruction) error

Types

type Body

type Body struct {
	Instructions []Instruction
	Metrics      Metrics
}

func Decode

func Decode(body []byte, scope Scope, out []wasm.ValueType) (Body, error)

type Instruction

type Instruction struct {
	Opcode    byte   `json:"opcode"`
	Immediate uint64 `json:"immediate"`
	Labels    []int  `json:"labels"`
}

func Block

func Block(blockType ...uint64) Instruction

func Br

func Br(labelidx int) Instruction

func BrIf

func BrIf(labelidx int) Instruction

func BrTable

func BrTable(labelidx int, labelidxN ...int) Instruction

func Call

func Call(funcidx uint32) Instruction

func CallIndirect

func CallIndirect(tableidx uint32) Instruction

func Drop

func Drop() Instruction

func Else

func Else() Instruction

func End

func End() Instruction

func F32Abs

func F32Abs() Instruction

func F32Add

func F32Add() Instruction

func F32Ceil

func F32Ceil() Instruction

func F32Const

func F32Const(v float32) Instruction

func F32ConvertI32S

func F32ConvertI32S() Instruction

func F32ConvertI32U

func F32ConvertI32U() Instruction

func F32ConvertI64S

func F32ConvertI64S() Instruction

func F32ConvertI64U

func F32ConvertI64U() Instruction

func F32Copysign

func F32Copysign() Instruction

func F32DemoteF64

func F32DemoteF64() Instruction

func F32Div

func F32Div() Instruction

func F32Eq

func F32Eq() Instruction

func F32Floor

func F32Floor() Instruction

func F32Ge

func F32Ge() Instruction

func F32Gt

func F32Gt() Instruction

func F32Le

func F32Le() Instruction

func F32Load

func F32Load(offset, align uint32) Instruction

func F32Lt

func F32Lt() Instruction

func F32Max

func F32Max() Instruction

func F32Min

func F32Min() Instruction

func F32Mul

func F32Mul() Instruction

func F32Ne

func F32Ne() Instruction

func F32Nearest

func F32Nearest() Instruction

func F32Neg

func F32Neg() Instruction

func F32ReinterpretI32

func F32ReinterpretI32() Instruction

func F32Sqrt

func F32Sqrt() Instruction

func F32Store

func F32Store(offset, align uint32) Instruction

func F32Sub

func F32Sub() Instruction

func F32Trunc

func F32Trunc() Instruction

func F64Abs

func F64Abs() Instruction

func F64Add

func F64Add() Instruction

func F64Ceil

func F64Ceil() Instruction

func F64Const

func F64Const(v float64) Instruction

func F64ConvertI32S

func F64ConvertI32S() Instruction

func F64ConvertI32U

func F64ConvertI32U() Instruction

func F64ConvertI64S

func F64ConvertI64S() Instruction

func F64ConvertI64U

func F64ConvertI64U() Instruction

func F64Copysign

func F64Copysign() Instruction

func F64Div

func F64Div() Instruction

func F64Eq

func F64Eq() Instruction

func F64Floor

func F64Floor() Instruction

func F64Ge

func F64Ge() Instruction

func F64Gt

func F64Gt() Instruction

func F64Le

func F64Le() Instruction

func F64Load

func F64Load(offset, align uint32) Instruction

func F64Lt

func F64Lt() Instruction

func F64Max

func F64Max() Instruction

func F64Min

func F64Min() Instruction

func F64Mul

func F64Mul() Instruction

func F64Ne

func F64Ne() Instruction

func F64Nearest

func F64Nearest() Instruction

func F64Neg

func F64Neg() Instruction

func F64PromoteF32

func F64PromoteF32() Instruction

func F64ReinterpretI64

func F64ReinterpretI64() Instruction

func F64Sqrt

func F64Sqrt() Instruction

func F64Store

func F64Store(offset, align uint32) Instruction

func F64Sub

func F64Sub() Instruction

func F64Trunc

func F64Trunc() Instruction

func GlobalGet

func GlobalGet(globalidx uint32) Instruction

func GlobalSet

func GlobalSet(globalidx uint32) Instruction

func I32Add

func I32Add() Instruction

func I32And

func I32And() Instruction

func I32Clz

func I32Clz() Instruction

func I32Const

func I32Const(v int32) Instruction

func I32Ctz

func I32Ctz() Instruction

func I32DivS

func I32DivS() Instruction

func I32DivU

func I32DivU() Instruction

func I32Eq

func I32Eq() Instruction

func I32Eqz

func I32Eqz() Instruction

func I32Extend16S

func I32Extend16S() Instruction

func I32Extend8S

func I32Extend8S() Instruction

func I32GeS

func I32GeS() Instruction

func I32GeU

func I32GeU() Instruction

func I32GtS

func I32GtS() Instruction

func I32GtU

func I32GtU() Instruction

func I32LeS

func I32LeS() Instruction

func I32LeU

func I32LeU() Instruction

func I32Load

func I32Load(offset, align uint32) Instruction

func I32Load16S

func I32Load16S(offset, align uint32) Instruction

func I32Load16U

func I32Load16U(offset, align uint32) Instruction

func I32Load8S

func I32Load8S(offset, align uint32) Instruction

func I32Load8U

func I32Load8U(offset, align uint32) Instruction

func I32LtS

func I32LtS() Instruction

func I32LtU

func I32LtU() Instruction

func I32Mul

func I32Mul() Instruction

func I32Ne

func I32Ne() Instruction

func I32Or

func I32Or() Instruction

func I32Popcnt

func I32Popcnt() Instruction

func I32ReinterpretF32

func I32ReinterpretF32() Instruction

func I32RemS

func I32RemS() Instruction

func I32RemU

func I32RemU() Instruction

func I32Rotl

func I32Rotl() Instruction

func I32Rotr

func I32Rotr() Instruction

func I32Shl

func I32Shl() Instruction

func I32ShrS

func I32ShrS() Instruction

func I32ShrU

func I32ShrU() Instruction

func I32Store

func I32Store(offset, align uint32) Instruction

func I32Store16

func I32Store16(offset, align uint32) Instruction

func I32Store8

func I32Store8(offset, align uint32) Instruction

func I32Sub

func I32Sub() Instruction

func I32TruncF32S

func I32TruncF32S() Instruction

func I32TruncF32U

func I32TruncF32U() Instruction

func I32TruncF64S

func I32TruncF64S() Instruction

func I32TruncF64U

func I32TruncF64U() Instruction

func I32TruncSatF32S

func I32TruncSatF32S() Instruction

func I32TruncSatF32U

func I32TruncSatF32U() Instruction

func I32TruncSatF64S

func I32TruncSatF64S() Instruction

func I32TruncSatF64U

func I32TruncSatF64U() Instruction

func I32WrapI64

func I32WrapI64() Instruction

func I32Xor

func I32Xor() Instruction

func I64Add

func I64Add() Instruction

func I64And

func I64And() Instruction

func I64Clz

func I64Clz() Instruction

func I64Const

func I64Const(v int64) Instruction

func I64Ctz

func I64Ctz() Instruction

func I64DivS

func I64DivS() Instruction

func I64DivU

func I64DivU() Instruction

func I64Eq

func I64Eq() Instruction

func I64Eqz

func I64Eqz() Instruction

func I64Extend16S

func I64Extend16S() Instruction

func I64Extend32S

func I64Extend32S() Instruction

func I64Extend8S

func I64Extend8S() Instruction

func I64ExtendI32S

func I64ExtendI32S() Instruction

func I64ExtendI32U

func I64ExtendI32U() Instruction

func I64GeS

func I64GeS() Instruction

func I64GeU

func I64GeU() Instruction

func I64GtS

func I64GtS() Instruction

func I64GtU

func I64GtU() Instruction

func I64LeS

func I64LeS() Instruction

func I64LeU

func I64LeU() Instruction

func I64Load

func I64Load(offset, align uint32) Instruction

func I64Load16S

func I64Load16S(offset, align uint32) Instruction

func I64Load16U

func I64Load16U(offset, align uint32) Instruction

func I64Load32S

func I64Load32S(offset, align uint32) Instruction

func I64Load32U

func I64Load32U(offset, align uint32) Instruction

func I64Load8S

func I64Load8S(offset, align uint32) Instruction

func I64Load8U

func I64Load8U(offset, align uint32) Instruction

func I64LtS

func I64LtS() Instruction

func I64LtU

func I64LtU() Instruction

func I64Mul

func I64Mul() Instruction

func I64Ne

func I64Ne() Instruction

func I64Or

func I64Or() Instruction

func I64Popcnt

func I64Popcnt() Instruction

func I64ReinterpretF64

func I64ReinterpretF64() Instruction

func I64RemS

func I64RemS() Instruction

func I64RemU

func I64RemU() Instruction

func I64Rotl

func I64Rotl() Instruction

func I64Rotr

func I64Rotr() Instruction

func I64Shl

func I64Shl() Instruction

func I64ShrS

func I64ShrS() Instruction

func I64ShrU

func I64ShrU() Instruction

func I64Store

func I64Store(offset, align uint32) Instruction

func I64Store16

func I64Store16(offset, align uint32) Instruction

func I64Store32

func I64Store32(offset, align uint32) Instruction

func I64Store8

func I64Store8(offset, align uint32) Instruction

func I64Sub

func I64Sub() Instruction

func I64TruncF32S

func I64TruncF32S() Instruction

func I64TruncF32U

func I64TruncF32U() Instruction

func I64TruncF64S

func I64TruncF64S() Instruction

func I64TruncF64U

func I64TruncF64U() Instruction

func I64TruncSatF32S

func I64TruncSatF32S() Instruction

func I64TruncSatF32U

func I64TruncSatF32U() Instruction

func I64TruncSatF64S

func I64TruncSatF64S() Instruction

func I64TruncSatF64U

func I64TruncSatF64U() Instruction

func I64Xor

func I64Xor() Instruction

func If

func If(blockType ...uint64) Instruction

func LocalGet

func LocalGet(localidx uint32) Instruction

func LocalSet

func LocalSet(localidx uint32) Instruction

func LocalTee

func LocalTee(localidx uint32) Instruction

func Loop

func Loop(blockType ...uint64) Instruction

func MemoryGrow

func MemoryGrow() Instruction

func MemorySize

func MemorySize() Instruction

func Nop

func Nop() Instruction

func Return

func Return() Instruction

func Select

func Select() Instruction

func Unreachable

func Unreachable() Instruction

func (*Instruction) BlockType

func (i *Instruction) BlockType(scope Scope) (in, out []wasm.ValueType, ok bool)

func (*Instruction) Continuation

func (i *Instruction) Continuation() int

func (*Instruction) Decode

func (i *Instruction) Decode(r io.Reader) error

func (*Instruction) Default

func (i *Instruction) Default() int

func (*Instruction) Else

func (i *Instruction) Else() int

func (*Instruction) Encode

func (i *Instruction) Encode(w io.Writer) error

func (*Instruction) F32

func (i *Instruction) F32() float32

func (*Instruction) F64

func (i *Instruction) F64() float64

func (*Instruction) Funcidx

func (i *Instruction) Funcidx() uint32

func (*Instruction) Globalidx

func (i *Instruction) Globalidx() uint32

func (*Instruction) I32

func (i *Instruction) I32() int32

func (*Instruction) I64

func (i *Instruction) I64() int64

func (*Instruction) Labelidx

func (i *Instruction) Labelidx() int

func (*Instruction) Localidx

func (i *Instruction) Localidx() uint32

func (*Instruction) Memarg

func (i *Instruction) Memarg() (offset uint32, align uint32)

func (*Instruction) Offset

func (i *Instruction) Offset() uint32

func (*Instruction) OpString

func (i *Instruction) OpString() string

func (*Instruction) Stack

func (i *Instruction) Stack(scope Scope) (pop, push int)

func (*Instruction) StackHeight

func (i *Instruction) StackHeight() int

func (*Instruction) String

func (i *Instruction) String() string

func (*Instruction) Typeidx

func (i *Instruction) Typeidx() uint32

func (*Instruction) Types

func (i *Instruction) Types(scope Scope) (pop, push []wasm.ValueType)

type Metrics

type Metrics struct {
	MaxNesting    int  // The maximum block nesting for the function.
	MaxStackDepth int  // The maximum stack depth for the function.
	LabelCount    int  // The number of labels in the function.
	HasLoops      bool // True if this function has loops
}

type Scope

type Scope interface {
	GetLocalType(localidx uint32) (wasm.ValueType, bool)
	GetGlobalType(globalidx uint32) (wasm.GlobalVar, bool)
	GetFunctionSignature(funcidx uint32) (wasm.FunctionSig, bool)
	GetType(typeidx uint32) (wasm.FunctionSig, bool)

	HasTable(tableidx uint32) bool
	HasMemory(memoryidx uint32) bool
}

type StaticScope

type StaticScope struct {
	ImportedFunctions []uint32
	ImportedGlobals   []wasm.GlobalVar

	Tables   int
	Memories int

	Locals []wasm.ValueType
	// contains filtered or unexported fields
}

func NewStaticScope

func NewStaticScope(m *wasm.Module) *StaticScope

func (*StaticScope) GetFunctionSignature

func (s *StaticScope) GetFunctionSignature(funcidx uint32) (wasm.FunctionSig, bool)

func (*StaticScope) GetGlobalType

func (s *StaticScope) GetGlobalType(globalidx uint32) (wasm.GlobalVar, bool)

func (*StaticScope) GetLocalType

func (s *StaticScope) GetLocalType(localidx uint32) (wasm.ValueType, bool)

func (*StaticScope) GetType

func (s *StaticScope) GetType(typeidx uint32) (wasm.FunctionSig, bool)

func (*StaticScope) HasMemory

func (s *StaticScope) HasMemory(memoryidx uint32) bool

func (*StaticScope) HasTable

func (s *StaticScope) HasTable(tableidx uint32) bool

func (*StaticScope) SetFunction

func (s *StaticScope) SetFunction(sig wasm.FunctionSig, body wasm.FunctionBody)

Jump to

Keyboard shortcuts

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