Documentation
¶
Overview ¶
Package frontend implements the translation of WebAssembly to SSA IR using the ssa package.
Index ¶
- func FunctionIndexToFuncRef(idx wasm.Index) ssa.FuncRef
- func SignatureForListener(wasmSig *wasm.FunctionType) (*ssa.Signature, *ssa.Signature)
- func SignatureForWasmFunctionType(typ *wasm.FunctionType) ssa.Signature
- func WasmTypeToSSAType(vt wasm.ValueType) ssa.Type
- type Compiler
- func (c *Compiler) Init(idx, typIndex wasm.Index, typ *wasm.FunctionType, localTypes []wasm.ValueType, ...)
- func (c *Compiler) LowerToSSA()
- func (c *Compiler) MaxGCRoots() int
- func (c *Compiler) PendingEhEntries() []EhPendingEntry
- func (c *Compiler) SetGCEnabled(on bool)
- func (c *Compiler) SetInterruptCheckInterval(interval uint64)
- func (c *Compiler) TryTableMetadata() []nativeapi.TryTableInfo
- func (c *Compiler) WithTryTableMetadata(t tryTableMetadata) *Compiler
- type EhPendingClause
- type EhPendingEntry
- type SharedTryTableMetadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SignatureForListener ¶
SignatureForListener returns the signatures for the listener functions.
func SignatureForWasmFunctionType ¶
func SignatureForWasmFunctionType(typ *wasm.FunctionType) ssa.Signature
SignatureForWasmFunctionType returns the ssa.Signature for the given wasm.FunctionType.
Types ¶
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler is in charge of lowering Wasm to SSA IR, and does the optimization on top of it in architecture-independent way.
func NewFrontendCompiler ¶
func NewFrontendCompiler(m *wasm.Module, ssaBuilder ssa.Builder, offset *nativeapi.ModuleContextOffsetData, ensureTermination bool, listenerOn bool, sourceInfo bool) *Compiler
NewFrontendCompiler returns a frontend Compiler.
func (*Compiler) Init ¶
func (c *Compiler) Init(idx, typIndex wasm.Index, typ *wasm.FunctionType, localTypes []wasm.ValueType, body []byte, needListener bool, bodyOffsetInCodeSection uint64)
Init initializes the state of frontendCompiler and make it ready for a next function.
func (*Compiler) LowerToSSA ¶
func (c *Compiler) LowerToSSA()
LowerToSSA lowers the current function to SSA IR which will be held by ssaBuilder.
After calling this, the caller will be able to access the SSA info in *Compiler.ssaBuilder.
Note that this only does the naive lowering, and do not do any optimization, instead the caller is expected to do so.
func (*Compiler) MaxGCRoots ¶ added in v0.2.0
MaxGCRoots is the most values any safepoint lowered so far writes into the root buffer. It accumulates across every function the compiler lowers, so the engine can size one buffer per call for the whole module.
func (*Compiler) PendingEhEntries ¶
func (c *Compiler) PendingEhEntries() []EhPendingEntry
PendingEhEntries returns the EhPendingEntry values accumulated while lowering the function most recently processed by LowerToSSA.
func (*Compiler) SetGCEnabled ¶ added in v0.2.0
SetGCEnabled makes loop headers emit the collector's safepoint poll. It must be called before lowering.
func (*Compiler) SetInterruptCheckInterval ¶
SetInterruptCheckInterval sets the loop interrupt-check interval used when ensureTermination is active. interval must be 0 (check every iteration) or a power of two. It must be called before lowering.
func (*Compiler) TryTableMetadata ¶
func (c *Compiler) TryTableMetadata() []nativeapi.TryTableInfo
TryTableMetadata returns the accumulated try_table metadata.
func (*Compiler) WithTryTableMetadata ¶
WithTryTableMetadata replaces the try_table metadata table implementation.
type EhPendingClause ¶
type EhPendingClause struct {
Kind byte
TagIndex uint32
HandlerBlkID ssa.BasicBlockID
}
EhPendingClause is one not-yet-resolved catch clause of an EhPendingEntry: the compiled handler block's ID stands in for its executable offset (EhClause.LandingPad), which is only known after this function has been fully compiled (Lower+RegAlloc+Finalize).
type EhPendingEntry ¶
type EhPendingEntry struct {
BodyBlkIDStart, BodyBlkIDEnd ssa.BasicBlockID
Clauses []EhPendingClause
// TryTableID is the module-local try-table ID assigned via
// tryTableMetadata.Append for this same try_table, letting the throw
// path look up NumLocals/ReuseLocals (nativeapi.TryTableInfo) for
// locals-save-area bookkeeping when unwinding past this try's frame.
TryTableID int
}
EhPendingEntry is one not-yet-resolved try_table body range, recorded by the frontend while lowering a try_table-with-catch. BodyBlkIDStart is the ID of the try body's first block (bodyBlk); BodyBlkIDEnd is the exclusive upper bound of every ssa.BasicBlockID allocated while lowering that body (including nested constructs and nested try_tables), captured via ssa.Builder.BlockIDMax() at the try_table's own `end`. Because the frontend allocates a try_table's handler blocks *before* its own bodyBlk (see the OpcodeTryTable lowering), [BodyBlkIDStart, BodyBlkIDEnd) never contains a handler-block ID, even though those IDs are numerically close.
The engine resolves this, after compiling the function, into one or more nativeapi.EhEntry values (one per contiguous run of the body's blocks in the final code layout -- see nativeapi.EhEntry's doc comment) using backend.Compiler.CompiledBlockOffsets().
type SharedTryTableMetadata ¶
type SharedTryTableMetadata struct {
// contains filtered or unexported fields
}
SharedTryTableMetadata is the thread-safe implementation for parallel compilation.
func NewSharedTryTableMetadata ¶
func NewSharedTryTableMetadata() *SharedTryTableMetadata
NewSharedTryTableMetadata creates a new SharedTryTableMetadata.
func (*SharedTryTableMetadata) Append ¶
func (s *SharedTryTableMetadata) Append(info nativeapi.TryTableInfo) int
func (*SharedTryTableMetadata) Table ¶
func (s *SharedTryTableMetadata) Table() []nativeapi.TryTableInfo