ssa

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoInline inlineAttr = iota
	AlwaysInline
	InlineHint
)
View Source
const (
	OrderingNotAtomic      = llvm.AtomicOrderingNotAtomic
	OrderingUnordered      = llvm.AtomicOrderingUnordered
	OrderingMonotonic      = llvm.AtomicOrderingMonotonic
	OrderingAcquire        = llvm.AtomicOrderingAcquire
	OrderingRelease        = llvm.AtomicOrderingRelease
	OrderingAcquireRelease = llvm.AtomicOrderingAcquireRelease
	OrderingSeqConsistent  = llvm.AtomicOrderingSequentiallyConsistent
)
View Source
const (
	PkgPython  = "github.com/goplus/lib/py"
	PkgRuntime = env.LLGoRuntimePkg + "/internal/runtime"
)
View Source
const (
	DbgFlagInstruction dbgFlags = 1 << iota

	DbgFlagAll = DbgFlagInstruction
)
View Source
const (
	MD_dbg = 0
)
View Source
const (
	NameValist = "__llgo_va_list"
)

Variables

View Source
var DWARF_LANG_C llvm.DwarfLang = 0x2
View Source
var DWARF_LANG_GO llvm.DwarfLang = 0x16
View Source
var (
	NoArgsNoRet = types.NewSignatureType(nil, nil, nil, nil, nil, false)
)

Functions

func FullName added in v0.3.0

func FullName(pkg *types.Package, name string) string

FullName returns the full name of a package member.

func FuncAddCtx added in v0.6.0

func FuncAddCtx(ctx *types.Var, sig *types.Signature) *types.Signature

FuncAddCtx adds a ctx to a function signature.

func FuncName added in v0.8.5

func FuncName(pkg *types.Package, name string, recv *types.Var, org bool) string

FuncName: - func: pkg.name - method: pkg.T.name, pkg.(*T).name

func HasNameValist added in v0.11.6

func HasNameValist(sig *types.Signature) bool

func Initialize

func Initialize(flags InitFlags)

Initialize initializes the LLVM library.

func Instantiate added in v0.9.8

func Instantiate(orig types.Type, t *types.Named) (types.Type, bool)

func IsClosure added in v0.11.6

func IsClosure(raw *types.Struct) bool

func NameOf added in v0.3.0

func NameOf(typ *types.Named) string

NameOf returns the full name of a named type.

func PathOf added in v0.3.0

func PathOf(pkg *types.Package) string

PathOf returns the package path of the specified package.

func SetDebug

func SetDebug(dbgFlags dbgFlags)

SetDebug sets debug flags.

func TypeArgs added in v0.9.7

func TypeArgs(typeArgs []types.Type) string

func VArg

func VArg() *types.Var

Types

type AtomicOp added in v0.8.9

type AtomicOp = llvm.AtomicRMWBinOp

AtomicOp is an atomic operation.

type AtomicOrdering added in v0.8.9

type AtomicOrdering = llvm.AtomicOrdering

type Background added in v0.6.0

type Background int
const (
	InGo Background
	InC
	InPython
)

type BasicBlock

type BasicBlock = *aBasicBlock

BasicBlock represents a basic block in a function.

func (BasicBlock) Addr added in v0.8.7

func (p BasicBlock) Addr() Expr

Addr returns the address of the basic block.

func (BasicBlock) Index

func (p BasicBlock) Index() int

Index returns the index of the basic block in the parent function.

func (BasicBlock) Parent

func (p BasicBlock) Parent() Function

Parent returns the function to which the basic block belongs.

type Builder

type Builder = *aBuilder

Builder represents a builder for creating instructions in a function.

func (Builder) Advance added in v0.5.0

func (b Builder) Advance(ptr Expr, offset Expr) Expr

Advance returns the pointer ptr advanced by offset.

func (Builder) Alloc

func (b Builder) Alloc(elem Type, heap bool) (ret Expr)

The Alloc instruction reserves space for a variable of the given type, zero-initializes it, and yields its address.

If heap is false, Alloc zero-initializes the same local variable in the call frame and returns its address; in this case the Alloc must be present in Function.Locals. We call this a "local" alloc.

If heap is true, Alloc allocates a new zero-initialized variable each time the instruction is executed. We call this a "new" alloc.

When Alloc is applied to a channel, map or slice type, it returns the address of an uninitialized (nil) reference of that kind; store the result of MakeSlice, MakeMap or MakeChan in that location to instantiate these types.

Example printed form:

t0 = local int
t1 = new int

func (Builder) AllocCStr added in v0.11.1

func (b Builder) AllocCStr(gostr Expr) (ret Expr)

AllocCStr allocates space on the heap for copy it from a Go string.

func (Builder) AllocU added in v0.8.5

func (b Builder) AllocU(elem Type, n ...int64) (ret Expr)

AllocU allocates uninitialized space for n*sizeof(elem) bytes.

func (Builder) AllocZ added in v0.8.5

func (b Builder) AllocZ(n Expr) (ret Expr)

AllocZ allocates zero initialized space for n bytes.

func (Builder) Alloca added in v0.4.0

func (b Builder) Alloca(n Expr) (ret Expr)

Alloca allocates uninitialized space for n bytes.

func (Builder) AllocaCStr added in v0.4.0

func (b Builder) AllocaCStr(gostr Expr) (ret Expr)

AllocaCStr allocates space for copy it from a Go string.

func (Builder) AllocaCStrs added in v0.9.1

func (b Builder) AllocaCStrs(strs Expr, endWithNil bool) (cstrs Expr)

func allocaCStrs(strs []string, endWithNil bool) **int8

func (Builder) AllocaSigjmpBuf added in v0.8.7

func (b Builder) AllocaSigjmpBuf() Expr

func (Builder) AllocaT added in v0.9.8

func (b Builder) AllocaT(t Type) (ret Expr)

func (Builder) ArrayAlloca added in v0.9.1

