instructions

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package instruction contains the handlers for specific groups of instructions. Each instruction object knows how to process itself in the context of some executors that work on instructions like WasmReader, WasmWriter, WasmAnalyzer, and WasmRunner.

Externally each instruction is seen through a simple Instruction interface. Internally they are seen through the instruction.ctxInstruction interface, which provides the extra interface methods each object needs to be handled by their corresponding executor. In addition each instruction object contains a Base object that provides common methods and fields for each instruction.

The following instruction groups are defined:

Binary  - operate on 2 same-type arguments and return a result of that same type.
Block   - block type pseudo-instructions (block, loop, and if)
Bool    - compare 2 same-type arguments and return a boolean (i32) type.
Branch  - branching instructions (br, br_if, and br_table, return).
Call    - function call instructions (call, call_indirect, memory.grow, and memory.size).
Const   - define constant values (const.i32, const.i64, const.f32, and const.f64).
Convert - convert from one type to another type
Mem     - access memory locations (load and store).
Unary   - operate on 1 argument and return a result of the same type as the argument.
Var     - get or set local or global variables.

Misc    - the few remaining instructions that fall outside the above groups.
          (unreachable, nop, else, end, drop, select)

Index

Constants

View Source
const BLOCK_EMPTY = int32(-0x40)

Variables

View Source
var Operations [256]Operation

Functions

func AnalyzeBlock

func AnalyzeBlock(a *context.Analyzer)

func CreateInstruction

func CreateInstruction(opcode byte) helper.Instruction

func NewBinary

func NewBinary() helper.Instruction

func NewBlock

func NewBlock() helper.Instruction

func NewBool

func NewBool() helper.Instruction

func NewBranch

func NewBranch() helper.Instruction

func NewCall

func NewCall() helper.Instruction

func NewConst

func NewConst() helper.Instruction

func NewConvert

func NewConvert() helper.Instruction

func NewMem

func NewMem() helper.Instruction

func NewMisc

func NewMisc() helper.Instruction

func NewUnary

func NewUnary() helper.Instruction

func NewVar

func NewVar() helper.Instruction

func ReadBlock

func ReadBlock(r *context.Reader) []helper.Instruction

func RunBlock

func RunBlock(vm *Runner, block []helper.Instruction) error

func WriteBlock

func WriteBlock(w *context.Writer, block []helper.Instruction)

Types

type Base

type Base struct {
	IP int
	SP int
	// contains filtered or unexported fields
}

Base implements basic behavior for all Instruction types. This class is not to be instantiated by itself. Use one of the concrete instruction types instead.

func (*Base) Analyze

func (o *Base) Analyze(_ *context.Analyzer)

func (*Base) GetIP

func (o *Base) GetIP() int

func (*Base) Mnemonic

func (o *Base) Mnemonic() string

func (*Base) Opcode

func (o *Base) Opcode() byte

func (*Base) Read

func (o *Base) Read(_ *context.Reader)

func (*Base) Run

func (o *Base) Run(vm *Runner)

func (*Base) StackChange

func (o *Base) StackChange() int

func (*Base) String

func (o *Base) String() string

func (*Base) Write

func (o *Base) Write(_ *context.Writer)

type Binary

type Binary struct {
	Base
}

type Block

type Block struct {
	Base
	// contains filtered or unexported fields
}

func (*Block) Analyze

func (o *Block) Analyze(a *context.Analyzer)

func (*Block) Read

func (o *Block) Read(r *context.Reader)

func (*Block) String

func (o *Block) String() string

func (*Block) Write

func (o *Block) Write(w *context.Writer)

type Bool

type Bool struct {
	Base
}

type Branch

type Branch struct {
	Base
	// contains filtered or unexported fields
}

func (*Branch) Analyze

func (o *Branch) Analyze(a *context.Analyzer)

func (*Branch) Read

func (o *Branch) Read(r *context.Reader)

func (*Branch) String

func (o *Branch) String() string

func (*Branch) Write

func (o *Branch) Write(w *context.Writer)

type Call

type Call struct {
	Base
	// contains filtered or unexported fields
}

func (*Call) Analyze

func (o *Call) Analyze(a *context.Analyzer)

func (*Call) Index added in v0.2.0

func (o *Call) Index() uint32

func (*Call) Read

func (o *Call) Read(r *context.Reader)

func (*Call) Run

func (o *Call) Run(vm *Runner)

func (*Call) StackChange

func (o *Call) StackChange() int

func (*Call) String

func (o *Call) String() string

func (*Call) Write

func (o *Call) Write(w *context.Writer)

type Const

type Const struct {
	Base
	Value sections.Variable
}

func (*Const) DataType

func (o *Const) DataType() value.DataType

func (*Const) Read

func (o *Const) Read(r *context.Reader)

func (*Const) String

func (o *Const) String() string

func (*Const) Write

func (o *Const) Write(w *context.Writer)

type Convert

type Convert struct {
	Base
}

type Mem

type Mem struct {
	Base
	// contains filtered or unexported fields
}

func (*Mem) Analyze

func (o *Mem) Analyze(a *context.Analyzer)

func (*Mem) Read

func (o *Mem) Read(r *context.Reader)

func (*Mem) String

func (o *Mem) String() string

func (*Mem) Write

func (o *Mem) Write(w *context.Writer)

type Misc

type Misc struct {
	Base
}

func (*Misc) Analyze

func (o *Misc) Analyze(a *context.Analyzer)

func (*Misc) StackChange

func (o *Misc) StackChange() int

type Operation

type Operation struct {
	Factory     func() helper.Instruction
	Mnemonic    string
	Result      value.DataType
	Arg1        value.DataType
	Arg2        value.DataType
	Align       byte
	StackChange int
}

func (*Operation) NewSignature

func (s *Operation) NewSignature(mnemonic string, result value.DataType, arg1 value.DataType, arg2 value.DataType, factory func() helper.Instruction)

type Runner

type Runner = context.Runner

type Unary

type Unary struct {
	Base
}

type Var

type Var struct {
	Base
	Index uint32
	// contains filtered or unexported fields
}

func (*Var) Analyze

func (o *Var) Analyze(a *context.Analyzer)

func (*Var) Read

func (o *Var) Read(r *context.Reader)

func (*Var) String

func (o *Var) String() string

func (*Var) Write

func (o *Var) Write(w *context.Writer)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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