wazeroir

package
v0.0.0-...-29e2939 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package wazeroir is a pkg to compile down the standard Wasm binary to wazero's specific IR (wazeroir). The wazeroir is inspired by microwasm format (a.k.a. LightbeamIR), previously used in the lightbeam JIT compiler in Wasmtime, though it is not specified and only exists in the previous codebase of wasmtime e.g. https://github.com/bytecodealliance/wasmtime/blob/v0.29.0/crates/lightbeam/src/microwasm.rs

See RATIONALE.md for detail.

Index

Constants

View Source
const EntrypointLabel = ".entrypoint"

Variables

This section is empty.

Functions

func Format

func Format(ops []Operation) string

Types

type BranchTarget

type BranchTarget struct {
	Label *Label
}

func (*BranchTarget) IsReturnTarget

func (b *BranchTarget) IsReturnTarget() bool

func (*BranchTarget) String

func (b *BranchTarget) String() (ret string)

type BranchTargetDrop

type BranchTargetDrop struct {
	Target *BranchTarget
	ToDrop *InclusiveRange
}

func (*BranchTargetDrop) String

func (b *BranchTargetDrop) String() (ret string)

type CompilationResult

type CompilationResult struct {
	// Operations holds wazeroir operations compiled from Wasm instructions in a Wasm function.
	Operations []Operation
	// LabelCallers maps Label.String() to the number of callers to that label.
	// Here "callers" means that the call-sites which jumps to the label with br, br_if or br_table
	// instructions.
	//
	// Note: zero possible and allowed in wasm. Ex.
	//
	//	(block
	//	  (br 0)
	//	  (block i32.const 1111)
	//	)
	//
	// This example the label corresponding to `(block i32.const 1111)` is never be reached at runtime because `br 0` exits the function before we reach there
	LabelCallers map[string]uint32
}

func Compile

Compile lowers given function instance into wazeroir operations so that the resulting operations can be consumed by the interpreter or the JIT compilation engine.

type Float

type Float byte
const (
	Float32 Float = iota
	Float64
)

func (Float) String

func (s Float) String() (ret string)

type InclusiveRange

type InclusiveRange struct {
	Start, End int
}

type Label

type Label struct {
	FrameID          uint32
	OriginalStackLen int
	Kind             LabelKind
}

func (*Label) String

func (l *Label) String() (ret string)

type LabelKind

type LabelKind = byte
const (
	LabelKindHeader LabelKind = iota
	LabelKindElse
	LabelKindContinuation
)

type MemoryImmediate

type MemoryImmediate struct {
	Alignment, Offset uint32
}

type Operation

type Operation interface {
	Kind() OperationKind
}

type OperationAbs

type OperationAbs struct{ Type Float }

func (*OperationAbs) Kind

func (o *OperationAbs) Kind() OperationKind

type OperationAdd

type OperationAdd struct{ Type UnsignedType }

func (*OperationAdd) Kind

func (o *OperationAdd) Kind() OperationKind

type OperationAnd

type OperationAnd struct{ Type UnsignedInt }

func (*OperationAnd) Kind

func (o *OperationAnd) Kind() OperationKind

type OperationBr

type OperationBr struct {
	Target *BranchTarget
}

func (*OperationBr) Kind

func (o *OperationBr) Kind() OperationKind

type OperationBrIf

type OperationBrIf struct {
	Then, Else *BranchTargetDrop
}

func (*OperationBrIf) Kind

func (o *OperationBrIf) Kind() OperationKind

type OperationBrTable

type OperationBrTable struct {
	Targets []*BranchTargetDrop
	Default *BranchTargetDrop
}

func (*OperationBrTable) Kind

func (o *OperationBrTable) Kind() OperationKind

type OperationCall

type OperationCall struct {
	FunctionIndex uint32
}

func (*OperationCall) Kind

func (o *OperationCall) Kind() OperationKind

type OperationCallIndirect

type OperationCallIndirect struct {
	TypeIndex, TableIndex uint32
}

func (*OperationCallIndirect) Kind

type OperationCeil

type OperationCeil struct{ Type Float }

func (*OperationCeil) Kind

func (o *OperationCeil) Kind() OperationKind

type OperationClz

type OperationClz struct{ Type UnsignedInt }

func (*OperationClz) Kind

func (o *OperationClz) Kind() OperationKind

type OperationConstF32

type OperationConstF32 struct{ Value float32 }

func (*OperationConstF32) Kind

