ssa

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbgFlagInstruction dbgFlags = 1 << iota

	DbgFlagAll = DbgFlagInstruction
)
View Source
const (
	NameValist = "__llgo_va_list"
)
View Source
const (
	PkgRuntime = "github.com/goplus/llgo/internal/runtime"
)

Variables

This section is empty.

Functions

func FullName added in v0.3.0

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

func HasVArg

func HasVArg(t *types.Tuple, n int) bool

func Initialize

func Initialize(flags InitFlags)

Initialize initializes the LLVM library.

func IsVArg

func IsVArg(arg *types.Var) bool

func NameOf added in v0.3.0

func NameOf(typ *types.Named) string

func PathOf added in v0.3.0

func PathOf(pkg *types.Package) string

func SetDebug

func SetDebug(dbgFlags dbgFlags)

SetDebug sets debug flags.

func VArg

func VArg() *types.Var

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

func (b Builder) Alloc(t *types.Pointer, 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) 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) Call

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

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) 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) 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.

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

Example printed form:

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

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.

Pos() returns the position of the ast.SelectorExpr.Sel for the field, if explicit in the source. For implicit selections, returns the position of the inducing explicit selection. If produced for a struct literal S{f: e}, it returns the position of the colon; for S{e} it returns the start of expression e.

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) 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) 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) MakeInterface added in v0.3.0

func (b Builder) MakeInterface(inter types.Type, x Expr, mayDelay bool) (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)

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

Example printed form:

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

func (Builder) Panic added in v0.3.0

func (b Builder) Panic(v Expr)

Panic emits a panic instruction.

func (Builder) Return

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

Return emits a return instruction.

func (Builder) SetBlock

func (b Builder) SetBlock(blk BasicBlock) Builder

SetBlock sets the current block to the specified basic block.

func (Builder) Store

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

Store stores val at the pointer ptr.

func (Builder) TypeAssert added in v0.3.0

func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) (ret 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) 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.

type Expr

type Expr struct {
	Type
	// contains filtered or unexported fields
}

func DelayExpr added in v0.3.0

func DelayExpr(f func() Expr) Expr

DelayExpr returns a delay expression.

func (Expr) Do added in v0.3.0

func (v Expr) Do() Expr

Do evaluates the delay expression and returns the result.

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) 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) 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.

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.

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 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) FuncOf

func (p Package) FuncOf(name string) Function

FuncOf returns a function by name.

func (Package) NewConst

func (p Package) NewConst(name string, val constant.Value) NamedConst

NewConst creates a new named constant.

func (Package) NewFunc

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

NewFunc creates a new function.

func (Package) NewVar

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

NewVar creates a new global variable.

func (Package) String

func (p Package) String() string

String returns a string representation of the package.

func (Package) VarOf

func (p Package) VarOf(name string) Global

VarOf returns a global variable by name.

type Program

type Program = *aProgram

A Program presents a program.

func NewProgram

func NewProgram(target *Target) Program

NewProgram creates a new program.

func (Program) Any added in v0.3.0

func (p Program) Any() Type

Any returns any 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) CString added in v0.3.0

func (p Program) CString() Type

func (Program) CStringVal added in v0.3.0

func (p Program) CStringVal(v string) Expr

CStringVal returns a c-style string constant expression.

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) Float64

func (p Program) Float64() Type

Float64 returns float64 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) IntVal

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

IntVal returns an integer constant expression.

func (Program) NeedRuntime added in v0.3.0

func (p Program) NeedRuntime() bool

NeedRuntime returns if the current package needs runtime.

func (Program) NewPackage

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

NewPackage creates a new package.

func (Program) Null

func (p Program) Null(t Type) Expr

Null returns a null constant expression.

func (Program) Pointer

func (p Program) Pointer(typ Type) Type

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) String added in v0.3.0

func (p Program) String() Type

func (Program) StringVal added in v0.3.0

func (p Program) StringVal(v string) Expr

StringVal returns string constant expression.

func (Program) Type

func (p Program) Type(typ types.Type) 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.

type Target

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

type Type

type Type = *aType

Jump to

Keyboard shortcuts

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