bytecode

package
v1.2.10 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bytecode defines ixgo's process-independent instruction descriptions.

Its codec reads and writes the versioned disk format and validates structural references without importing the interpreter. It also converts go/types graphs and debug declarations to and from wire descriptions. Runtime reflect-type mapping, host linking and executor binding remain in package ixgo.

This package is available without build tags. Its exported names form a bridge within the module, not a public compatibility commitment.

Index

Constants

View Source
const MaxSize = 64 << 20
View Source
const Version = 1

Variables

View Source
var Magic = [8]byte{'I', 'X', 'G', 'O', 'B', 'C', 0, Version}

Functions

func Constant

func Constant(expr ast.Expr) (out constant.Value)

ExactString represents floats as ratios and complex values as sums.

func DecodeDebugObject

func DecodeDebugObject(obj DebugObject, typ types.Type) (types.Object, error)

DecodeDebugObject restores a declaration using an already reconstructed type.

func DecodeFileSet

func DecodeFileSet(data []byte) (*token.FileSet, error)

DecodeFileSet validates all offsets before passing them to token's mutators.

func Encode

func Encode(p *Program) ([]byte, error)

func EncodeFileSet

func EncodeFileSet(fs *token.FileSet) ([]byte, error)

EncodeFileSet preserves complete physical lines and alternative positions. FileSet.Write is the only API that exposes //line mappings. Its exported snapshot fields are read reflectively, without accessing private memory.

func Marshal

func Marshal(p *Program) ([]byte, error)

func ParseConstant

func ParseConstant(text string) (constant.Value, error)

func RuntimeType

func RuntimeType(t types.Type) bool

RuntimeType reports whether a type can occur as a runtime value.

func Validate

func Validate(p *Program) error

Type construction validates the graph separately and supplies it to the loader.

func ValidateProgram

func ValidateProgram(p *Program) error

ValidateProgram checks the description and complete type graph.

Types

type Aux

type Aux struct {
	Kind            AuxKind
	Op              token.Token
	Type            TypeID
	RightType       TypeID
	Source          TypeID
	Target          TypeID
	Key             TypeID
	Element         TypeID
	Field           TypeID
	Chan            TypeID
	Address         TypeID
	Map             TypeID
	Signature       TypeID
	GoType          TypeID
	Flags           AuxFlags
	Values          [2]Value
	Preds           []int32
	Results         int
	Index           int
	Targets         [2]int32
	JumpTarget      int32
	Registers       []obj.Register
	RuntimeResults  []obj.Register
	Edges           [][]obj.Register
	RuntimeEdges    [][]obj.Register
	ReceiverCache   obj.Register
	RuntimeSource   obj.Register
	RuntimeKey      obj.Register
	RuntimeIndex    obj.Register
	RuntimeLow      obj.Register
	RuntimeHigh     obj.Register
	RuntimeMax      obj.Register
	RuntimeChan     obj.Register
	RuntimeValue    obj.Register
	RuntimeAddress  obj.Register
	Offset          uintptr
	States          []SelectState
	Body            uint32
	Call            CallAux
	Symbol          string
	Method          string
	Error           string
	InterfaceArgs   []bool
	BuiltinConstant uintptr
	BuiltinRuntime  BuiltinRegisters
	Pos             token.Pos
	Object          DebugObject
	Expr            string
}

Aux contains only data; Kind selects the fields used by an instruction. Slices deliberately have no omitempty tags: nil and empty are distinct.

func (Aux) BasicBool

func (a Aux) BasicBool() bool

func (Aux) Blocking

func (a Aux) Blocking() bool

func (Aux) Cached

func (a Aux) Cached() bool

func (Aux) CommaOk

func (a Aux) CommaOk() bool

func (Aux) Condition

func (a Aux) Condition() bool

func (Aux) Constant

func (a Aux) Constant() [2]bool

func (Aux) Global

func (a Aux) Global() bool

func (Aux) Heap

func (a Aux) Heap() bool

func (Aux) IsAddr

func (a Aux) IsAddr() bool

func (Aux) IsString

func (a Aux) IsString() bool

func (Aux) MakeSliceCheck