func (b Builder) ArrayAlloca(telem Type, n Expr) (ret Expr)

ArrayAlloca reserves space for an array of n elements of type telem.

func (Builder) Atomic added in v0.8.9

func (b Builder) Atomic(op AtomicOp, ptr, val Expr) Expr

Atomic performs an atomic operation on the memory location pointed to by ptr.

func (Builder) AtomicCmpXchg added in v0.8.9

func (b Builder) AtomicCmpXchg(ptr, old, new Expr) Expr

AtomicCmpXchg performs an atomic compare-and-swap operation on the memory location pointed to by ptr.

func (Builder) BinOp

func (b Builder) BinOp(op token.Token, x, y Expr) Expr

The BinOp instruction yields the result of binary operation (x op y). op can be: ADD SUB MUL QUO REM + - * / % AND OR XOR SHL SHR AND_NOT & | ^ << >> &^ EQL NEQ LSS LEQ GTR GEQ == != < <= > >=

func (Builder) BuiltinCall added in v0.3.0

func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr)

A Builtin represents a specific use of a built-in function, e.g. len.

Builtins are immutable values. Builtins do not have addresses.

`fn` indicates the function: one of the built-in functions from the Go spec (excluding "make" and "new").

func (Builder) CBytes added in v0.9.8

func (b Builder) CBytes(v Expr) Expr

CBytes returns a c-style bytes

func (Builder) CMalloc added in v0.9.8

func (b Builder) CMalloc(n Expr) Expr

CMalloc returns a c-style pointer

func (Builder) CStr added in v0.4.0

func (b Builder) CStr(v string) Expr

CStr returns a c-style string constant expression.

func (Builder) CString added in v0.9.8

func (b Builder) CString(v Expr) Expr

CString returns a c-style string

func (Builder) Call

func (b Builder) Call(fn Expr, args ...Expr) (ret Expr)

The Call instruction represents a function call.

The Call instruction yields the function result if there is exactly one. Otherwise it returns a tuple, the components of which are accessed via Extract.

Example printed form:

t2 = println(t0, t1)
t4 = t3()

func (Builder) ChangeInterface added in v0.8.6

func (b Builder) ChangeInterface(typ Type, x Expr) (ret Expr)

ChangeInterface constructs a value of one interface type from a value of another interface type known to be assignable to it. This operation cannot fail.

Pos() returns the ast.CallExpr.Lparen if the instruction arose from an explicit T(e) conversion; the ast.TypeAssertExpr.Lparen if the instruction arose from an explicit e.(T) operation; or token.NoPos otherwise.

Example printed form:

t1 = change interface interface{} <- I (t0)

func (Builder) ChangeType added in v0.3.0

func (b Builder) ChangeType(t Type, x Expr) (ret Expr)

The ChangeType instruction applies to X a value-preserving type change to Type().

Type changes are permitted:

  • between a named type and its underlying type.
  • between two named types of the same underlying type.
  • between (possibly named) pointers to identical base types.
  • from a bidirectional channel to a read- or write-channel, optionally adding/removing a name.
  • between a type (t) and an instance of the type (tσ), i.e. Type() == σ(X.Type()) (or X.Type()== σ(Type())) where σ is the type substitution of Parent().TypeParams by Parent().TypeArgs.

This operation cannot fail dynamically.

Type changes may to be to or from a type parameter (or both). All types in the type set of X.Type() have a value-preserving type change to all types in the type set of Type().

Example printed form:

t1 = changetype *int <- IntPtr (t0)

func (Builder) Complex added in v0.8.9

func (b Builder) Complex(r, i Expr) Expr

func (Builder) Const

func (b Builder) Const(v constant.Value, typ Type) Expr

Const returns a constant expression.

func (Builder) Convert added in v0.3.0

func (b Builder) Convert(t Type, x Expr) (ret Expr)

The Convert instruction yields the conversion of value X to type Type(). One or both of those types is basic (but possibly named).

A conversion may change the value and representation of its operand. Conversions are permitted:

  • between real numeric types.
  • between complex numeric types.
  • between string and []byte or []rune.
  • between pointers and unsafe.Pointer.
  • between unsafe.Pointer and uintptr.
  • from (Unicode) integer to (UTF-8) string.

A conversion may imply a type name change also.

Conversions may to be to or from a type parameter. All types in the type set of X.Type() can be converted to all types in the type set of Type().

This operation cannot fail dynamically.

Conversions of untyped string/number/bool constants to a specific representation are eliminated during SSA construction.

Example printed form:

t1 = convert []byte <- string (t0)

func (Builder) DIDeclare added in v0.9.8

func (b Builder) DIDeclare(variable *types.Var, v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock)

func (Builder) DIGlobal added in v0.9.8

func (b Builder) DIGlobal(v Expr, name string, pos token.Position)

func (Builder) DIParam added in v0.9.8

func (b Builder) DIParam(variable *types.Var, v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock)

func (Builder) DIScope added in v0.9.8

func (b Builder) DIScope(f Function, scope *types.Scope) DIScope

func (Builder) DISetCurrentDebugLocation added in v0.9.8

func (b Builder) DISetCurrentDebugLocation(diScope DIScope, pos token.Position)

func (Builder) DIValue added in v0.9.8

func (b Builder) DIValue(variable *types.Var, v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock)

func (Builder) DIVarAuto added in v0.9.8

func (b Builder) DIVarAuto(scope DIScope, pos token.Position, varName string, vt Type) DIVar

func (Builder) DIVarParam added in v0.9.8

func (b Builder) DIVarParam(scope DIScope, pos token.Position, varName string, vt Type, argNo int) DIVar

func (Builder) DebugFunction added in v0.9.8

func (b Builder) DebugFunction(f Function, pos token.Position, bodyPos token.Position)

func (Builder) Defer added in v0.8.6

func (b Builder) Defer(kind DoAction, fn Expr, args ...Expr)

Defer emits a defer instruction.

func (Builder) DeferData added in v0.8.7

