compiler

package
v0.0.0-...-05c0e0f Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: MIT Imports: 10 Imported by: 9

Documentation

Index

Constants

View Source
const NGEN_ENV_API_PREFIX = "wenv_"
View Source
const NGEN_FP_HEADER = `` /* 1043-byte string literal not displayed */
View Source
const NGEN_FUNCTION_PREFIX = "wasm_function_"
View Source
const NGEN_HEADER = `` /* 2018-byte string literal not displayed */
View Source
const NGEN_INS_LABEL_PREFIX = "ins"
View Source
const NGEN_LOCAL_PREFIX = "l"
View Source
const NGEN_VALUE_PREFIX = "v"

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicBlock

type BasicBlock struct {
	Code       []Instr
	JmpKind    TyJmpKind
	JmpTargets []int

	JmpCond    TyValueID
	YieldValue TyValueID
}

type CFGraph

type CFGraph struct {
	Blocks []BasicBlock
}

func (*CFGraph) ToInsSeq

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

type FixupInfo

type FixupInfo struct {
	CodePos  int
	TablePos int
}

type GasPolicy

type GasPolicy interface {
	GetCost(key Instr) int64
}

type Instr

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

	Op         string
	Immediates []int64
	Values     []TyValueID
}

Instr denotes a single instrution.

func (*Instr) BranchTargets

func (ins *Instr) BranchTargets() []int

type InterpreterCode

type InterpreterCode struct {
	NumRegs    int
	NumParams  int
	NumLocals  int
	NumReturns int
	Bytes      []byte
	JITInfo    interface{}
	JITDone    bool
}

type Location

type Location struct {
	CodePos         int
	StackDepth      int
	BrHead          bool // true for loops
	PreserveTop     bool
	LoopPreserveTop bool
	FixupList       []FixupInfo

	IfBlock bool
}

type Module

type Module struct {
	Base                 *wasm.Module
	FunctionNames        map[int]string
	DisableFloatingPoint bool
}

func LoadModule

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

func (*Module) CompileForInterpreter

func (m *Module) CompileForInterpreter(gp GasPolicy) ([]InterpreterCode, error)

func (*Module) CompileWithNGen

func (m *Module) CompileWithNGen(gp GasPolicy, numGlobals uint64) (string, error)

type SSAFunctionCompiler

type SSAFunctionCompiler struct {
	Module *wasm.Module
	Source *disasm.Disassembly

	Code      []Instr
	Stack     []TyValueID
	Locations []*Location

	CallIndexOffset int

	StackValueSets map[int][]TyValueID
	UsedValueIDs   map[TyValueID]struct{}

	ValueID TyValueID
}

SSAFunctionCompiler represents a compiler which translates a WebAssembly modules intepreted 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 intepreted 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()

func (*SSAFunctionCompiler) FixupLocationRef

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

func (*SSAFunctionCompiler) InsertGasCounters

func (c *SSAFunctionCompiler) InsertGasCounters(gp GasPolicy)

func (*SSAFunctionCompiler) NGen

func (c *SSAFunctionCompiler) NGen(selfID uint64, numParams uint64, numLocals uint64, numGlobals uint64) string

func (*SSAFunctionCompiler) NewCFGraph

func (c *SSAFunctionCompiler) NewCFGraph() *CFGraph

func (*SSAFunctionCompiler) NextValueID

func (c *SSAFunctionCompiler) NextValueID() TyValueID

func (*SSAFunctionCompiler) PopStack

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

func (*SSAFunctionCompiler) PushStack

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

func (*SSAFunctionCompiler) RegAlloc

func (c *SSAFunctionCompiler) RegAlloc() int

FIXME: The current RegAlloc is based on wasm stack info and we probably want a real one (in addition to this) with liveness analysis. 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
}

func (*SimpleGasPolicy) GetCost

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

type TyJmpKind

type TyJmpKind uint8
const (
	JmpUndef TyJmpKind = iota
	JmpUncond
	JmpEither
	JmpTable
	JmpReturn
)

type TyValueID

type TyValueID uint64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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