func (a Aux) MakeSliceCheck() bool

func (*Aux) SetBasicBool

func (a *Aux) SetBasicBool(value bool)

func (*Aux) SetBlocking

func (a *Aux) SetBlocking(value bool)

func (*Aux) SetCached

func (a *Aux) SetCached(value bool)

func (*Aux) SetCommaOk

func (a *Aux) SetCommaOk(value bool)

func (*Aux) SetCondition

func (a *Aux) SetCondition(value bool)

func (*Aux) SetConstant

func (a *Aux) SetConstant(values [2]bool)

func (*Aux) SetGlobal

func (a *Aux) SetGlobal(value bool)

func (*Aux) SetHeap

func (a *Aux) SetHeap(value bool)

func (*Aux) SetIsAddr

func (a *Aux) SetIsAddr(value bool)

func (*Aux) SetIsString

func (a *Aux) SetIsString(value bool)

func (*Aux) SetMakeSliceCheck

func (a *Aux) SetMakeSliceCheck(value bool)

type AuxFlags

type AuxFlags uint16

AuxFlags stores independent instruction properties. Bit values are stable.

const (
	AuxCommaOk AuxFlags = 1 << iota
	AuxGlobal
	AuxCached
	AuxCondition
	AuxBasicBool
	AuxIsString

	AuxMakeSliceCheck
	AuxHeap
	AuxBlocking
	AuxIsAddr
	AuxConstant0
	AuxConstant1
)

func AuxConstantFlags

func AuxConstantFlags(values [2]bool) AuxFlags

func AuxFlag

func AuxFlag(value bool, flag AuxFlags) AuxFlags

AuxFlag converts a runtime property into its wire-description flag.

type AuxKind

type AuxKind uint8

AuxKind is a stable wire tag. New kinds append to this list.

const (
	AuxNone AuxKind = iota
	AuxBinaryOp
	AuxUnaryOp
	AuxPhi
	AuxJump
	AuxIf
	AuxReturn
	AuxExtract
	AuxNext
	AuxField
	AuxLookup
	AuxIndex
	AuxSlice
	AuxRange
	AuxTypeAssert
	AuxConversion
	AuxCreation
	AuxSend
	AuxStore
	AuxMapUpdate
	AuxPanic
	AuxClosure
	AuxCallSite
	AuxCall
	AuxDirectCall
	AuxExternalCall
	AuxDynamicCall
	AuxClosureCall
	AuxInvokeCall
	AuxBuiltinCall
	AuxBodyCall
	AuxSelect
	AuxInstructionDebugRef
)

func (AuxKind) String

func (k AuxKind) String() string

type Boundary

type Boundary struct{ Reads, Writes []obj.Register }

type BuiltinRegisters

type BuiltinRegisters struct {
	Arguments []obj.Register
	Result    obj.Register
	Bound     bool
}

type CallAux

type CallAux struct {
	DeferStack     obj.Register
	Kind           obj.CallKind
	Signature      TypeID
	Target         obj.Register
	Arguments      []obj.Register
	Name           string
	ExtractResults []obj.Register
	Runtime        CallRegisters
}

type CallRegisters

type CallRegisters struct {
	DeferStack     obj.Register
	Target         obj.Register
	Arguments      []obj.Register
	ExtractResults []obj.Register
}

type DebugObject

type DebugObject struct {
	Kind                                     DebugObjectKind
	Name, PackagePath, PackageName, Constant string
	Pos                                      token.Pos
	Type                                     TypeID
}

DebugObject preserves the basic declaration identity used by callbacks.

func EncodeDebugObject

func EncodeDebugObject(obj types.Object, id TypeID) (DebugObject, error)

EncodeDebugObject preserves declaration identity using the supplied type ID.

type DebugObjectKind

type DebugObjectKind uint8

DebugObjectKind is a stable wire tag. New kinds append to this list.

const (
	DebugObjectNone DebugObjectKind = iota
	DebugObjectVar
	DebugObjectConst
)

func (DebugObjectKind) String

func (k DebugObjectKind) String() string

type External

