Documentation ¶
Index ¶
- Constants
- Variables
- func FullName(pkg *types.Package, name string) string
- func FuncAddCtx(ctx *types.Var, sig *types.Signature) *types.Signature
- func HasVArg(t *types.Tuple, n int) bool
- func Initialize(flags InitFlags)
- func IsVArg(arg *types.Var) bool
- func NameOf(typ *types.Named) string
- func PathOf(pkg *types.Package) string
- func SetDebug(dbgFlags dbgFlags)
- func VArg() *types.Var
- type Background
- type BasicBlock
- type Builder
- func (b Builder) Advance(ptr Expr, offset Expr) Expr
- func (b Builder) Alloc(elem Type, heap bool) (ret Expr)
- func (b Builder) Alloca(n Expr) (ret Expr)
- func (b Builder) AllocaCStr(gostr Expr) (ret Expr)
- func (b Builder) BinOp(op token.Token, x, y Expr) Expr
- func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr)
- func (b Builder) CStr(v string) Expr
- func (b Builder) Call(fn Expr, args ...Expr) (ret Expr)
- func (b Builder) CallPyInit() (ret Expr)
- func (b Builder) ChangeType(t Type, x Expr) (ret Expr)
- func (b Builder) Const(v constant.Value, typ Type) Expr
- func (b Builder) Convert(t Type, x Expr) (ret Expr)
- func (b Builder) Dispose()
- func (b Builder) Extract(x Expr, index int) (ret Expr)
- func (b Builder) Field(x Expr, idx int) Expr
- func (b Builder) FieldAddr(x Expr, idx int) Expr
- func (b Builder) If(cond Expr, thenb, elseb BasicBlock)
- func (b Builder) ImportPyMod(path string) Expr
- func (b Builder) Index(x, idx Expr, addr func(Expr) Expr) Expr
- func (b Builder) IndexAddr(x, idx Expr) Expr
- func (b Builder) InlineCall(fn Expr, args ...Expr) (ret Expr)
- func (b Builder) Jump(jmpb BasicBlock)
- func (b Builder) Load(ptr Expr) Expr
- func (b Builder) LoadPyModSyms(modName string, objs ...PyObjRef) Expr
- func (b Builder) Lookup(x, key Expr, commaOk bool) (ret Expr)
- func (b Builder) MakeClosure(fn Expr, bindings []Expr) Expr
- func (b Builder) MakeInterface(tinter Type, x Expr) (ret Expr)
- func (b Builder) MakeMap(t Type, nReserve Expr) (ret Expr)
- func (b Builder) MakeSlice(t Type, len, cap Expr) (ret Expr)
- func (b Builder) MapUpdate(m, k, v Expr)
- func (b Builder) Panic(v Expr)
- func (b Builder) Phi(t Type) Phi
- func (b Builder) Return(results ...Expr)
- func (b Builder) SetBlock(blk BasicBlock) Builder
- func (b Builder) SetBlockEx(blk BasicBlock, pos InsertPoint) Builder
- func (b Builder) SizeOf(t Type, n ...int64) Expr
- func (b Builder) Slice(x, low, high, max Expr) (ret Expr)
- func (b Builder) Store(ptr, val Expr) Builder
- func (b Builder) Str(v string) (ret Expr)
- func (b Builder) StringData(x Expr) Expr
- func (b Builder) StringLen(x Expr) Expr
- func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) (ret Expr)
- func (b Builder) UnOp(op token.Token, x Expr) (ret Expr)
- func (b Builder) Unreachable()
- type Expr
- type Function
- func (p Function) Block(idx int) BasicBlock
- func (p Function) FreeVar(b Builder, i int) Expr
- func (p Function) HasBody() bool
- func (p Function) MakeBlock() BasicBlock
- func (p Function) MakeBlocks(nblk int) []BasicBlock
- func (p Function) MakeBody(nblk int) Builder
- func (p Function) NewBuilder() Builder
- func (p Function) Param(i int) Expr
- type Global
- type InitFlags
- type InsertPoint
- type NamedConst
- type Package
- func (p Package) FuncOf(name string) Function
- func (p Package) NewFunc(name string, sig *types.Signature, bg Background) Function
- func (p Package) NewFuncEx(name string, sig *types.Signature, bg Background, hasFreeVars bool) Function
- func (p Package) NewPyFunc(name string, sig *types.Signature, doInit bool) PyObjRef
- func (p Package) NewPyModVar(name string, doInit bool) Global
- func (p Package) NewVar(name string, typ types.Type, bg Background) Global
- func (p Package) PyInit() bool
- func (p Package) PyObjOf(name string) PyObjRef
- func (p Package) PyObjs() map[string]PyObjRef
- func (p Package) String() string
- func (p Package) VarOf(name string) Global
- type Phi
- type Program
- func (p Program) Any() Type
- func (p Program) Bool() Type
- func (p Program) BoolVal(v bool) Expr
- func (p Program) CStr() Type
- func (p Program) Closure(fn Type) Type
- func (p Program) Elem(typ Type) Type
- func (p Program) Field(typ Type, i int) Type
- func (p Program) Float64() Type
- func (p Program) FloatVal(v float64, t Type) Expr
- func (p Program) FuncDecl(sig *types.Signature, bg Background) Type
- func (p Program) Index(typ Type) Type
- func (p Program) Int() Type
- func (p Program) IntVal(v uint64, t Type) Expr
- func (p Program) NewPackage(name, pkgPath string) Package
- func (p Program) Null(t Type) Expr
- func (p Program) Pointer(typ Type) Type
- func (p Program) PyObjectPtr() Type
- func (p Program) PyObjectPtrPtr() Type
- func (p Program) SetPython(py any)
- func (p Program) SetRuntime(runtime any)
- func (p Program) SizeOf(typ Type, n ...int64) uint64
- func (p Program) Slice(typ Type) Type
- func (p Program) String() Type
- func (p Program) Type(typ types.Type, bg Background) Type
- func (p Program) Uintptr() Type
- func (p Program) Val(v interface{}) Expr
- func (p Program) Void() Type
- func (p Program) VoidPtr() Type
- type PyObjRef
- type Target
- type Type
Constants ¶
const ( ClosureCtx = "__llgo_ctx" ClosureStub = "__llgo_stub." NameValist = "__llgo_va_list" )
const ( PkgPython = "github.com/goplus/llgo/py" PkgRuntime = "github.com/goplus/llgo/internal/runtime" )
const ( DbgFlagInstruction dbgFlags = 1 << iota DbgFlagAll = DbgFlagInstruction )
Variables ¶
var (
NoArgsNoRet = types.NewSignatureType(nil, nil, nil, nil, nil, false)
)
Functions ¶
func FuncAddCtx ¶ added in v0.6.0
FuncAddCtx adds a ctx to a function signature.
Types ¶
type BasicBlock ¶
type BasicBlock = *aBasicBlock
BasicBlock represents a basic block in a function.
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) Alloc ¶
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) AllocaCStr ¶ added in v0.4.0
AllocaCStr allocates space for copy it from a Go string.
func (Builder) BinOp ¶
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
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) Call ¶
The Call instruction represents a function or method 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() t7 = invoke t5.Println(...t6)
func (Builder) CallPyInit ¶ added in v0.8.0
CallPyInit calls Py_Initialize.
func (Builder) ChangeType ¶ added in v0.3.0
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) Convert ¶ added in v0.3.0
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) Dispose ¶ added in v0.8.0
func (b Builder) Dispose()
Dispose disposes of the builder.
func (Builder) Extract ¶ added in v0.6.0
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) FieldAddr ¶ added in v0.3.0
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) If ¶
func (b Builder) If(cond Expr, thenb, elseb BasicBlock)
If emits an if instruction.
func (Builder) ImportPyMod ¶ added in v0.8.0
ImportPyMod imports a Python module.
func (Builder) Index ¶ added in v0.5.0
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 ¶
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) InlineCall ¶ added in v0.3.0
TODO(xsw): make inline call
func (Builder) LoadPyModSyms ¶ added in v0.8.0
LoadPyModSyms loads python objects from specified module.
func (Builder) Lookup ¶ added in v0.6.0
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) MakeClosure ¶ added in v0.6.0
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 anon@1.2 [x y z] t1 = make closure bound$(main.I).add [i]
func (Builder) MakeInterface ¶ added in v0.3.0
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
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
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) MapUpdate ¶ added in v0.4.0
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) SetBlock ¶
func (b Builder) SetBlock(blk BasicBlock) Builder
SetBlock means SetBlockEx(blk, AtEnd).
func (Builder) SetBlockEx ¶ added in v0.8.0
func (b Builder) SetBlockEx(blk BasicBlock, pos InsertPoint) Builder
SetBlockEx sets blk as current basic block and pos as its insert point.
func (Builder) Slice ¶ added in v0.4.0
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) StringData ¶ added in v0.8.0
StringData returns the data pointer of a string.
func (Builder) TypeAssert ¶ added in v0.3.0
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 ¶
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 Expr ¶
type Expr struct { Type // contains filtered or unexported fields }
var Nil Expr // Zero value is a nil Expr
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) 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 ¶
MakeBody creates nblk basic blocks for the function, and creates a new Builder associated to #0 block.
func (Function) NewBuilder ¶
NewBuilder creates a new Builder for the function.
type Global ¶
type Global = *aGlobal
A Global is a named Value holding the address of a package-level variable.
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 AfterInit )
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) NewFuncEx ¶ added in v0.6.0
func (p Package) NewFuncEx(name string, sig *types.Signature, bg Background, hasFreeVars bool) Function
NewFuncEx creates a new function.
func (Package) NewPyModVar ¶ added in v0.8.0
NewPyModVar creates a new global variable for a Python module.
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, bblks []BasicBlock, f func(i int) Expr)
AddIncoming adds incoming values to a phi node.
type Program ¶
type Program = *aProgram
A Program presents a program.
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) NewPackage ¶
NewPackage creates a new package.
func (Program) PyObjectPtr ¶ added in v0.8.0
PyObjectPtr returns the *py.Object type.
func (Program) PyObjectPtrPtr ¶ added in v0.8.0
PyObjectPtrPtr returns the **py.Object type.
func (Program) SetPython ¶ added in v0.8.0
SetPython sets the Python package. Its type can be *types.Package or func() *types.Package.
func (Program) SetRuntime ¶ added in v0.3.0
SetRuntime sets the runtime. Its type can be *types.Package or func() *types.Package.
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)
type PyObjRef ¶ added in v0.8.0
type PyObjRef = *aPyObjRef
PyObjRef represents a python object reference.