func (b Builder) DeferData() Expr

DeferData returns the defer data (*runtime.Defer).

func (Builder) Dispose added in v0.8.0

func (b Builder) Dispose()

Dispose disposes of the builder.

func (Builder) Do added in v0.8.6

func (b Builder) Do(da DoAction, fn Expr, args ...Expr) (ret Expr)

Do call a function with an action.

func (Builder) EndBuild added in v0.8.6

func (b Builder) EndBuild()

EndBuild ends the build process of a function.

func (Builder) Extract added in v0.6.0

func (b Builder) Extract(x Expr, i int) (ret Expr)

The Extract instruction yields component Index of Tuple.

This is used to access the results of instructions with multiple return values, such as Call, TypeAssert, Next, UnOp(ARROW) and IndexExpr(Map).

Example printed form:

t1 = extract t0 #1

func (Builder) Field added in v0.5.0

func (b Builder) Field(x Expr, idx int) Expr

The Field instruction yields the value of Field of struct X.

func (Builder) FieldAddr added in v0.3.0

func (b Builder) FieldAddr(x Expr, idx int) Expr

The FieldAddr instruction yields the address of Field of *struct X.

The field is identified by its index within the field list of the struct type of X.

Dynamically, this instruction panics if X evaluates to a nil pointer.

Type() returns a (possibly named) *types.Pointer.

Example printed form:

t1 = &t0.name [#1]

func (Builder) Go added in v0.8.6

func (b Builder) Go(fn Expr, args ...Expr)

The Go instruction creates a new goroutine and calls the specified function within it.

Example printed form:

go println(t0, t1)
go t3()
go invoke t5.Println(...t6)

func (Builder) GoBytes added in v0.9.8

func (b Builder) GoBytes(v Expr, n Expr) (ret Expr)

GoBytes returns a Go bytes

func (Builder) GoString added in v0.9.8

func (b Builder) GoString(v Expr) Expr

GoString returns a Go string

func (Builder) GoStringN added in v0.9.8

func (b Builder) GoStringN(v Expr, n Expr) Expr

GoStringN returns a Go string

func (Builder) If

func (b Builder) If(cond Expr, thenb, elseb BasicBlock)

If emits an if instruction.

func (Builder) IfThen added in v0.8.6

func (b Builder) IfThen(cond Expr, then func())

IfThen emits an if-then instruction.

func (Builder) Imethod added in v0.8.5

func (b Builder) Imethod(intf Expr, method *types.Func) Expr

Imethod returns closure of an interface method.

func (Builder) Index added in v0.5.0

func (b Builder) Index(x, idx Expr, takeAddr func() (addr Expr, zero bool)) Expr

The Index instruction yields element Index of collection X, an array, string or type parameter containing an array, a string, a pointer to an, array or a slice.

Example printed form:

t2 = t0[t1]

func (Builder) IndexAddr

func (b Builder) IndexAddr(x, idx Expr) Expr

The IndexAddr instruction yields the address of the element at index `idx` of collection `x`. `idx` is an integer expression.

The elements of maps and strings are not addressable; use Lookup (map), Index (string), or MapUpdate instead.

Dynamically, this instruction panics if `x` evaluates to a nil *array pointer.

Example printed form:

t2 = &t0[t1]

func (Builder) IndirectJump added in v0.8.7

func (b Builder) IndirectJump(addr Expr, dests []BasicBlock)

IndirectJump emits an indirect jump instruction.

func (Builder) InlineAsm added in v0.11.6

func (b Builder) InlineAsm(instruction string)

InlineAsm generates inline assembly instruction

func (Builder) InlineAsmFull added in v0.11.6

func (b Builder) InlineAsmFull(instruction, constraints string, retType Type, exprs []Expr) Expr

func (Builder) InlineCall added in v0.3.0

func (b Builder) InlineCall(fn Expr, args ...Expr) (ret Expr)

TODO(xsw): make inline call

func (Builder) Jump

func (b Builder) Jump(jmpb BasicBlock)

Jump emits a jump instruction.

func (Builder) Load

func (b Builder) Load(ptr Expr) Expr

Load returns the value at the pointer ptr.

func (Builder) Longjmp added in v0.11.1

func (b Builder) Longjmp(jb, retval Expr)

func (Builder) Lookup added in v0.6.0

func (b Builder) Lookup(x, key Expr, commaOk bool) (ret Expr)

The Lookup instruction yields element Index of collection map X. Index is the appropriate key type.

If CommaOk, the result is a 2-tuple of the value above and a boolean indicating the result of a map membership test for the key. The components of the tuple are accessed using Extract.

Example printed form:

t2 = t0[t1]
t5 = t3[t4],ok

func (Builder) MakeChan added in v0.8.10

func (b Builder) MakeChan(t Type, size Expr) (ret Expr)

The MakeChan instruction creates a new channel object and yields a value of kind chan.

Type() returns a (possibly named) *types.Chan.

Pos() returns the ast.CallExpr.Lparen for the make(chan) that created it.

Example printed form:

t0 = make chan int 0
t0 = make IntChan 0

type MakeChan struct {
	register
	Size Value // int; size of buffer; zero => synchronous.
}

func (Builder) MakeClosure added in v0.6.0

func (b Builder) MakeClosure(fn Expr, bindings []Expr) Expr

The MakeClosure instruction yields a closure value whose code is Fn and whose free variables' values are supplied by Bindings.

Type() returns a (possibly named) *types.Signature.

Example printed form:

t0 = make closure [email protected] [x y z]
t1 = make closure bound$(main.I).add [i]

func (Builder) MakeInterface added in v0.3.0

func (b Builder) MakeInterface(tinter Type, x Expr) (ret Expr)

MakeInterface constructs an instance of an interface type from a value of a concrete type.

Use Program.MethodSets.MethodSet(X.Type()) to find the method-set of X, and Program.MethodValue(m) to find the implementation of a method.

To construct the zero value of an interface type T, use:

NewConst(constant.MakeNil(), T, pos)

Example printed form:

t1 = make interface{} <- int (42:int)
t2 = make Stringer <- t0

func (Builder) MakeMap added in v0.4.0

func (b Builder) MakeMap(t Type, nReserve Expr) (ret Expr)

The MakeMap instruction creates a new hash-table-based map object and yields a value of kind map.

t is a (possibly named) *types.Map.

Example printed form:

t1 = make map[string]int t0
t1 = make StringIntMap t0

func (Builder) MakeSlice added in v0.5.0

func (b Builder) MakeSlice(t Type, len, cap Expr) (ret Expr)

The MakeSlice instruction yields a slice of length Len backed by a newly allocated array of length Cap.

Both Len and Cap must be non-nil Values of integer type.

(Alloc(types.Array) followed by Slice will not suffice because Alloc can only create arrays of constant length.)

Type() returns a (possibly named) *types.Slice.

Example printed form:

t1 = make []string 1:int t0
t1 = make StringSlice 1:int t0

func (Builder) MakeString added in v0.8.9

func (b Builder) MakeString(cstr Expr, n ...Expr) (ret Expr)

MakeString creates a new string from a C string pointer and length.

func (Builder) MapUpdate added in v0.4.0

func (b Builder) MapUpdate(m, k, v Expr)

The MapUpdate instruction updates the association of Map[Key] to Value.

Pos() returns the ast.KeyValueExpr.Colon or ast.IndexExpr.Lbrack, if explicit in the source.

Example printed form:

t0[t1] = t2

func (Builder) Next added in v0.8.5

func (b Builder) Next(typ Type, iter Expr, isString bool) Expr

The Next instruction reads and advances the (map or string) iterator Iter and returns a 3-tuple value (ok, k, v). If the iterator is not exhausted, ok is true and k and v are the next elements of the domain and range, respectively. Otherwise ok is false and k and v are undefined.

Components of the tuple are accessed using Extract.

The IsString field distinguishes iterators over strings from those over maps, as the Type() alone is insufficient: consider map[int]rune.

Type() returns a *types.Tuple for the triple (ok, k, v). The types of k and/or v may be types.Invalid.

Example printed form:

t1 = next t0

func (Builder) Panic added in v0.3.0

func (b Builder) Panic(v Expr)

Panic emits a panic instruction.

func (Builder) Param added in v0.9.8

func (b Builder) Param(idx int) Expr

func (Builder) Phi added in v0.4.0

func (b Builder) Phi(t Type) Phi

Phi returns a phi node.

func (Builder) PrintEx added in v0.8.5

func (b Builder) PrintEx(ln bool, args ...Expr) (ret Expr)

PrintEx prints the arguments to stderr.

func (Builder) Printf added in v0.11.0

func (b Builder) Printf(fmt string, args ...Expr) Expr

func (Builder) Println added in v0.8.5

func (b Builder) Println(args ...Expr) (ret Expr)

Println prints the arguments to stderr, followed by a newline.

func (Builder) PyBool added in v0.11.6

func (b Builder) PyBool(bVal Expr) (ret Expr)

PyBool(bVal bool) *Object

func (Builder) PyByteArray added in v0.11.6

func (b Builder) PyByteArray(v Expr) Expr

PyByteArray(val []byte) *Object

func (Builder) PyBytes added in v0.11.6

func (b Builder) PyBytes(v Expr) Expr

PyBytes(val [...]byte) *Object

func (Builder) PyComplex128 added in v0.11.6

func (b Builder) PyComplex128(v Expr) Expr

PyComplex128(val complex128) *Object

func (Builder) PyComplex64 added in v0.11.6

func (b Builder) PyComplex64(v Expr) Expr

PyComplex64(val complex64) *Object

func (Builder) PyFloat added in v0.8.2

func (b Builder) PyFloat(fltVal Expr) (ret Expr)

PyFloat(fltVal float64) *Object

func (Builder) PyImportMod added in v0.8.2

func (b Builder) PyImportMod(path string) Expr

PyImportMod imports a Python module.

func (Builder) PyInt64 added in v0.11.6

func (b Builder) PyInt64(intVal Expr) (ret Expr)

PyInt64(val int64) *Object

func (Builder) PyList added in v0.8.2

func (b Builder) PyList(args ...Expr) (ret Expr)

PyList(args ...Expr) *Object

func (Builder) PyListSetItem added in v0.8.2

func (b Builder) PyListSetItem(list, index, item Expr) (ret Expr)

PyListSetItem(list *Object, index uintptr, item *Object) c.Int

func (Builder) PyLoadModSyms added in v0.8.2

func (b Builder) PyLoadModSyms(modName string, objs ...PyObjRef) Expr

PyLoadModSyms loads python objects from specified module.

func (Builder) PyNewList added in v0.8.2

func (b Builder) PyNewList(n Expr) (ret Expr)

PyNewList(n uintptr) *Object

func (Builder) PyNewTuple added in v0.9.7

func (b Builder) PyNewTuple(n Expr) (ret Expr)

PyNewTuple(n int) *Object

func (Builder) PyNewVar added in v0.8.2

func (b Builder) PyNewVar(modName, name string) PyGlobal

PyNewVar creates a Python variable.

func (Builder) PyStr added in v0.9.0

func (b Builder) PyStr(v string) Expr

PyStr returns a py-style string constant expression.

func (Builder) PyStrExpr added in v0.11.6

func (b Builder) PyStrExpr(v Expr) Expr

PyStrExpr(str string) *Object

func (Builder) PyTuple added in v0.9.7

func (b Builder) PyTuple(args ...Expr) (ret Expr)

PyTuple(args ...Expr) *Object

func (Builder) PyTupleSetItem added in v0.9.7

func (b Builder) PyTupleSetItem(list, index, item Expr) (ret Expr)

PyTupleSetItem(list *Object, index uintptr, item *Object) c.Int

func (Builder) PyUint64 added in v0.11.6

func (b Builder) PyUint64(uintVal Expr) (ret Expr)

PyUint64(val uint64) *Object

func (Builder) PyVal added in v0.8.2

func (b Builder) PyVal(v Expr) (ret Expr)

PyVal(v any) *Object

func (Builder) Range added in v0.8.5

func (b Builder) Range(x Expr) Expr

The Range instruction yields an iterator over the domain and range of X, which must be a string or map.

Elements are accessed via Next.

Type() returns an opaque and degenerate "rangeIter" type.

Pos() returns the ast.RangeStmt.For.

Example printed form:

t0 = range "hello":string

func (Builder) Recover added in v0.8.8

func (b Builder) Recover() Expr

Recover emits a recover instruction.

func (Builder) Recv added in v0.8.10

func (b Builder) Recv(ch Expr, commaOk bool) (ret Expr)

func (Builder) Return

func (b Builder) Return(results ...Expr)

Return emits a return instruction.

func (Builder) RunDefers added in v0.8.6

func (b Builder) RunDefers()

RunDefers emits instructions to run deferred instructions.

func (Builder) Select added in v0.9.0

func (b Builder) Select(states []*SelectState, blocking bool) (ret Expr)

The Select instruction tests whether (or blocks until) one of the specified sent or received states is entered.

Let n be the number of States for which Dir==RECV and T_i (0<=i<n) be the element type of each such state's Chan. Select returns an n+2-tuple

(index int, recvOk bool, r_0 T_0, ... r_n-1 T_n-1)

The tuple's components, described below, must be accessed via the Extract instruction.

If Blocking, select waits until exactly one state holds, i.e. a channel becomes ready for the designated operation of sending or receiving; select chooses one among the ready states pseudorandomly, performs the send or receive operation, and sets 'index' to the index of the chosen channel.

If !Blocking, select doesn't block if no states hold; instead it returns immediately with index equal to -1.

If the chosen channel was used for a receive, the r_i component is set to the received value, where i is the index of that state among all n receive states; otherwise r_i has the zero value of type T_i. Note that the receive index i is not the same as the state index index.

The second component of the triple, recvOk, is a boolean whose value is true iff the selected operation was a receive and the receive successfully yielded a value.

Pos() returns the ast.SelectStmt.Select.

Example printed form:

t3 = select nonblocking [<-t0, t1<-t2]
t4 = select blocking []

func (Builder) Send added in v0.8.10

func (b Builder) Send(ch Expr, x Expr) (ret Expr)

The Send instruction sends X on channel Chan.

Pos() returns the ast.SendStmt.Arrow, if explicit in the source.

Example printed form:

send t0 <- t1

func (Builder) SetBlock

func (b Builder) SetBlock(blk BasicBlock) Builder

SetBlock means SetBlockEx(blk, AtEnd, true).

func (Builder) SetBlockEx added in v0.8.0

func (b Builder) SetBlockEx(blk BasicBlock, pos InsertPoint, setBlk bool)

SetBlockEx sets blk as current basic block and pos as its insert point.

func (Builder) Setjmp added in v0.11.1

func (b Builder) Setjmp(jb Expr) Expr

func (Builder) Siglongjmp added in v0.8.7

func (b Builder) Siglongjmp(jb, retval Expr)

func (Builder) Sigsetjmp added in v0.8.7

func (b Builder) Sigsetjmp(jb, savemask Expr) Expr

func (Builder) Slice added in v0.4.0

func (b Builder) Slice(x, low, high, max Expr) (ret Expr)

The Slice instruction yields a slice of an existing string, slice or *array X between optional integer bounds Low and High.

Dynamically, this instruction panics if X evaluates to a nil *array pointer.

Type() returns string if the type of X was string, otherwise a *types.Slice with the same element type as X.

Example printed form:

t1 = slice t0[1:]

func (Builder) SliceCap added in v0.8.2

func (b Builder) SliceCap(x Expr) Expr

SliceCap returns the length of a slice cap.

func (Builder) SliceData added in v0.8.2

func (b Builder) SliceData(x Expr) Expr

SliceData returns the data pointer of a slice.

func (Builder) SliceLen added in v0.8.2

func (b Builder) SliceLen(x Expr) Expr

SliceLen returns the length of a slice.

func (Builder) SliceLit added in v0.8.5

func (b Builder) SliceLit(t Type, elts ...Expr) Expr

SliceLit creates a new slice with the specified elements.

func (Builder) SliceToArrayPointer added in v0.9.7

func (b Builder) SliceToArrayPointer(x Expr, typ Type) (ret Expr)

The SliceToArrayPointer instruction yields the conversion of slice X to array pointer.

Pos() returns the ast.CallExpr.Lparen, if the instruction arose from an explicit conversion in the source.

Conversion may to be to or from a type parameter. All types in the type set of X.Type() must be a slice types that can be converted to all types in the type set of Type() which must all be pointer to array types.

This operation can fail dynamically if the length of the slice is less than the length of the array.

Example printed form:

t1 = slice to array pointer *[4]byte <- []byte (t0)

func (Builder) StackSave added in v0.11.6

func (b Builder) StackSave() Expr

declare ptr @llvm.stacksave.p0()

func (Builder) Store

func (b Builder) Store(ptr, val Expr) Expr

Store stores val at the pointer ptr.

func (Builder) Str added in v0.4.0

func (b Builder) Str(v string) Expr

Str returns a Go string constant expression.

func (Builder) StringData added in v0.8.0

func (b Builder) StringData(x Expr) Expr

StringData returns the data pointer of a string.

func (Builder) StringLen added in v0.8.0

func (b Builder) StringLen(x Expr) Expr

StringLen returns the length of a string.

func (Builder) Times added in v0.9.1

func (b Builder) Times(n Expr, loop func(i Expr))

Times emits a times-loop instruction.

func (Builder) TypeAssert added in v0.3.0

func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) Expr