type External struct {
	Symbol, Package, Name string
	Receiver, Signature   TypeID
	Link                  bool // package/name describe the go:linkname target
}

type Function

type Function struct {
	Memo                  *MemoDescription
	InjectReturns         []int
	NamedResults          []obj.Register
	Name, Package, Member string
	Signature             TypeID
	Args, Results, Env    int
	Stack                 []Value
	Blocks                []int
	Code                  []Instruction
	Recover               bool
	RecoverPC             int32
	CacheRegs             []obj.Register
	ClearRanges           [][2]obj.Register
	LocalRefs             []obj.Register
	ChildFrame            obj.Register
	HasGC                 bool
	GCRegs                [][]obj.Register
	NameMetadata          string
	Entry                 token.Position
	EntryPos              token.Pos // Optional declaration position in FileSet.
	Positions             []token.Pos
	InterfaceThunk        bool
	Numeric               *NumericInput
	GCPlan                *GCPlan // Large functions materialize GCRegs on demand.
}

func (*Function) ValidateGC

func (f *Function) ValidateGC(gc bool) error

ValidateGC also protects the lazy runtime binder when other checks are disabled.

type GCBlock

type GCBlock struct {
	LiveOut   []obj.Register
	Transfers []GCTransfer
	IsRecover bool
}

type GCCapture

type GCCapture struct {
	Result int
	Binds  []int
}

type GCPlan

type GCPlan struct {
	Registers, Uses, Recover []obj.Register
	Blocks                   []GCBlock
	Points                   []GCPoint
	Captures                 []GCCapture
}

GCPlan describes SSA-free liveness transfers and their mapping to execution PCs.

type GCPoint

type GCPoint struct {
	Block, Instr int // Block -1 denotes an unmapped PC.
}

type GCTransfer

type GCTransfer struct {
	Def              obj.Register
	UseStart, UseEnd int
}

type Global

type Global struct {
	Name     string
	Type     TypeID
	Alias    string
	External bool
	Host     bool   // resolve registered package storage
	Binding  string // external go:linkname target
}

type Instruction

type Instruction struct {
	Source        obj.Source
	Op            obj.Opcode
	Result        obj.Register
	Args          []obj.Register
	ArgKinds      []obj.OperandKind
	Aux           PackedAux
	RuntimeResult obj.Register
	RuntimeArgs   []obj.Register
	RuntimeBound  bool
}

type Member

type Member struct {
	Kind          MemberKind
	Package, Name string
	Type          TypeID
	Value         string
}

type MemberKind

type MemberKind uint8

MemberKind is a stable wire tag. New kinds append to this list.

const (
	MemberInvalid MemberKind = iota
	MemberGlobal
	MemberConstant
	MemberType
)

func (MemberKind) String

func (k MemberKind) String() string

type MemoDescription

type MemoDescription struct {
	Kind     uint8
	Returns  []int
	Output   int
	State    bool
	Receiver *MemoReceiver
	Updates  []MemoReceiverUpdate
}

MemoDescription contains installation data, never live cache entries. Function IDs are supplied by the containing artifact's function table.

type MemoReceiver

type MemoReceiver struct {
	Fields    [][]int
	Additive  []bool
	Affine    []bool
	Bitwise   []bool
	Functions []uint32
}

type MemoReceiverUpdate

type MemoReceiverUpdate struct {
	PC         int
	Field      int
	Op         token.Token
	Operand    int
	HasOperand bool
}

type Method

type Method struct {
	Type     TypeID
	Name     string
	Function uint32
}

type Mode

type Mode uint

type NumericInput

type NumericInput struct {
	Types      map[obj.Register]TypeID
	Results    []TypeID
	Boundaries []Boundary
}

type Package

type Package struct {
	Path, Name string
	Host       bool
}

type PackedAssert

type PackedAssert struct {
	Source        TypeID
	Target        TypeID
	CommaOk       bool
	RuntimeSource obj.Register
	GoType        TypeID
}

type PackedAux

type PackedAux struct {
	Kind AuxKind
	Data any
}

PackedAux retains only fields used by an auxiliary kind. The codec expands one temporary descriptor at a time, preserving the on-disk schema.

