compile

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: GPL-3.0 Imports: 13 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DynamicBindings

func DynamicBindings(buffers []BufferBinding) uint32

DynamicBindings is the variable-length bindings of an entry, one bit per binding index, for a backend to check the lengths it supplies against.

func Invoke

func Invoke[B, V any](r compute.Operations[B, V], op *Operation, buf B, args []V) V

Invoke calls the renderer's method for op with the buffer, when the operation acts on one, and the value operands in order, and returns the result, or the zero value for an operation with none. An emitter implements compute.Operations over its own operand types and passes the operands it evaluated.

Types

type ArrayType

type ArrayType struct {
	Elem Type
	Len  int
}

ArrayType is a fixed-size array.

func (ArrayType) Kind

func (a ArrayType) Kind() Kind

func (ArrayType) String

func (a ArrayType) String() string

type Assign

type Assign struct {
	Targets []Expr
	Values  []Expr
}

Assign stores Values into Targets. Several targets appear only for a multi-result call, which is then the single value.

type Binary

type Binary struct {
	T    Type
	Op   Op
	X, Y Expr
}

Binary is an arithmetic, bitwise, shift, comparison, or logical operation; the emitter selects the form from the operand type.

func (*Binary) Type

func (e *Binary) Type() Type

type Block

type Block struct {
	Stmts []Stmt
}

Block is a statement list with its own local scope.

type Break

type Break struct{}

Break leaves the innermost loop.

type BufferBinding

type BufferBinding struct {
	Param   int
	Type    BufferType
	Binding int
}

BufferBinding is one buffer parameter of an entry point and its binding index, which is the parameter's position.

type BufferType

type BufferType struct {
	Name    string
	Word    bool
	Size    int
	Dynamic bool // slice-backed buffer, its length travels with the binding
	Params  bool
}

BufferType is an opaque buffer handle: byte-addressed or word-addressed, with its size constant (bytes or words), or Dynamic for a buffer whose length arrives with the binding, in bytes for a byte buffer and in words for a word buffer. Params marks the wrapper's params buffer, only ever read, and only through LoadStruct.

func (BufferType) Kind

func (b BufferType) Kind() Kind

func (BufferType) String

func (b BufferType) String() string

type Call

type Call struct {
	T    Type
	Func int
	Args []Expr
}

Call calls a module function. A multi-result call has a Tuple type and appears only as the single value of a multi-target Assign.

func (*Call) Type

func (e *Call) Type() Type

type Case

type Case struct {
	Values []Expr
	Body   *Block
}

Case is one switch case with constant values.

type Composite

type Composite struct {
	T     Type
	Elems []Expr
}

Composite builds a struct or array value from positional elements, one per field or element.

func (*Composite) Type

func (e *Composite) Type() Type

type Const

type Const struct {
	T     Type
	Value constant.Value
}

Const is a folded constant.

func (*Const) Type

func (e *Const) Type() Type

type Continue

type Continue struct{}

Continue advances the innermost loop.

type Convert

type Convert struct {
	T Type
	X Expr
}

Convert is an explicit scalar conversion; its result is canonical.

func (*Convert) Type

func (e *Convert) Type() Type

type Entry

type Entry struct {
	Func    int
	Wrapper int // synthesized wrapper function
	Span    bool
	Group   bool
	Buffers []BufferBinding
	Params  []int // locals holding the struct parameters, in order
	Coords  int   // 1, 2, or 3 trailing coordinates
}

Entry is an entry point: a function plus its dispatch shape and the synthesized wrapper the emitted shell calls. A span entry ends in two int32 coordinates and renders a segment of dots per thread; an index entry ends in one uint32 coordinate, the thread's x; a group entry ends in three, the thread's index in its group, the group's size, and the group's index, and its params row is the group's. The workgroup an entry runs in is each backend's choice.

type Error

type Error struct {
	Pos token.Position
	Msg string
}

Error is one compile-stage diagnostic at a source position.

func (Error) Error

func (e Error) Error() string

type ErrorList

type ErrorList []Error

ErrorList collects every diagnostic of a run so a source with several violations reports all of them at once.

func (ErrorList) Error

func (l ErrorList) Error() string

type Expr

type Expr interface {
	Type() Type
}