The TypeAssert instruction tests whether interface value X has type AssertedType.

If !CommaOk, on success it returns v, the result of the conversion (defined below); on failure it panics.

If CommaOk: on success it returns a pair (v, true) where v is the result of the conversion; on failure it returns (z, false) where z is AssertedType's zero value. The components of the pair must be accessed using the Extract instruction.

If Underlying: tests whether interface value X has the underlying type AssertedType.

If AssertedType is a concrete type, TypeAssert checks whether the dynamic type in interface X is equal to it, and if so, the result of the conversion is a copy of the value in the interface.

If AssertedType is an interface, TypeAssert checks whether the dynamic type of the interface is assignable to it, and if so, the result of the conversion is a copy of the interface value X. If AssertedType is a superinterface of X.Type(), the operation will fail iff the operand is nil. (Contrast with ChangeInterface, which performs no nil-check.)

Type() reflects the actual type of the result, possibly a 2-types.Tuple; AssertedType is the asserted type.

Depending on the TypeAssert's purpose, Pos may return:

  • the ast.CallExpr.Lparen of an explicit T(e) conversion;
  • the ast.TypeAssertExpr.Lparen of an explicit e.(T) operation;
  • the ast.CaseClause.Case of a case of a type-switch statement;
  • the Ident(m).NamePos of an interface method value i.m (for which TypeAssert may be used to effect the nil check).