func PackAux

func PackAux(a Aux) PackedAux

func (PackedAux) Expand

func (p PackedAux) Expand() Aux

type PackedBinary

type PackedBinary struct {
	Op        token.Token
	Type      TypeID
	RightType TypeID
	Constant  [2]bool
	Values    [2]Value
}

type PackedCall

type PackedCall struct {
	Call            CallAux
	Symbol          string
	Body            uint32
	Registers       []obj.Register
	Method          string
	InterfaceArgs   []bool
	BuiltinConstant uintptr
	Error           string
	BuiltinRuntime  BuiltinRegisters
}

type PackedClosure

type PackedClosure struct {
	Signature TypeID
	Body      uint32
	Registers []obj.Register
}

type PackedConversion

type PackedConversion struct {
	Source        TypeID
	Target        TypeID
	RuntimeSource obj.Register
}

type PackedCreation

type PackedCreation struct {
	Target TypeID
	Heap   bool
}

type PackedDebug

type PackedDebug struct {
	Pos    token.Pos
	IsAddr bool
	Expr   string
	Object DebugObject
}

type PackedExtract

type PackedExtract struct {
	Index int
}

type PackedField

type PackedField struct {
	Source        TypeID
	Field         TypeID
	Cached        bool
	ReceiverCache obj.Register
	Index         int
	Offset        uintptr
	RuntimeSource obj.Register
}

type PackedIf

type PackedIf struct {
	Targets   [2]int32
	Condition bool
	BasicBool bool
	Constant  [2]bool
}

type PackedIndex

type PackedIndex struct {
	Source        TypeID
	Target        TypeID
	RuntimeSource obj.Register
	RuntimeIndex  obj.Register
}

type PackedJump

type PackedJump struct {
	JumpTarget int32
}

type PackedLookup

type PackedLookup struct {
	Source        TypeID
	Key           TypeID
	Element       TypeID
	CommaOk       bool
	RuntimeSource obj.Register
	RuntimeKey    obj.Register
}

type PackedMap

type PackedMap struct {
	Map  TypeID
	Key  TypeID
	Type TypeID
}

type PackedNext

type PackedNext struct {
	IsString bool
}

type PackedPanic

type PackedPanic struct {
	Type         TypeID
	RuntimeValue obj.Register
}

type PackedPhi

type PackedPhi struct {
	Preds          []int32
	Registers      []obj.Register
	RuntimeResults []obj.Register
	Edges          [][]obj.Register
	RuntimeEdges   [][]obj.Register
}

type PackedRange

type PackedRange struct {
	Source  TypeID
	Key     TypeID
	Element TypeID
}

type PackedReturn

type PackedReturn struct {
	Results        int
	RuntimeResults []obj.Register
}

type PackedSelect

type PackedSelect struct {
	Blocking bool
	States   []SelectState
}

type PackedSend

type PackedSend struct {
	Chan         TypeID
	Type         TypeID
	RuntimeChan  obj.Register
	RuntimeValue obj.Register
}

type PackedSlice

type PackedSlice struct {
	Source         TypeID
	Target         TypeID
	MakeSliceCheck bool
	RuntimeSource  obj.Register
	RuntimeLow     obj.Register
	RuntimeHigh    obj.Register
	RuntimeMax     obj.Register
}

type PackedStore

type PackedStore struct {
	Address        TypeID
	Type           TypeID
	RuntimeAddress obj.Register
	RuntimeValue   obj.Register
}

type PackedUnary

type PackedUnary struct {
	Op       token.Token
	Type     TypeID
	CommaOk  bool
	Global   bool
	Constant [2]bool
	Values   [2]Value
}

type Program

type Program struct {
	RuntimeTypeNames                  []RuntimeName
	FileSet                           []byte
	Externals                         []External
	Members                           []Member
	Version                           int
	GoVersion, GOOS, GOARCH, Compiler string
	Mode                              Mode
	Main                              string
	Packages                          []Package
	Types                             TypeTable
	Functions                         []Function
	Globals                           []Global
	Methods                           []Method
	GC                                bool
}

func Decode

func Decode(data []byte) (Program, error)

