Documentation ¶
Index ¶
- type BasicBlock
- type CFGraph
- type FixupInfo
- type GasPolicy
- type Instr
- type InterpreterCode
- type Location
- type Module
- type SSAFunctionCompiler
- func (c *SSAFunctionCompiler) Compile(importTypeIDs []int)
- func (c *SSAFunctionCompiler) FilterFloatingPoint()
- func (c *SSAFunctionCompiler) FixupLocationRef(loc *Location, wasUnreachable bool)
- func (c *SSAFunctionCompiler) InsertGasCounters(gp GasPolicy)
- func (c *SSAFunctionCompiler) NewCFGraph() *CFGraph
- func (c *SSAFunctionCompiler) NextValueID() TyValueID
- func (c *SSAFunctionCompiler) PopStack(n int) []TyValueID
- func (c *SSAFunctionCompiler) PushStack(values ...TyValueID)
- func (c *SSAFunctionCompiler) RegAlloc() int
- func (c *SSAFunctionCompiler) Serialize() []byte
- type SimpleGasPolicy
- type TyJmpKind
- type TyValueID
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 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 ¶
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
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