Example printed form:

t1 = typeassert t0.(int)
t3 = typeassert,ok t2.(T)

func (Builder) UnOp

func (b Builder) UnOp(op token.Token, x Expr) (ret Expr)

The UnOp instruction yields the result of (op x). ARROW is channel receive. MUL is pointer indirection (load). XOR is bitwise complement. SUB is negation. NOT is logical negation.

func (Builder) Unreachable added in v0.4.0

func (b Builder) Unreachable()

Unreachable emits an unreachable instruction.

type CompilationUnit added in v0.9.8

type CompilationUnit = *aCompilationUnit

type DIExpression added in v0.9.8

type DIExpression = *aDIExpression

type DIFile added in v0.9.8

type DIFile = *aDIFile

type DIFunction added in v0.9.8

type DIFunction = *aDIFunction

type DIGlobalVariableExpression added in v0.9.8

type DIGlobalVariableExpression = *aDIGlobalVariableExpression

type DILexicalBlock added in v0.9.8

type DILexicalBlock = *aDILexicalBlock

type DIScope added in v0.9.8

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

type DIScopeMeta added in v0.9.8

type DIScopeMeta = *aDIScopeMeta

type DIType added in v0.9.8

type DIType = *aDIType

type DIVar added in v0.9.8

type DIVar = *aDIVar

type DoAction added in v0.8.6

type DoAction int
const (
	Call DoAction = iota
	Go
	DeferAlways // defer statement executes always
	DeferInCond // defer statement executes in a conditional block
	DeferInLoop // defer statement executes in a loop block
)

type Expr

type Expr struct {
	Type
	// contains filtered or unexported fields
}
var Nil Expr // Zero value is a nil Expr

func Builtin added in v0.8.6

func Builtin(name string) Expr

Builtin returns a builtin function expression.

func SizeOf added in v0.8.5

func SizeOf(prog Program, t Type, n ...int64) Expr

SizeOf returns the size of a type.

func (Expr) IsNil added in v0.4.0

func (v Expr) IsNil() bool

IsNil checks if the expression is nil or not.

func (Expr) Name added in v0.9.9

func (v Expr) Name() string

func (Expr) SetName added in v0.9.9

func (v Expr) SetName(alias string) Expr

func (Expr) SetOrdering added in v0.8.9

func (v Expr) SetOrdering(ordering AtomicOrdering) Expr

SetOrdering sets the ordering of the atomic operation.

type Function

type Function = *aFunction

Function represents a function or method.

func (Function) Block

func (p Function) Block(idx int) BasicBlock

Block returns the ith basic block of the function.

func (Function) FreeVar added in v0.6.0

func (p Function) FreeVar(b Builder, i int) Expr

FreeVar returns the function's ith free variable.

func (Function) HasBody added in v0.6.0

func (p Function) HasBody() bool

HasBody reports whether the function has a body.

func (Function) Inline added in v0.9.8

func (p Function) Inline(inline inlineAttr)

func (Function) MakeBlock added in v0.8.0

func (p Function) MakeBlock() BasicBlock

MakeBlock creates a new basic block for the function.

func (Function) MakeBlocks

func (p Function) MakeBlocks(nblk int) []BasicBlock

MakeBlocks creates nblk basic blocks for the function.

func (Function) MakeBody

func (p Function) MakeBody(nblk int) Builder

MakeBody creates nblk basic blocks for the function, and creates a new Builder associated to #0 block.

func (Function) Name added in v0.8.9

func (p Function) Name() string

Name returns the function's name.

func (Function) NewBuilder

func (p Function) NewBuilder() Builder

NewBuilder creates a new Builder for the function.

func (Function) Param

func (p Function) Param(i int) Expr

Params returns the function's ith parameter.

func (Function) SetRecover added in v0.8.8

func (p Function) SetRecover(blk BasicBlock)

SetRecover sets the recover block for the function.

type Global

type Global = *aGlobal

A Global is a named Value holding the address of a package-level variable.

func (Global) Init

func (g Global) Init(v Expr)

Init initializes the global variable with the given value.

func (Global) InitNil added in v0.8.8

func (g Global) InitNil()

func (Global) ReplaceAllUsesWith added in v0.9.9

func (g Global) ReplaceAllUsesWith(v Expr)

type InitFlags

type InitFlags int

InitFlags is a set of flags for initializing the LLVM library.

const (
	InitNativeTarget InitFlags = 1 << iota
	InitAllTargets
	InitAllTargetInfos
	InitAllTargetMCs

	InitNativeAsmPrinter
	InitAllAsmPrinters

	InitAllAsmParsers

	InitNative = InitNativeTarget | InitNativeAsmPrinter
	InitAll    = InitAllTargets | InitAllAsmParsers | InitAllAsmPrinters | InitAllTargetInfos | InitAllTargetMCs
)

