disasm

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2019 License: BSD-3-Clause Imports: 12 Imported by: 15 modules, 20 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package disasm provides functions for disassembling WebAssembly bytecode.

Index

Constants

This section is empty.

Variables

View Source
var ErrStackUnderflow = errors.New("disasm: stack underflow")

Functions

func Assemble

func Assemble(instr []Instr) ([]byte, error)

Assemble encodes a set of instructions into binary representation.

func SetDebugMode

func SetDebugMode(l bool)

Types

type BlockInfo

type BlockInfo struct {
	Start     bool           // If true, this instruction starts a block. Else this instruction ends it.
	Signature wasm.BlockType // The block signature

	// Indices to the accompanying control operator.
	// For 'if', this is the index to the 'else' operator.
	IfElseIndex int
	// For 'else', this is the index to the 'if' operator.
	ElseIfIndex int
	// The index to the `end' operator for if/else/loop/block.
	EndIndex int
	// For end, it is the index to the operator that starts the block.
	BlockStartIndex int
}

BlockInfo stores details about a block created or ended by an instruction.

type Disassembly

type Disassembly struct {
	Code     []Instr
	MaxDepth int // The maximum stack depth that can be reached while executing this function
}

Disassembly is the result of disassembling a WebAssembly function.

func NewDisassembly added in v0.6.0

func NewDisassembly(fn wasm.Function, module *wasm.Module) (*Disassembly, error)

NewDisassembly disassembles the given function. It also takes the function's parent module as an argument for locating any other functions referenced by fn.

type Instr

type Instr struct {
	Op ops.Op

	// Immediates are arguments to an operator in the bytecode stream itself.
	// Valid value types are:
	// - (u)(int/float)(32/64)
	// - wasm.BlockType
	Immediates  []interface{}
	NewStack    *StackInfo // non-nil if the instruction creates or unwinds a stack.
	Block       *BlockInfo // non-nil if the instruction starts or ends a new block.
	Unreachable bool       // whether the operator can be reached during execution
	// IsReturn is true if executing this instruction will result in the
	// function returning. This is true for branches (br, br_if) to
	// the depth <max_relative_depth> + 1, or the return operator itself.
	// If true, NewStack for this instruction is nil.
	IsReturn bool
	// If the operator is br_table (ops.BrTable), this is a list of StackInfo
	// fields for each of the blocks/branches referenced by the operator.
	Branches []StackInfo
}

Instr describes an instruction, consisting of an operator, with its appropriate immediate value(s).

func Disassemble

func Disassemble(code []byte) ([]Instr, error)

Disassemble disassembles a given function body into a set of instructions. It won't check operations for validity.

type StackInfo

type StackInfo struct {
	StackTopDiff int64 // The difference between the stack depths at the end of the block
	PreserveTop  bool  // Whether the value on the top of the stack should be preserved while unwinding
	IsReturn     bool  // Whether the unwind is equivalent to a return
}

StackInfo stores details about a new stack created or unwound by an instruction.

Jump to

Keyboard shortcuts

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