compiler

package
v0.0.0-...-f0a1fc9 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2019 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicBlock

type BasicBlock struct {
	Code       []Instr   // Block instruction
	JmpKind    TyJmpKind // Block jmp (if any)
	JmpTargets []int     // Block jmp target (if any)

	JmpCond    TyValueID // Block jmp condition (if any)
	YieldValue TyValueID // Block yield value
}

BasicBlock - cf block struct

type CFGraph

type CFGraph struct {
	Blocks []BasicBlock // Blocks
}

CFGraph - cf graph struct

func (*CFGraph) ToInsSeq

func (g *CFGraph) ToInsSeq() []Instr

ToInsSeq - convert given cfGraph to instruction set

type FixupInfo

type FixupInfo struct {
	CodePos  int // Bytecode position
	TablePos int // Table position
}

FixupInfo - fixup info

type GasPolicy

type GasPolicy interface {
	GetCost(key string) int64 // Get gas cost
}

GasPolicy - gas policy

type Instr

type Instr struct {
	Target TyValueID // the value id we are assigning to

	Op         string      // Operation
	Immediates []int64     // Immediate values
	Values     []TyValueID // Value
}

Instr - single instrution

type InterpreterCode

type InterpreterCode struct {
	NumRegs    int // Reg count
	NumParams  int // Param count
	NumLocals  int // Local vars count
	NumReturns int // Returns count

	Bytes   []byte      // Byte val
	JITInfo interface{} // Just-in-time meta
	JITDone bool        // Finished just-in-time compilation
}

InterpreterCode - interpreter metadata

type Location

type Location struct {
	CodePos         int         // Pos
	StackDepth      int         // Stack depth
	BrHead          bool        // true for loops
	PreserveTop     bool        // Should preserve
	LoopPreserveTop bool        // Loop preserve
	FixupList       []FixupInfo // Fixups

	IfBlock bool // No clue
}

Location - location

type Module

type Module struct {
	Base                 *wasm.Module   `json:"-"` // Base parsed module
	FunctionNames        map[int]string // Module functions
	DisableFloatingPoint bool           // Config to disable float ops
	Identifier           []byte         `json:"ID"` // Unique module identifier
}

Module - wasm module

func LoadModule

func LoadModule(moduleBytes []byte) (*Module, error)

LoadModule - load WASM raw bytes module

func (*Module) CompileForInterpreter

func (module *Module) CompileForInterpreter(gp GasPolicy) (_retCode []InterpreterCode, retErr error)

CompileForInterpreter - compile given WASM bytecode for interpreter

func (*Module) String

func (module *Module) String() string

String - module stringer

type SSAFunctionCompiler

type SSAFunctionCompiler struct {
	Module *wasm.Module        // Wasm module
	Source *disasm.Disassembly // Wasm source

	Code      []Instr     // Instruction set
	Stack     []TyValueID // Stack
	Locations []*Location // Locations

	CallIndexOffset int // Call index offset

	StackValueSets map[int][]TyValueID    // Stack values
	UsedValueIDs   map[TyValueID]struct{} // Value IDs

	ValueID TyValueID // ValueID
}

SSAFunctionCompiler represents a compiler which translates a WebAssembly modules interpreted code into a Static-Single-Assignment-based intermediate representation.

func NewSSAFunctionCompiler

func NewSSAFunctionCompiler(m *wasm.Module, d *disasm.Disassembly) *SSAFunctionCompiler

NewSSAFunctionCompiler instantiates a compiler which translates a WebAssembly modules interpreted code into a Static-Single-Assignment-based intermediate representation.

func (*SSAFunctionCompiler) Compile

func (c *SSAFunctionCompiler) Compile(importTypeIDs []int)

Compile compiles an interpreted WebAssembly modules source code into a Static-Single-Assignment-based intermediate representation.

func (*SSAFunctionCompiler) FilterFloatingPoint

func (c *SSAFunctionCompiler) FilterFloatingPoint()

FilterFloatingPoint - handle disableFloatingPoint param

func (*SSAFunctionCompiler) FixupLocationRef

func (c *SSAFunctionCompiler) FixupLocationRef(loc *Location, wasUnreachable bool)

FixupLocationRef - fix location ref

func (*SSAFunctionCompiler) InsertGasCounters

func (c *SSAFunctionCompiler) InsertGasCounters(gp GasPolicy)

InsertGasCounters - insert gas counter to given wasm

func (*SSAFunctionCompiler) NewCFGraph

func (c *SSAFunctionCompiler) NewCFGraph() *CFGraph

NewCFGraph - init new cf graph from function compiler

func (*SSAFunctionCompiler) NextValueID

func (c *SSAFunctionCompiler) NextValueID() TyValueID

NextValueID - get ID of next value

func (*SSAFunctionCompiler) PopStack

func (c *SSAFunctionCompiler) PopStack(n int) []TyValueID

PopStack - clear last elm from stack

func (*SSAFunctionCompiler) PushStack

func (c *SSAFunctionCompiler) PushStack(values ...TyValueID)

PushStack - push to stack

func (*SSAFunctionCompiler) RegAlloc

func (c *SSAFunctionCompiler) RegAlloc() int

RegAlloc - returns the total number of registers used

func (*SSAFunctionCompiler) Serialize

func (c *SSAFunctionCompiler) Serialize() []byte

Serialize serializes a set of SSA-form instructions into a byte array for execution with an exec.VirtualMachine.

Instruction encoding: Value ID (4 bytes) | Opcode (1 byte) | Operands

Types are erased in the generated code. Example: float32/float64 are represented as uint32/uint64 respectively.

type SimpleGasPolicy

type SimpleGasPolicy struct {
	GasPerInstruction int64 // Gas per instruction
}

SimpleGasPolicy - simple policy setting simple gas per instruction

func (*SimpleGasPolicy) GetCost

func (p *SimpleGasPolicy) GetCost(key string) int64

GetCost - get gas cost

type TyJmpKind

type TyJmpKind uint8

TyJmpKind - jmp type/identifier (uint val)

const (
	// JmpUndef - jmp instr undef
	JmpUndef TyJmpKind = iota

	// JmpUncond - jmp uncond
	JmpUncond

	// JmpEither - jmp either
	JmpEither

	// JmpTable - jmp table
	JmpTable

	// JmpReturn - jmp return
	JmpReturn
)

type TyValueID

type TyValueID uint64

TyValueID - uint64 type alias indicating a tyValueID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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