type InsertPoint added in v0.8.0

type InsertPoint int
const (
	AtEnd InsertPoint = iota
	AtStart
	BeforeLast
)

type NamedConst

type NamedConst = *aNamedConst

A NamedConst is a Member of a Package representing a package-level named constant.

Pos() returns the position of the declaring ast.ValueSpec.Names[*] identifier.

NB: a NamedConst is not a Value; it contains a constant Value, which it augments with the name and position of its 'const' declaration.

type Package

type Package = *aPackage

func (Package) AddGlobalString added in v0.11.6

func (pkg Package) AddGlobalString(name string, value string)

func (Package) AfterInit added in v0.8.5

func (p Package) AfterInit(b Builder, ret BasicBlock)

AfterInit is called after the package is initialized (init all packages that depends on).

func (Package) ConstString added in v0.11.6

func (pkg Package) ConstString(value string) Expr

ConstString creates an SSA expression representing a Go string literal. The returned value is backed by an anonymous global constant and can be used to initialize package-level variables or other constant contexts that expect a Go string value.

func (Package) ExportFuncs added in v0.11.6

func (p Package) ExportFuncs() map[string]string

func (Package) FuncOf

func (p Package) FuncOf(name string) Function

FuncOf returns a function by name.

func (Package) InitAbiTypes added in v0.12.0

func (p Package) InitAbiTypes(fname string) Function

func (Package) InitDebug added in v0.11.0

func (p Package) InitDebug(name, pkgPath string, positioner Positioner)

func (Package) Module added in v0.11.6

func (p Package) Module() llvm.Module

func (Package) NewFunc

func (p Package) NewFunc(name string, sig *types.Signature, bg Background) Function

NewFunc creates a new function.

func (Package) NewFuncEx added in v0.6.0

func (p Package) NewFuncEx(name string, sig *types.Signature, bg Background, hasFreeVars bool, instantiated bool) Function

NewFuncEx creates a new function.

func (Package) NewVar

func (p Package) NewVar(name string, typ types.Type, bg Background) Global

NewVar creates a new global variable.

func (Package) NewVarEx added in v0.8.6

func (p Package) NewVarEx(name string, t Type) Global

NewVarEx creates a new global variable.

func (Package) Path added in v0.8.5

func (p Package) Path() string

Path returns the package path.

func (Package) PyNewFunc added in v0.8.2

func (p Package) PyNewFunc(name string, sig *types.Signature, doInit bool) PyObjRef

PyNewFunc creates a new python function.

func (Package) PyNewModVar added in v0.8.2

func (p Package) PyNewModVar(name string, doInit bool) Global

PyNewModVar creates a new global variable for a Python module.

func (Package) PyObjOf added in v0.8.0

func (p Package) PyObjOf(name string) PyObjRef

PyObjOf returns a python object by name.

func (Package) SetExport added in v0.11.6

func (p Package) SetExport(name, export string)

func (Package) SetResolveLinkname added in v0.9.5

func (p Package) SetResolveLinkname(fn func(string) string)

SetResolveLinkname sets a function to resolve linkname.

func (Package) String

func (p Package) String() string

String returns a string representation of the package.

func (Package) Undefined added in v0.11.6

func (pkg Package) Undefined(names ...string) error

Undefined global string var by names

func (Package) VarOf

func (p Package) VarOf(name string) Global

VarOf returns a global variable by name.

type Phi added in v0.4.0

type Phi struct {
	Expr
}

Phi represents a phi node.

func (Phi) AddIncoming added in v0.4.0

func (p Phi) AddIncoming(b Builder, preds []BasicBlock, f func(i int, blk BasicBlock) Expr)

AddIncoming adds incoming values to a phi node.

type Positioner added in v0.9.8

type Positioner interface {
	Position(pos token.Pos) token.Position
}

type Program

type Program = *aProgram

A Program presents a program.

func NewProgram

func NewProgram(target *Target) Program

NewProgram creates a new program.

func (Program) AbiType added in v0.12.0

func (p Program) AbiType() Type

AbiType returns abi.Type type.

func (Program) AbiTypePtr added in v0.8.5

func (p Program) AbiTypePtr() Type

AbiTypePtr returns *abi.Type type.

func (Program) Any added in v0.3.0

func (p Program) Any() Type

Any returns the any (empty interface) type.

func (Program) Bool

func (p Program) Bool() Type

Bool returns bool type.

func (Program) BoolVal

func (p Program) BoolVal(v bool) Expr

BoolVal returns a boolean constant expression.

func (Program) Byte added in v0.8.3

func (p Program) Byte() Type

Byte returns byte type.

func (Program) CInt added in v0.8.2

func (p Program) CInt() Type

CInt returns c.Int type.

func (Program) CIntPtr added in v0.8.7

func (p Program) CIntPtr() Type

CIntPtr returns *c.Int type.

func (Program) CStr added in v0.4.0

func (p Program) CStr() Type

CStr returns *int8 type.

func (Program) Closure added in v0.6.0

func (p Program) Closure(sig *types.Signature) Type

Closure creates a closture type for a function.

func (Program) Complex128 added in v0.8.9

func (p Program) Complex128() Type

Complex128 returns complex128 type.

func (Program) Complex64 added in v0.8.9

func (p Program) Complex64() Type

Complex64 returns complex64 type.

func (Program) ComplexVal added in v0.8.9

func (p Program) ComplexVal(v complex128, t Type) Expr

ComplexVal returns a complex constant expression.

func (Program) Defer added in v0.8.6

func (p Program) Defer() Type

Defer returns runtime.Defer type.

func (Program) DeferPtr added in v0.8.6

func (p Program) DeferPtr() Type

DeferPtr returns *runtime.Defer type.

func (Program) Elem

