visitor

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const AnyOpcode = isa.OpcodeMask + 1

Variables

This section is empty.

Functions

func DepthFirst

func DepthFirst(root Node, visitor Visitor)

DepthFirst performs a depth-first visitation

func Replace

func Replace(root Node, pattern Pattern, mapper Mapper)

Replace visits all Instruction nodes and if any of the instructions therein match the provided Pattern, they will be replaced using the provided Mapper

Types

type Branches

type Branches interface {
	Node
	Prologue() Instructions
	ThenBranch() Node
	ElseBranch() Node
	Epilogue() Node
}

Branches represent a branching junction

type Instructions

type Instructions interface {
	Node
	Set(isa.Instructions)
}

Instructions represent a series of non-branching instructions

type Mapper

type Mapper func(isa.Instructions) isa.Instructions

Mapper maps one set of instructions to another

type Node

type Node interface {
	Code() isa.Instructions
}

A Node is returned when a Branch analysis is performed

func Branch

func Branch(code isa.Instructions) Node

Branch splits linear instructions into a tree of conditional branches

type Pattern

type Pattern [][]isa.Opcode

Pattern is a replacement pattern for the visitor. The second level of the array identifies the possible matching Opcodes, while the first level identifies the sequence in which they should appear

type Visitor

type Visitor interface {
	EnterRoot(Node)
	ExitRoot(Node)
	EnterBranches(Branches)
	ExitBranches(Branches)
	Instructions(Instructions)
}

Visitor is an interface called back upon visiting

Jump to

Keyboard shortcuts

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