disasm

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: LGPL-3.0, BSD-3-Clause Imports: 12 Imported by: 0

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")
View Source
var PrintDebugInfo = false

Functions

This section is empty.

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
	// The index to the accompanying control operator.
	// For 'if', this is an index to the 'else' operator
	// For else/loop/block, the index is to the 'end' operator
	PairIndex 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 Disassemble

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

Disassemble 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).

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 unwinded by an instruction.

Jump to

Keyboard shortcuts

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