func (p Program) Elem(typ Type) Type

func (Program) Field added in v0.3.0

func (p Program) Field(typ Type, i int) Type

func (Program) Float32 added in v0.8.5

func (p Program) Float32() Type

Float32 returns float32 type.

func (Program) Float64

func (p Program) Float64() Type

Float64 returns float64 type.

func (Program) FloatVal added in v0.4.0

func (p Program) FloatVal(v float64, t Type) Expr

FloatVal returns a float constant expression.

func (Program) FuncDecl added in v0.6.0

func (p Program) FuncDecl(sig *types.Signature, bg Background) Type

FuncDecl converts a Go/C function declaration into raw type.

func (Program) Index

func (p Program) Index(typ Type) Type

func (Program) Int

func (p Program) Int() Type

Int returns int type.

func (Program) Int32 added in v0.8.3

func (p Program) Int32() Type

Int32 returns int32 type.

func (Program) Int64 added in v0.8.3

func (p Program) Int64() Type

Int64 returns int64 type.

func (Program) IntVal

func (p Program) IntVal(v uint64, t Type) Expr

IntVal returns an integer constant expression.

func (Program) Linkname added in v0.9.7

func (p Program) Linkname(name string) (link string, ok bool)

func (Program) NewPackage

func (p Program) NewPackage(name, pkgPath string) Package

NewPackage creates a new package.

func (Program) Nil added in v0.8.7

func (p Program) Nil(t Type) Expr

Nil returns a null constant expression. t should be a pointer type.

func (Program) OffsetOf added in v0.8.5

func (p Program) OffsetOf(typ Type, i int) uint64

OffsetOf returns the offset of a field in a struct.

func (Program) Pointer

func (p Program) Pointer(typ Type) Type

func (Program) PointerSize added in v0.8.5

func (p Program) PointerSize() int

func (Program) PyObjectPtr added in v0.8.0

func (p Program) PyObjectPtr() Type

PyObjectPtr returns the *py.Object type.

func (Program) PyObjectPtrPtr added in v0.8.0

func (p Program) PyObjectPtrPtr() Type

PyObjectPtrPtr returns the **py.Object type.

func (Program) SetCompileMethods added in v0.12.0

func (p Program) SetCompileMethods(check func(Package, types.Type))

func (Program) SetLinkname added in v0.9.7

func (p Program) SetLinkname(name, link string)

func (Program) SetPatch added in v0.9.8

func (p Program) SetPatch(patchType func(types.Type) types.Type)

func (Program) SetPython added in v0.8.0

func (p Program) SetPython(py any)

SetPython sets the Python package. Its type can be *types.Package or func() *types.Package.

func (Program) SetRuntime added in v0.3.0

func (p Program) SetRuntime(runtime any)

SetRuntime sets the runtime. Its type can be *types.Package or func() *types.Package.

func (Program) SetTypeBackground added in v0.9.2

func (p Program) SetTypeBackground(fullName string, bg Background)

func (Program) SizeOf added in v0.5.0

func (p Program) SizeOf(typ Type, n ...int64) uint64

TODO(xsw): how to generate platform independent code?

func (Program) Slice added in v0.4.0

func (p Program) Slice(typ Type) Type

func (Program) String added in v0.3.0

func (p Program) String() Type

String returns string type.

func (Program) Struct added in v0.8.5

func (p Program) Struct(typs ...Type) Type

Struct returns a struct type.

func (Program) Target added in v0.11.6

func (p Program) Target() *Target

func (Program) TargetData added in v0.11.6

func (p Program) TargetData() llvm.TargetData

func (Program) Type

func (p Program) Type(typ types.Type, bg Background) Type

Type convert a Go/C type into raw type. C type = raw type Go type: convert to raw type (because of closure)

func (Program) TypeSizes added in v0.8.5

func (p Program) TypeSizes(sizes types.Sizes) types.Sizes

TypeSizes returns the sizes of the types.

func (Program) Uint added in v0.8.3

func (p Program) Uint() Type

Uint returns uint type.

func (Program) Uint16 added in v0.12.0

func (p Program) Uint16() Type

Uint16 returns uint16 type.

func (Program) Uint32 added in v0.8.3

func (p Program) Uint32() Type

Uint32 returns uint32 type.

func (Program) Uint64 added in v0.8.3

func (p Program) Uint64() Type

Uint64 returns uint64 type.

func (Program) Uintptr added in v0.3.0

func (p Program) Uintptr() Type

Uintptr returns uintptr type.

func (Program) Val

func (p Program) Val(v interface{}) Expr

Val returns a constant expression.

func (Program) Void

func (p Program) Void() Type

Void returns void type.

func (Program) VoidPtr added in v0.5.0

func (p Program) VoidPtr() Type

VoidPtr returns *void type.

func (Program) VoidPtrPtr added in v0.8.5

func (p Program) VoidPtrPtr() Type

VoidPtrPtr returns **void type.

func (Program) Zero added in v0.8.5

func (p Program) Zero(t Type) Expr

Zero returns a zero constant expression.

type PyGlobal added in v0.8.2

type PyGlobal = *aPyGlobal

type PyObjRef added in v0.8.0

type PyObjRef = *aPyObjRef

PyObjRef represents a python object reference.

type SelectState added in v0.9.0

type SelectState struct {
	Chan  Expr // channel to use (for send or receive)
	Value Expr // value to send (for send)
	Send  bool // direction of case (SendOnly or RecvOnly)
}

type Target

type Target struct {
	GOOS   string
	GOARCH string
	GOARM  string // "5", "6", "7" (default)
}

func (*Target) Spec added in v0.11.1

func (p *Target) Spec() (spec TargetSpec)

type TargetSpec added in v0.11.1

type TargetSpec struct {
	Triple   string
	CPU      string
	Features string
}

type Type

type Type = *aType

func (Type) RawType added in v0.6.0

func (t Type) RawType() types.Type

RawType returns the raw type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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