func (o *OperationConstF32) Kind() OperationKind

type OperationConstF64

type OperationConstF64 struct{ Value float64 }

func (*OperationConstF64) Kind

func (o *OperationConstF64) Kind() OperationKind

type OperationConstI32

type OperationConstI32 struct{ Value uint32 }

func (*OperationConstI32) Kind

func (o *OperationConstI32) Kind() OperationKind

type OperationConstI64

type OperationConstI64 struct{ Value uint64 }

func (*OperationConstI64) Kind

func (o *OperationConstI64) Kind() OperationKind

type OperationCopysign

type OperationCopysign struct{ Type Float }

func (*OperationCopysign) Kind

func (o *OperationCopysign) Kind() OperationKind

type OperationCtz

type OperationCtz struct{ Type UnsignedInt }

func (*OperationCtz) Kind

func (o *OperationCtz) Kind() OperationKind

type OperationDiv

type OperationDiv struct{ Type SignedType }

func (*OperationDiv) Kind

func (o *OperationDiv) Kind() OperationKind

type OperationDrop

type OperationDrop struct{ Range *InclusiveRange }

func (*OperationDrop) Kind

func (o *OperationDrop) Kind() OperationKind

type OperationEq

type OperationEq struct{ Type UnsignedType }

func (*OperationEq) Kind

func (o *OperationEq) Kind() OperationKind

type OperationEqz

type OperationEqz struct{ Type UnsignedInt }

func (*OperationEqz) Kind

func (o *OperationEqz) Kind() OperationKind

type OperationExtend

type OperationExtend struct{ Signed bool }

func (*OperationExtend) Kind

func (o *OperationExtend) Kind() OperationKind

type OperationF32DemoteFromF64

type OperationF32DemoteFromF64 struct{}

func (*OperationF32DemoteFromF64) Kind

type OperationF32ReinterpretFromI32

type OperationF32ReinterpretFromI32 struct{}

func (*OperationF32ReinterpretFromI32) Kind

type OperationF64PromoteFromF32

type OperationF64PromoteFromF32 struct{}

func (*OperationF64PromoteFromF32) Kind

type OperationF64ReinterpretFromI64

type OperationF64ReinterpretFromI64 struct{}

func (*OperationF64ReinterpretFromI64) Kind

type OperationFConvertFromI

type OperationFConvertFromI struct {
	InputType  SignedInt
	OutputType Float
}

func (*OperationFConvertFromI) Kind

type OperationFloor

type OperationFloor struct{ Type Float }

func (*OperationFloor) Kind

func (o *OperationFloor) Kind() OperationKind

type OperationGe

type OperationGe struct{ Type SignedType }

func (*OperationGe) Kind

func (o *OperationGe) Kind() OperationKind

type OperationGlobalGet

type OperationGlobalGet struct{ Index uint32 }

func (*OperationGlobalGet) Kind

type OperationGlobalSet

type OperationGlobalSet struct{ Index uint32 }

func (*OperationGlobalSet) Kind

type OperationGt

type OperationGt struct{ Type SignedType }

func (*OperationGt) Kind

func (o *OperationGt) Kind() OperationKind

type OperationI32ReinterpretFromF32

type OperationI32ReinterpretFromF32 struct{}

func (*OperationI32ReinterpretFromF32) Kind

type OperationI32WrapFromI64

type OperationI32WrapFromI64 struct{}

func (*OperationI32WrapFromI64) Kind

type OperationI64ReinterpretFromF64

type OperationI64ReinterpretFromF64 struct{}

func (*OperationI64ReinterpretFromF64) Kind

type OperationITruncFromF

type OperationITruncFromF struct {
	InputType  Float
	OutputType SignedInt
}

func (*OperationITruncFromF) Kind

type OperationKind

