Documentation ¶
Overview ¶
Package codegen provides an interface for code generation using LLVM.
codegen provides a higher-level and simpler interface for generating AOT or JIT code than using the LLVM go bindings directly.
Index ¶
- Variables
- func IsBool(ty Type) bool
- func IsFloat(ty Type) bool
- func IsInteger(ty Type) bool
- func IsPointer(ty Type) bool
- func IsSignedInteger(ty Type) bool
- func IsStruct(ty Type) bool
- func IsUnsignedInteger(ty Type) bool
- func IsVector(ty Type) bool
- type Array
- type Builder
- func (b *Builder) Add(x, y *Value) *Value
- func (b *Builder) AddS(x *Value, y interface{}) *Value
- func (b *Builder) AlignOf(ty Type) *Value
- func (b *Builder) And(x, y *Value) *Value
- func (b *Builder) Call(f Function, args ...*Value) *Value
- func (b *Builder) Div(x, y *Value) *Value
- func (b *Builder) DivS(x *Value, y interface{}) *Value
- func (b *Builder) Equal(x, y *Value) *Value
- func (b *Builder) ForN(n *Value, cb func(iterator *Value) (cont *Value))
- func (b *Builder) GlobalString(s string) *Value
- func (b *Builder) GreaterOrEqualTo(x, y *Value) *Value
- func (b *Builder) GreaterThan(x, y *Value) *Value
- func (b *Builder) If(cond *Value, onTrue func())
- func (b *Builder) IfElse(cond *Value, onTrue, onFalse func())
- func (b *Builder) Invert(x *Value) *Value
- func (b *Builder) IsBlockTerminated() bool
- func (b *Builder) LessOrEqualTo(x, y *Value) *Value
- func (b *Builder) LessThan(x, y *Value) *Value
- func (b *Builder) Local(name string, ty Type) *Value
- func (b *Builder) LocalInit(name string, val *Value) *Value
- func (b *Builder) Memcpy(dst, src, size *Value)
- func (b *Builder) Mul(x, y *Value) *Value
- func (b *Builder) MulS(x *Value, y interface{}) *Value
- func (b *Builder) Negate(x *Value) *Value
- func (b *Builder) Not(x *Value) *Value
- func (b *Builder) NotEqual(x, y *Value) *Value
- func (b *Builder) One(ty Type) *Value
- func (b *Builder) Or(x, y *Value) *Value
- func (b *Builder) Parameter(i int) *Value
- func (b *Builder) Rem(x, y *Value) *Value
- func (b *Builder) Return(val *Value)
- func (b *Builder) Scalar(v interface{}) *Value
- func (b *Builder) Select(cond, x, y *Value) *Value
- func (b *Builder) ShiftLeft(x, y *Value) *Value
- func (b *Builder) ShiftRight(x, y *Value) *Value
- func (b *Builder) Shuffle(x, y, indices *Value) *Value
- func (b *Builder) SizeOf(ty Type) *Value
- func (b *Builder) Sub(x, y *Value) *Value
- func (b *Builder) SubS(x *Value, y interface{}) *Value
- func (b *Builder) Switch(cases []SwitchCase, defaultCase func())
- func (b *Builder) Undef(ty Type) *Value
- func (b *Builder) Vector(el0 interface{}, els ...interface{}) *Value
- func (b *Builder) VectorN(n int, v interface{}) *Value
- func (b *Builder) While(test func() *Value, loop func())
- func (b *Builder) Xor(x, y *Value) *Value
- func (b *Builder) Zero(ty Type) *Value
- type Const
- type Executor
- type Field
- type Float
- type Function
- type FunctionType
- type Global
- type IndexOrName
- type Integer
- type Module
- func (m *Module) ConstStruct(ty *Struct, fields map[string]interface{}) Const
- func (m *Module) Executor(optimize bool) (*Executor, error)
- func (m *Module) Extern(name string, ty Type) Global
- func (m *Module) Function(resTy Type, name string, paramTys ...Type) Function
- func (m *Module) Global(name string, val Const) Global
- func (m *Module) Object(optimize bool) ([]byte, error)
- func (m *Module) Optimize()
- func (m *Module) ParseFunctionSignature(sig string) Function
- func (m *Module) Scalar(v interface{}) Const
- func (m *Module) String() string
- func (m *Module) Verify() error
- func (m *Module) ZeroGlobal(name string, ty Type) Global
- type Pointer
- type Signature
- type Struct
- type SwitchCase
- type Type
- type TypeList
- type Types
- func (t *Types) Array(el Type, n int) *Array
- func (t *Types) DeclarePackedStruct(name string) *Struct
- func (t *Types) DeclareStruct(name string) *Struct
- func (t *Types) PackedStruct(name string, fields ...Field) *Struct
- func (t *Types) Pointer(el Type) Pointer
- func (t *Types) Struct(name string, fields ...Field) *Struct
- func (t *Types) TypeOf(v interface{}) Type
- func (t *Types) Vector(el Type, count int) Vector
- type Value
- func (v *Value) Bitcast(ty Type) *Value
- func (v *Value) Cast(ty Type) *Value
- func (v *Value) Extract(at IndexOrName) *Value
- func (v *Value) Index(path ...ValueIndexOrName) *Value
- func (v *Value) Insert(at ValueIndexOrName, val *Value) *Value
- func (v *Value) IsNull() *Value
- func (v *Value) Load() *Value
- func (v *Value) LoadUnaligned() *Value
- func (v *Value) Name() string
- func (v *Value) SetName(name string) *Value
- func (v *Value) SetNameIfUnset(name string) *Value
- func (v *Value) Store(val *Value)
- func (v *Value) StoreUnaligned(val *Value)
- func (v *Value) Type() Type
- type ValueIndexOrName
- type Vector
Constants ¶
This section is empty.
Variables ¶
var Variadic variadicTy
Variadic is a type that can be used as the last parameter of a function definition to indicate a variadic function.
Functions ¶
func IsSignedInteger ¶
IsSignedInteger returns true if ty is a signed integer type.
func IsUnsignedInteger ¶
IsUnsignedInteger returns true if ty is an unsigned integer type.
Types ¶
type Array ¶
type Array struct { Element Type // The type of the element the pointer points to. Size int // Number of elements in the array. // contains filtered or unexported fields }
Array represents a static array type.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is provided to the callback of Build() for building a function's body.
func (*Builder) And ¶
And performs a bitwise-and of the two integers. The types of the two values must be equal.
func (*Builder) ForN ¶
ForN builds a logic block with the following psuedocode:
for it := 0; it < n; it++ { cont := cb() if cont == false { break; } }
If cb returns nil then the loop will never exit early.
func (*Builder) GlobalString ¶
GlobalString returns a pointer to a global variable holidng the string data.
func (*Builder) GreaterOrEqualTo ¶
GreaterOrEqualTo returns x >= y. The types of the two values must be equal.
func (*Builder) GreaterThan ¶
GreaterThan returns x > y. The types of the two values must be equal.
func (*Builder) IsBlockTerminated ¶
IsBlockTerminated returns true if the last instruction is a terminator (unconditional jump). It is illegal to write another instruction after a terminator.
func (*Builder) LessOrEqualTo ¶
LessOrEqualTo returns x <= y. The types of the two values must be equal.
func (*Builder) Local ¶
Local returns a pointer to a new local variable with the specified name and type.
func (*Builder) LocalInit ¶
LocalInit returns a new local variable with the specified name and initial value.
func (*Builder) Memcpy ¶
Memcpy performs an intrinsic memory copy of size bytes from src to dst. dst and src must be a void pointer (alias of u8*). size is the copy size in bytes. size must be of type uint32. align is the minimum pointer alignment of dst and src. align must of type uint32, or nil to represent no guaranteed alignment.
func (*Builder) Or ¶
Or performs a bitwise-or of the two integers. The types of the two values must be equal.
func (*Builder) ShiftRight ¶
ShiftRight performs a bit-shift right by shift bits.
func (*Builder) Shuffle ¶
Shuffle performs a vector-shuffle operation of the two vector values x and y with the specified indices.
func (*Builder) SizeOf ¶
SizeOf returns the size of the type in bytes as a uint64. If ty is void, a value of 1 is returned.
func (*Builder) Switch ¶
func (b *Builder) Switch(cases []SwitchCase, defaultCase func())
Switch builds a switch statement.
func (*Builder) VectorN ¶
VectorN returns a constant vector of n elements with the same value v in each element.
func (*Builder) While ¶
While builds a logic block with the following psuedocode:
while test() { loop() }
type Const ¶
type Const struct { Type Type // contains filtered or unexported fields }
Const is an immutable value.
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor executes module functions.
func (*Executor) AlignOf ¶
AlignOf returns the preferred stack/global alignment for the specified type.
func (*Executor) FieldOffsets ¶
func (*Executor) SizeOf ¶
SizeOf returns the offset in bytes between successive objects of the specified type, including alignment padding.
func (*Executor) StructLayout ¶
type Float ¶
type Float struct {
// contains filtered or unexported fields
}
Float represents a floating-point type.
type Function ¶
type Function struct { Name string Type FunctionType // contains filtered or unexported fields }
Function represents a callable function.
func (Function) LinkOnceODR ¶
LinkOnceODR sets this function's linkage to "linkonce_odr". This lets the function be merged with other global symbols with the same name, with the assumption their implementation is identical. Unlike "linkonce" this also preserves inlining.
func (Function) LinkPrivate ¶
LinkPrivate makes this function use private linkage.
type FunctionType ¶
type FunctionType struct { Signature Signature // contains filtered or unexported fields }
FunctionType is the type of a function
func (FunctionType) String ¶
func (t FunctionType) String() string
func (FunctionType) TypeName ¶
func (t FunctionType) TypeName() string
type Global ¶
type Global struct { Type Type // contains filtered or unexported fields }
Global is a global value.
func (Global) LinkPrivate ¶
LinkPrivate makes this global use private linkage.
type IndexOrName ¶
type IndexOrName interface{}
IndexOrName can be an index (int) or field name (string).
type Integer ¶
type Integer struct { Signed bool // Is this integer type signed? // contains filtered or unexported fields }
Integer represents an integer type.
type Module ¶
type Module struct { Types Types // contains filtered or unexported fields }
Module is a JIT module.
func (*Module) ConstStruct ¶
ConstStruct returns a constant struct with the value v.
func (*Module) Extern ¶
Extern returns a global variable declared externally with the given name and type.
func (*Module) Function ¶
Function creates a new function with the given name, result type and parameters.
func (*Module) Global ¶
Global returns a new global variable intiailized with the specified constant value.
func (*Module) ParseFunctionSignature ¶
ParseFunctionSignature returns a function parsed from a C-style signature. Example:
"void* Foo(uint8_t i, bool b)"
type Pointer ¶
type Pointer struct { Element Type // The type of the element the pointer points to. // contains filtered or unexported fields }
Pointer represents a pointer type.
type Struct ¶
Struct is the type of a structure.
type SwitchCase ¶
type SwitchCase struct { Conditions func() []*Value Block func() }
type Type ¶
type Type interface { String() string TypeName() string // contains filtered or unexported methods }
Type represents a JIT type.
type Types ¶
type Types struct { Void Type // Void is the void type. Bool Type // Bool is a one-bit integer type. Int Type // Int is a signed 32-bit or 64-bit integer type. Int8 Type // Int8 is a signed 8-bit integer type. Int16 Type // Int16 is a signed 16-bit integer type. Int32 Type // Int32 is a signed 32-bit integer type. Int64 Type // Int64 is a signed 64-bit integer type. Uint Type // Uint is an unsigned 32-bit or 64-bit integer type. Uint8 Type // Uint8 is an unsigned 8-bit integer type. Uint16 Type // Uint16 is an unigned 16-bit integer type. Uint32 Type // Uint32 is an unsigned 32-bit integer type. Uint64 Type // Uint64 is an unsigned 64-bit integer type. Uintptr Type // Uinptr is an unsigned integer type of the same width as a pointer. Size Type // Size is an unsigned integer of native bit-width. Float32 Type // Float32 is a 32-bit floating-point number type. Float64 Type // Float64 is a 64-bit floating-point number type. // contains filtered or unexported fields }
Types contains all the types for a module.
func (*Types) DeclarePackedStruct ¶
DeclarePackedStruct creates a new, packed empty struct type.
func (*Types) DeclareStruct ¶
DeclareStruct creates a new, empty struct type.
func (*Types) PackedStruct ¶
PackedStruct creates a new packed struct type.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents a value.
func (*Value) Extract ¶
func (v *Value) Extract(at IndexOrName) *Value
Extract returns the field at extracted from the struct or array v.
func (*Value) Index ¶
func (v *Value) Index(path ...ValueIndexOrName) *Value
Index returns a new pointer to the array or field element found by following the list of indices as specified by path.
func (*Value) Insert ¶
func (v *Value) Insert(at ValueIndexOrName, val *Value) *Value
Insert creates a copy of the struct or array v with the field/element at changed to val.
func (*Value) LoadUnaligned ¶
LoadUnaligned loads the element from the pointer value, it allows the loaded value to be unaligned
func (*Value) SetNameIfUnset ¶
SetNameIfUnset assigns a name to the value if it isn't already set.
func (*Value) StoreUnaligned ¶
StoreUnaligned stores val to the pointer ptr. It assumes that the destination address may be unaligned
type ValueIndexOrName ¶
type ValueIndexOrName interface{}
ValueIndexOrName can be an index (Value or int) or field name (string).