Expr is an expression node carrying its type.

type ExprStmt

type ExprStmt struct {
	X Expr
}

ExprStmt evaluates an expression for effect: a call or an operation with no result, or the value of a blank assignment.

type Field

type Field struct {
	Name   string
	Type   Type
	Offset int
}

Field is one laid-out struct field.

type FieldRef

type FieldRef struct {
	T     Type
	X     Expr
	Field int
}

FieldRef selects a struct field by index.

func (*FieldRef) Type

func (e *FieldRef) Type() Type

type For

type For struct {
	Cond Expr
	Post Stmt
	Body *Block
}

For is a loop. Cond and Post may be nil. A Go loop's init statement lowers into the block wrapping the loop.

type Func

type Func struct {
	Name      string
	Locals    []Local
	NumParams int
	Results   []Type
	Body      *Block
}

Func is a lowered function. The first NumParams locals are the parameters in order.

type If

type If struct {
	Cond Expr
	Then *Block
	Else Stmt
}

If is a conditional; Else is nil, a Block, or another If.

type IndexRef

type IndexRef struct {
	T     Type
	X     Expr
	Index Expr
}

IndexRef selects an array element.

func (*IndexRef) Type

func (e *IndexRef) Type() Type

type Kind

type Kind int

Kind is a scalar type or the category of a composite type.

const (
	Bool Kind = iota
	I8
	I16
	I32
	I64
	U8
	U16
	U32
	U64
	F32
	ArrayKind
	StructKind
	ByteBufferKind
	WordBufferKind
)

func (Kind) String

func (k Kind) String() string

type LoadStruct

type LoadStruct struct {
	T      Type
	Buffer Expr
	Addr   Expr
}

LoadStruct is the struct row at a byte address of a byte buffer. Only the synthesized entry wrappers use it, to fetch a row's params. It names the row, not a copy of it: an emitter may copy the row into a local or bind it by reference and read its fields in place.

func (*LoadStruct) Type

func (e *LoadStruct) Type() Type

type Local

type Local struct {
	Name string
	Type Type
	Kind ParamKind // meaningful for parameters
}

Local is a function's local or parameter slot.

type LocalRef

type LocalRef struct {
	T     Type
	Index int
}

LocalRef reads or addresses a local or parameter by index. A ref parameter denotes the value it refers to.

func (*LocalRef) Type

func (e *LocalRef) Type() Type

type Mask

type Mask struct {
	T Type
	X Expr
}

Mask re-canonicalizes a narrow value held in a 32-bit register to its declared width: sign-extended for signed types, zero-extended for unsigned.

func (*Mask) Type

func (e *Mask) Type() Type

type Module

type Module struct {
	Structs []StructType
	Tables  []Table
	Funcs   []Func
	Entries []Entry
}

Module is a lowered program.

func Lower

func Lower(prog *Program) (*Module, error)

Lower lowers a validated Program to the IR. Every diagnostic of the run is returned together; a Module is returned only when there are none.

type Op

type Op int

Op is an operator.

const (
	Add Op = iota
	Sub
	Mul
	Div
	Rem
	BitAnd
	BitOr
	BitXor
	AndNot
	Shl
	Shr
	Eq
	Ne
	Lt
	Le
	Gt
	Ge
	LogicalAnd
	LogicalOr
	Neg
	Not
	BitComplement
)

func (Op) String

func (o Op) String() string

type OpCall

type OpCall struct {
	T    Type
	Op   *Operation
	Args []Expr
}

OpCall calls an operation of compute.Operations. A buffer operation takes the buffer as the first argument.

func (*OpCall) Type

func (e *OpCall) Type() Type

type Operation

type Operation struct {
	Name     string
	Buffered bool
	Operands int
	Yields   bool
}

Operation is an operation of compute.Operations as the interface declares it, read from the interface's method: its name, whether its first parameter is the buffer it acts on, its value operands after that, and whether it has a result. The compile stage states nothing about an operation itself; an OpCall node names one, and Invoke calls it on a backend.

func (*Operation) Pure

func (o *Operation) Pure() bool