type OperationKind byte
const (
	OperationKindUnreachable OperationKind = iota
	OperationKindLabel
	OperationKindBr
	OperationKindBrIf
	OperationKindBrTable
	OperationKindCall
	OperationKindCallIndirect
	OperationKindDrop
	OperationKindSelect
	OperationKindPick
	OperationKindSwap
	OperationKindGlobalGet
	OperationKindGlobalSet
	OperationKindLoad
	OperationKindLoad8
	OperationKindLoad16
	OperationKindLoad32
	OperationKindStore
	OperationKindStore8
	OperationKindStore16
	OperationKindStore32
	OperationKindMemorySize
	OperationKindMemoryGrow
	OperationKindConstI32
	OperationKindConstI64
	OperationKindConstF32
	OperationKindConstF64
	OperationKindEq
	OperationKindNe
	OperationKindEqz
	OperationKindLt
	OperationKindGt
	OperationKindLe
	OperationKindGe
	OperationKindAdd
	OperationKindSub
	OperationKindMul
	OperationKindClz
	OperationKindCtz
	OperationKindPopcnt
	OperationKindDiv
	OperationKindRem
	OperationKindAnd
	OperationKindOr
	OperationKindXor
	OperationKindShl
	OperationKindShr
	OperationKindRotl
	OperationKindRotr
	OperationKindAbs
	OperationKindNeg
	OperationKindCeil
	OperationKindFloor
	OperationKindTrunc
	OperationKindNearest
	OperationKindSqrt
	OperationKindMin
	OperationKindMax
	OperationKindCopysign
	OperationKindI32WrapFromI64
	OperationKindITruncFromF
	OperationKindFConvertFromI
	OperationKindF32DemoteFromF64
	OperationKindF64PromoteFromF32
	OperationKindI32ReinterpretFromF32
	OperationKindI64ReinterpretFromF64
	OperationKindF32ReinterpretFromI32
	OperationKindF64ReinterpretFromI64
	OperationKindExtend
	OperationKindSignExtend32From8
	OperationKindSignExtend32From16
	OperationKindSignExtend64From8
	OperationKindSignExtend64From16
	OperationKindSignExtend64From32
)

func (OperationKind) String

func (o OperationKind) String() (ret string)

type OperationLabel

type OperationLabel struct {
	Label *Label
}

func (*OperationLabel) Kind

func (o *OperationLabel) Kind() OperationKind

type OperationLe

type OperationLe struct{ Type SignedType }

func (*OperationLe) Kind

func (o *OperationLe) Kind() OperationKind

type OperationLoad

type OperationLoad struct {
	Type UnsignedType
	Arg  *MemoryImmediate
}

func (*OperationLoad) Kind

func (o *OperationLoad) Kind() OperationKind

type OperationLoad16

type OperationLoad16 struct {
	Type SignedInt
	Arg  *MemoryImmediate
}

func (*OperationLoad16) Kind

func (o *OperationLoad16) Kind() OperationKind

type OperationLoad32

type OperationLoad32 struct {
	Signed bool
	Arg    *MemoryImmediate
}

func (*OperationLoad32) Kind

func (o *OperationLoad32) Kind() OperationKind

type OperationLoad8

type OperationLoad8 struct {
	Type SignedInt
	Arg  *MemoryImmediate
}

func (*OperationLoad8) Kind

func (o *OperationLoad8) Kind() OperationKind

type OperationLt

type OperationLt struct{ Type SignedType }

func (*OperationLt) Kind

func (o *OperationLt) Kind() OperationKind

type OperationMax

type OperationMax struct{ Type Float }

func (*OperationMax) Kind

func (o *OperationMax) Kind() OperationKind

type OperationMemoryGrow

type OperationMemoryGrow struct{ Alignment uint64 }

func (*OperationMemoryGrow) Kind

type OperationMemorySize

type OperationMemorySize struct{}

func (*OperationMemorySize) Kind

type OperationMin

type OperationMin struct{ Type Float }

func (*OperationMin) Kind

func (o *OperationMin) Kind() OperationKind

type OperationMul

type OperationMul struct{ Type UnsignedType }

func (*OperationMul) Kind

func (o *OperationMul) Kind() OperationKind

type OperationNe

type OperationNe struct{ Type UnsignedType }

func (*OperationNe) Kind

func (o *OperationNe) Kind() OperationKind

type OperationNearest

type OperationNearest struct{ Type Float }

func (*OperationNearest) Kind

func (o *OperationNearest) Kind() OperationKind

type OperationNeg

type OperationNeg struct{ Type Float }

func (*OperationNeg) Kind

func (o *OperationNeg) Kind() OperationKind

type OperationOr

type OperationOr struct{ Type UnsignedInt }

func (*OperationOr) Kind

func (o *OperationOr) Kind() OperationKind

type OperationPick

type OperationPick struct{ Depth int }

func (*OperationPick) Kind

func (o *OperationPick) Kind() OperationKind

type OperationPopcnt

type OperationPopcnt struct{ Type UnsignedInt }

func (*OperationPopcnt) Kind

func (o *OperationPopcnt) Kind() OperationKind

type OperationRem