func Read

func Read(r io.Reader, validate bool) (Program, error)

Read decodes a framed program. validate enables checksum verification. Framing, format version and decoding resource limits are always enforced.

type RuntimeName

type RuntimeName struct {
	Type          TypeID
	Name, Package string
}

type SelectState

type SelectState struct {
	Chan, Send TypeID
	Dir        reflect.SelectDir
}

type TypeDecoder

type TypeDecoder struct {
	// contains filtered or unexported fields
}

func NewTypeDecoder

func NewTypeDecoder(table TypeTable) (d *TypeDecoder, err error)

func ValidateTypes

func ValidateTypes(p *Program) (*TypeDecoder, error)

ValidateTypes performs structural validation and returns the reconstructed type graph so callers can reuse it for binding without a second construction.

func (*TypeDecoder) EnsurePackage

func (d *TypeDecoder) EnsurePackage(path, name string) *types.Package

func (*TypeDecoder) Package

func (d *TypeDecoder) Package(path string) *types.Package

func (*TypeDecoder) Packages

func (d *TypeDecoder) Packages() map[string]*types.Package

Packages returns the decoder-owned package map for read-only iteration. Use EnsurePackage to add a package.

func (*TypeDecoder) Type

func (d *TypeDecoder) Type(id TypeID) (types.Type, error)

type TypeEncoder

type TypeEncoder struct {
	// contains filtered or unexported fields
}

func NewTypeEncoder

func NewTypeEncoder() *TypeEncoder

func (*TypeEncoder) Add

func (e *TypeEncoder) Add(t types.Type) TypeID

func (*TypeEncoder) Err

func (e *TypeEncoder) Err() error

func (*TypeEncoder) Table

func (e *TypeEncoder) Table() TypeTable

func (*TypeEncoder) Type

func (e *TypeEncoder) Type(id TypeID) types.Type

type TypeID

type TypeID uint32

type TypeKind

type TypeKind uint8

TypeKind is the stable wire tag for a type node. New kinds append to this list.

const (
	TypeInvalid TypeKind = iota
	TypeBasic
	TypeError
	TypePointer
	TypeSlice
	TypeArray
	TypeMap
	TypeChan
	TypeStruct
	TypeTuple
	TypeSignature
	TypeNamed
	TypeInterface
)

func (TypeKind) String

func (k TypeKind) String() string

type TypeMethod

type TypeMethod struct {
	Name, Package string
	Signature     TypeID
}

type TypeNode

type TypeNode struct {
	Kind          TypeKind
	Name, Package string
	// Scope is a per-object identity for local names; zero means package scope.
	Scope                 TypeID
	Basic                 int
	Len                   int64
	Dir                   int
	Elem, Key, Underlying TypeID
	Fields                []TypeVar
	Params, Results       []TypeVar
	Receiver              *TypeVar
	Variadic              bool
	Methods               []TypeMethod
	Embeddeds             []TypeID
	Implicit              bool
}

type TypePackage

type TypePackage struct{ Path, Name string }

type TypeTable

type TypeTable struct {
	Types    []TypeNode
	Packages []TypePackage
}

IDs are one-based indices into Types. The wire graph contains no Go objects.

type TypeVar

type TypeVar struct {
	Name, Package string
	Type          TypeID
	Embedded      bool
	Tag           string
}

type Value

type Value struct {
	Kind ValueKind
	Type TypeID
	Bits uint64
	Imag uint64
	Text string
	Body uint32
	Env  []Value
}

Value contains only wire data, never interpreter objects or addresses.

type ValueKind

type ValueKind uint8

ValueKind is a stable wire tag. New kinds append to this list.

const (
	ValueInvalid ValueKind = iota
	ValueNil
	ValueInvalidReflect
	ValueReflect
	ValueZero
	ValueBool
	ValueInt
	ValueUint
	ValueFloat32
	ValueFloat64
	ValueComplex64
	ValueComplex128
	ValueString
	ValueGlobal
	ValueFunction
	ValueExternal
)

func (ValueKind) String

func (k ValueKind) String() string

Jump to

Keyboard shortcuts

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