Pure reports an operation that reads and writes no buffer contents, so its evaluation order is not observable: one that acts on no buffer and yields a value (min and max), and Length, which takes a buffer but reads its length, not its contents. NextPhase acts on no buffer and yields nothing, and orders the buffer stores around it.

func (*Operation) String

func (o *Operation) String() string

type Package

type Package struct {
	Path    string
	Files   []*ast.File
	Types   *types.Package
	Info    *types.Info
	Entries []string
}

Package is one type-checked compute package.

type ParamKind

type ParamKind int

ParamKind distinguishes how a function parameter is passed.

const (
	ValueParam  ParamKind = iota // by value
	RefParam                     // by reference, from a Go pointer
	BufferParam                  // a buffer handle
)

type Program

type Program struct {
	Fset     *token.FileSet
	Parent   *Package
	Packages []*Package
}

Program is the loaded compute tree: the parent package and the validated subpackages, sharing one file set.

func Load

func Load(parent Source, subs ...Source) (*Program, error)

Load parses and type-checks the parent compute package and the compute subpackages, then validates the subpackages against the compute subset. Every diagnostic of the run is returned together as an ErrorList; a Program is returned only when there are none.

type Return

type Return struct {
	Values []Expr
}

Return returns zero or more values.

type Scalar

type Scalar Kind

Scalar is a scalar type.

func (Scalar) Bytes

func (s Scalar) Bytes() int

Bytes is the scalar's size in a buffer: its width in bytes, and one for bool, the byte Go stores.

func (Scalar) Kind

func (s Scalar) Kind() Kind

func (Scalar) Narrow

func (s Scalar) Narrow() bool

Narrow reports an 8 or 16-bit integer, which the targets compute in 32-bit registers.

func (Scalar) String

func (s Scalar) String() string

func (Scalar) Width

func (s Scalar) Width() int

Width is the scalar's bit width, or 0 for bool.

type Source

type Source struct {
	Path    string
	Files   fs.FS
	Entries []string
}

Source is one compute package as the compile stage receives it: its import path and the file system holding its Go files. Files holds the package's subset source and nothing else: the compute packages name the files they embed one by one, so the stage takes every file it is given rather than filtering by name. Entries names the exported functions the renderer dispatches as compute entry points; every other function is a helper.

type Stmt

type Stmt interface {
	// contains filtered or unexported methods
}

Stmt is a statement node.

type StructRef

type StructRef struct {
	Index int
}

StructRef refers to a laid-out struct by its index in Module.Structs.

func (StructRef) Kind

func (s StructRef) Kind() Kind

func (StructRef) String

func (s StructRef) String() string

type StructType

type StructType struct {
	Name   string
	Fields []Field
	Size   int
	Align  int
}

StructType is a laid-out struct: fields in declaration order with the offsets the layout rule assigns.

type Switch

type Switch struct {
	Tag     Expr
	Cases   []Case
	Default *Block
}

Switch dispatches on an integer or bool tag.

type Table

type Table struct {
	Name   string
	Type   ArrayType
	Values []constant.Value
}

Table is a package-level lookup array lowered to constant memory.

type TableRef

type TableRef struct {
	T     Type
	Table int
	Index Expr
}

TableRef selects a lookup table element.

func (*TableRef) Type

func (e *TableRef) Type() Type

type Tuple

type Tuple struct {
	Elems []Type
}

Tuple is the type of a multi-result call.

func (Tuple) Kind

func (t Tuple) Kind() Kind

func (Tuple) String

func (t Tuple) String() string

type Type

type Type interface {
	Kind() Kind
	String() string
}

Type is an IR type. Scalars are Scalar values; composites and buffers are the other implementations.

type Unary

type Unary struct {
	T  Type
	Op Op
	X  Expr
}

Unary is Neg, Not, or BitComplement.

func (*Unary) Type

func (e *Unary) Type() Type

type VarDecl

type VarDecl struct {
	Local int
	Init  Expr
}

VarDecl declares a local with an initializer.

type Zero

type Zero struct {
	T Type
}

Zero is the zero value of a composite type.

func (*Zero) Type

func (e *Zero) Type() Type

Directories

Path Synopsis
Package msl emits Metal Shading Language source from the compute IR.
Package msl emits Metal Shading Language source from the compute IR.

Jump to

Keyboard shortcuts

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