type OperationRem struct{ Type SignedInt }

func (*OperationRem) Kind

func (o *OperationRem) Kind() OperationKind

type OperationRotl

type OperationRotl struct{ Type UnsignedInt }

func (*OperationRotl) Kind

func (o *OperationRotl) Kind() OperationKind

type OperationRotr

type OperationRotr struct{ Type UnsignedInt }

func (*OperationRotr) Kind

func (o *OperationRotr) Kind() OperationKind

type OperationSelect

type OperationSelect struct{}

func (*OperationSelect) Kind

func (o *OperationSelect) Kind() OperationKind

type OperationShl

type OperationShl struct{ Type UnsignedInt }

func (*OperationShl) Kind

func (o *OperationShl) Kind() OperationKind

type OperationShr

type OperationShr struct{ Type SignedInt }

func (*OperationShr) Kind

func (o *OperationShr) Kind() OperationKind

type OperationSignExtend32From16

type OperationSignExtend32From16 struct{}

func (*OperationSignExtend32From16) Kind

type OperationSignExtend32From8

type OperationSignExtend32From8 struct{}

func (*OperationSignExtend32From8) Kind

type OperationSignExtend64From16

type OperationSignExtend64From16 struct{}

func (*OperationSignExtend64From16) Kind

type OperationSignExtend64From32

type OperationSignExtend64From32 struct{}

func (*OperationSignExtend64From32) Kind

type OperationSignExtend64From8

type OperationSignExtend64From8 struct{}

func (*OperationSignExtend64From8) Kind

type OperationSqrt

type OperationSqrt struct{ Type Float }

func (*OperationSqrt) Kind

func (o *OperationSqrt) Kind() OperationKind

type OperationStore

type OperationStore struct {
	Type UnsignedType
	Arg  *MemoryImmediate
}

func (*OperationStore) Kind

func (o *OperationStore) Kind() OperationKind

type OperationStore16

type OperationStore16 struct {
	// TODO: Semantically Type doesn't affect operation so consider deleting this field.
	Type UnsignedInt
	Arg  *MemoryImmediate
}

func (*OperationStore16) Kind

func (o *OperationStore16) Kind() OperationKind

type OperationStore32

type OperationStore32 struct {
	Arg *MemoryImmediate
}

func (*OperationStore32) Kind

func (o *OperationStore32) Kind() OperationKind

type OperationStore8

type OperationStore8 struct {
	// TODO: Semantically Type doesn't affect operation so consider deleting this field.
	Type UnsignedInt
	Arg  *MemoryImmediate
}

func (*OperationStore8) Kind

func (o *OperationStore8) Kind() OperationKind

type OperationSub

type OperationSub struct{ Type UnsignedType }

func (*OperationSub) Kind

func (o *OperationSub) Kind() OperationKind

type OperationSwap

type OperationSwap struct{ Depth int }

func (*OperationSwap) Kind

func (o *OperationSwap) Kind() OperationKind

type OperationTrunc

type OperationTrunc struct{ Type Float }

func (*OperationTrunc) Kind

func (o *OperationTrunc) Kind() OperationKind

type OperationUnreachable

type OperationUnreachable struct{}

func (*OperationUnreachable) Kind

type OperationXor

type OperationXor struct{ Type UnsignedInt }

func (*OperationXor) Kind

func (o *OperationXor) Kind() OperationKind

type SignedInt

type SignedInt byte
const (
	SignedInt32 SignedInt = iota
	SignedInt64
	SignedUint32
	SignedUint64
)

func (SignedInt) String

func (s SignedInt) String() (ret string)

type SignedType

type SignedType byte
const (
	SignedTypeInt32 SignedType = iota
	SignedTypeUint32
	SignedTypeInt64
	SignedTypeUint64
	SignedTypeFloat32
	SignedTypeFloat64
)

func (SignedType) String

func (s SignedType) String() (ret string)

type UnsignedInt

type UnsignedInt byte
const (
	UnsignedInt32 UnsignedInt = iota
	UnsignedInt64
)

func (UnsignedInt) String

func (s UnsignedInt) String() (ret string)

type UnsignedType

type UnsignedType byte
const (
	UnsignedTypeI32 UnsignedType = iota
	UnsignedTypeI64
	UnsignedTypeF32
	UnsignedTypeF64
	UnsignedTypeUnknown
)

func (UnsignedType) String

func (s UnsignedType) String() (ret string)

Jump to

Keyboard shortcuts

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