codegen

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: Apache-2.0 Imports: 13 Imported by: 13

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

Constants

This section is empty.

Variables

View Source
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 DataLayout added in v1.2.0

func DataLayout(abi *device.ABI) string

DataLayout returns an LLVM data layout string for the given ABI, or an empty string if there is no known data layout for the given ABI. Reference: https://llvm.org/docs/LangRef.html#langref-datalayout

func IsBool

func IsBool(ty Type) bool

IsBool returns true if ty is the boolean type.

func IsEnum added in v1.2.0

func IsEnum(ty Type) bool

IsEnum returns true if ty is an enum type.

func IsFloat

func IsFloat(ty Type) bool

IsFloat returns true if ty is a float type.

func IsFunction added in v1.2.0

func IsFunction(ty Type) bool

IsFunction returns true if ty is a function type.

func IsInteger

func IsInteger(ty Type) bool

IsInteger returns true if ty is an integer type.

func IsIntegerOrEnum added in v1.2.0

func IsIntegerOrEnum(ty Type) bool

IsIntegerOrEnum returns true if ty is an integer or enum type.

func IsPointer

func IsPointer(ty Type) bool

IsPointer returns true if ty is a pointer type.

func IsSignedInteger

func IsSignedInteger(ty Type) bool

IsSignedInteger returns true if ty is a signed integer type.

func IsSignedIntegerOrEnum added in v1.2.0

func IsSignedIntegerOrEnum(ty Type) bool

IsSignedIntegerOrEnum returns true if ty is a signed integer or enum type.

func IsStruct

func IsStruct(ty Type) bool

IsStruct returns true if ty is a struct type.

func IsUnsignedInteger

func IsUnsignedInteger(ty Type) bool

IsUnsignedInteger returns true if ty is an unsigned integer type.

func IsVector

func IsVector(ty Type) bool

IsVector returns true if ty is a vector type.

func StrideInBits added in v1.2.0

func StrideInBits(ty Type) int

StrideInBits returns the number of bits per element when held in an array.

Types

type Alias added in v1.2.0

type Alias struct {
	// contains filtered or unexported fields
}

Alias is a named type that aliases another type.

func (Alias) AlignInBits added in v1.2.0

func (a Alias) AlignInBits() int

func (Alias) SizeInBits added in v1.2.0

func (a Alias) SizeInBits() int

func (Alias) String added in v1.2.0

func (a Alias) String() string

func (Alias) TypeName added in v1.2.0

func (a Alias) TypeName() string

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.

func (Array) AlignInBits added in v1.2.0

func (t Array) AlignInBits() int

func (Array) SizeInBits added in v1.2.0

func (t Array) SizeInBits() int

func (Array) String

func (t Array) String() string

func (Array) TypeName

func (t Array) TypeName() string

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

func (b *Builder) Add(x, y *Value) *Value

Add returns x + y. The types of the two values must be equal.

func (*Builder) AddS

func (b *Builder) AddS(x *Value, y interface{}) *Value

AddS returns x + y. The types of the two values must be equal.

func (*Builder) AlignOf

func (b *Builder) AlignOf(ty Type) *Value

AlignOf returns the alignment of the type in bytes.

func (*Builder) And

func (b *Builder) And(x, y *Value) *Value

And performs a bitwise-and of the two integers. The types of the two values must be equal.

func (*Builder) Call

func (b *Builder) Call(f *Function, args ...*Value) *Value

Call invokes the function f with the specified arguments

func (*Builder) CallIndirect added in v1.2.0

func (b *Builder) CallIndirect(f *Value, args ...*Value) *Value

CallIndirect invokes the function pointer f with the specified arguments

func (*Builder) Div

func (b *Builder) Div(x, y *Value) *Value

Div returns x / y. The types of the two values must be equal.

func (*Builder) DivS

func (b *Builder) DivS(x *Value, y interface{}) *Value

DivS returns x / y. The types of the two values must be equal.

func (*Builder) Equal

func (b *Builder) Equal(x, y *Value) *Value

Equal returns x == y. The types of the two values must be equal.

func (*Builder) ForN

func (b *Builder) ForN(n *Value, cb func(iterator *Value) (cont *Value))

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) FuncAddr added in v1.2.0

func (b *Builder) FuncAddr(f *Function) *Value

FuncAddr returns the pointer to the given function.

func (*Builder) GreaterOrEqualTo

func (b *Builder) GreaterOrEqualTo(x, y *Value) *Value

GreaterOrEqualTo returns x >= y. The types of the two values must be equal.

func (*Builder) GreaterThan

func (b *Builder) GreaterThan(x, y *Value) *Value

GreaterThan returns x > y. The types of the two values must be equal.

func (*Builder) If

func (b *Builder) If(cond *Value, onTrue func())

If builds an if statement.

func (*Builder) IfElse

func (b *Builder) IfElse(cond *Value, onTrue, onFalse func())

IfElse builds an if-else statement.

func (*Builder) Invert

func (b *Builder) Invert(x *Value) *Value

Invert returns ~x.

func (*Builder) Invoke added in v1.2.0

func (b *Builder) Invoke(f *Function, cleanup func(), args ...*Value) *Value

Invoke invokes the function f with the specified arguments. If an exception is thrown while calling f, then cleanup will be called before rethrowing the exception.

func (*Builder) IsBlockTerminated

func (b *Builder) IsBlockTerminated() bool

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

func (b *Builder) LessOrEqualTo(x, y *Value) *Value

LessOrEqualTo returns x <= y. The types of the two values must be equal.

func (*Builder) LessThan

func (b *Builder) LessThan(x, y *Value) *Value

LessThan returns x < y. The types of the two values must be equal.

func (*Builder) Local

func (b *Builder) Local(name string, ty Type) *Value

Local returns a pointer to a new local variable with the specified name and type.

func (*Builder) LocalInit

func (b *Builder) LocalInit(name string, val *Value) *Value

LocalInit returns a new local variable with the specified name and initial value.

func (*Builder) Memcpy

func (b *Builder) Memcpy(dst, src, size *Value)

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.

func (*Builder) Memset added in v1.2.0

func (b *Builder) Memset(dst, val, size *Value)

Memset performs an intrinsic memory set to the given value. dst must be a void pointer (alias of u8*). val is value that is to be repeated size times into dst. val must be of type uint8. size is the copy size in bytes. size must be of type uint32.

func (*Builder) Memzero added in v1.2.0

func (b *Builder) Memzero(dst, size *Value)

Memzero performs an intrinsic memory clear to 0. dst must be a void pointer (alias of u8*). size is the copy size in bytes. size must be of type uint32.

func (*Builder) Mul

func (b *Builder) Mul(x, y *Value) *Value

Mul returns x * y. The types of the two values must be equal.

func (*Builder) MulS

func (b *Builder) MulS(x *Value, y interface{}) *Value

MulS returns x * y. The types of the two values must be equal.

func (*Builder) Negate

func (b *Builder) Negate(x *Value) *Value

Negate returns -x. The type of x must be a signed integer or float.

func (*Builder) Not

func (b *Builder) Not(x *Value) *Value

Not returns !x. The type of x must be Bool.

func (*Builder) NotEqual

func (b *Builder) NotEqual(x, y *Value) *Value

NotEqual returns x != y. The types of the two values must be equal.

func (*Builder) One

func (b *Builder) One(ty Type) *Value

One returns a one-value of the specified bool, int or float type.

func (*Builder) Or

func (b *Builder) Or(x, y *Value) *Value

Or performs a bitwise-or of the two integers. The types of the two values must be equal.

func (*Builder) Parameter

func (b *Builder) Parameter(i int) *Value

Parameter returns i'th function parameter

func (*Builder) PrintfSpecifier added in v1.2.0

func (b *Builder) PrintfSpecifier(v *Value) (string, []*Value)

PrintfSpecifier returns the string and values that can be used to print v with printf.

func (*Builder) Rem

func (b *Builder) Rem(x, y *Value) *Value

Rem returns x % y. The types of the two values must be equal.

func (*Builder) Return

func (b *Builder) Return(val *Value)

Return returns execution of the function with the given value

func (*Builder) Scalar

func (b *Builder) Scalar(v interface{}) *Value

Scalar returns a constant scalar with the value v.

func (*Builder) Select

func (b *Builder) Select(cond, x, y *Value) *Value

Select returns (cond ? x : y). x and y must be of the same type.

func (*Builder) SetLocation added in v1.2.0

func (b *Builder) SetLocation(line, column int)

SetLocation sets the source location of the next instructions to be built.

func (*Builder) ShiftLeft

func (b *Builder) ShiftLeft(x, y *Value) *Value

ShiftLeft performs a bit-shift left by shift bits.

func (*Builder) ShiftRight

func (b *Builder) ShiftRight(x, y *Value) *Value

ShiftRight performs a bit-shift right by shift bits.

func (*Builder) Shuffle

func (b *Builder) Shuffle(x, y, indices *Value) *Value

Shuffle performs a vector-shuffle operation of the two vector values x and y with the specified indices.

func (*Builder) SizeOf

func (b *Builder) SizeOf(ty Type) *Value

SizeOf returns the size of the type in bytes as a uint64. If ty is void, a value of 1 is returned.

func (*Builder) StructOf added in v1.2.0

func (b *Builder) StructOf(name string, v []*Value) *Value

StructOf builds a struct value that holds all the values in v.

func (*Builder) Sub

func (b *Builder) Sub(x, y *Value) *Value

Sub returns x - y. The types of the two values must be equal.

func (*Builder) SubS

func (b *Builder) SubS(x *Value, y interface{}) *Value

SubS returns x - y. The types of the two values must be equal.

func (*Builder) Switch

func (b *Builder) Switch(cases []SwitchCase, defaultCase func())

Switch builds a switch statement.

func (*Builder) Throw added in v1.2.0

func (b *Builder) Throw(v *Value)

Throw throws an exception with the given value.

func (*Builder) Undef

func (b *Builder) Undef(ty Type) *Value

Undef returns a new undefined value of the specified type.

func (*Builder) Vector

func (b *Builder) Vector(el0 interface{}, els ...interface{}) *Value

Vector returns a constant vector with the specified values.

func (*Builder) VectorN

func (b *Builder) VectorN(n int, v interface{}) *Value

VectorN returns a constant vector of n elements with the same value v in each element.

func (*Builder) While

func (b *Builder) While(test func() *Value, loop func())

While builds a logic block with the following psuedocode:

while test() {
  loop()
}

func (*Builder) Xor

func (b *Builder) Xor(x, y *Value) *Value

Xor performs a bitwise-xor of the two integers. The types of the two values must be equal.

func (*Builder) Zero

func (b *Builder) Zero(ty Type) *Value

Zero returns a zero-value of the specified type.

type Const

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

Const is an immutable value.

func (Const) Cast

func (v Const) Cast(ty Type) Const

Cast casts the constant v to the type ty.

func (Const) Value

func (c Const) Value(b *Builder) *Value

Value returns a Value for the constant.

type Enum added in v1.2.0

type Enum struct {
	// contains filtered or unexported fields
}

Enum is an enumerator.

func (Enum) AlignInBits added in v1.2.0

func (t Enum) AlignInBits() int

func (Enum) SizeInBits added in v1.2.0

func (t Enum) SizeInBits() int

func (Enum) String added in v1.2.0

func (t Enum) String() string

func (Enum) TypeName added in v1.2.0

func (t Enum) TypeName() string

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor executes module functions.

func (*Executor) AlignOf

func (e *Executor) AlignOf(t Type) int

AlignOf returns the preferred stack/global alignment for the specified type.

func (*Executor) FieldOffsets

func (e *Executor) FieldOffsets(s *Struct) []int

func (*Executor) FunctionAddress

func (e *Executor) FunctionAddress(f *Function) unsafe.Pointer

FunctionAddress returns the address of the function f.

func (*Executor) GlobalAddress added in v1.2.0

func (e *Executor) GlobalAddress(g Global) unsafe.Pointer

GlobalAddress returns the address of the global g.

func (*Executor) SizeOf

func (e *Executor) SizeOf(t Type) int

SizeOf returns the offset in bytes between successive objects of the specified type, including alignment padding.

func (*Executor) StructLayout

func (e *Executor) StructLayout(s *Struct) string

type Field

type Field struct {
	Name string
	Type Type
}

Field is a single field in a struct.

type Float

type Float struct {
	// contains filtered or unexported fields
}

Float represents a floating-point type.

func (Float) AlignInBits added in v1.2.0

func (t Float) AlignInBits() int

func (Float) SizeInBits added in v1.2.0

func (t Float) SizeInBits() int

func (Float) String

func (t Float) String() string

func (Float) TypeName

func (t Float) TypeName() string

type Function

type Function struct {
	Name string
	Type *FunctionType
	// contains filtered or unexported fields
}

Function represents a callable function.

func (*Function) Build

func (f *Function) Build(cb func(*Builder)) (err error)

Build calls cb with a Builder that can construct the function body.

func (*Function) Inline

func (f *Function) Inline() *Function

Inline makes this function prefer inlining

func (*Function) LinkInternal added in v1.2.0

func (f *Function) LinkInternal() *Function

LinkInternal makes this function use internal linkage.

func (*Function) LinkOnceODR

func (f *Function) LinkOnceODR() *Function

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

func (f *Function) LinkPrivate() *Function

LinkPrivate makes this function use private linkage.

func (*Function) SetLocation added in v1.2.0

func (f *Function) SetLocation(path string, line int) *Function

SetLocation sets the source location of the given function. SetLocation returns f so it can be called fluently.

func (*Function) SetParameterNames added in v1.2.0

func (f *Function) SetParameterNames(names ...string) *Function

SetParameterNames assigns debug names to each of the function parameters.

func (Function) String

func (f Function) String() string

type FunctionType

type FunctionType struct {
	Signature Signature
	// contains filtered or unexported fields
}

FunctionType is the type of a function

func (FunctionType) AlignInBits added in v1.2.0

func (t FunctionType) AlignInBits() int

func (FunctionType) SizeInBits added in v1.2.0

func (t FunctionType) SizeInBits() int

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) Cast added in v1.2.0

func (v Global) Cast(ty Type) Global

Cast casts the global value to the given type.

func (Global) LinkPrivate

func (g Global) LinkPrivate() Global

LinkPrivate makes this global use private linkage.

func (Global) LinkPublic added in v1.2.0

func (g Global) LinkPublic() Global

LinkPublic makes this global use public linkage.

func (Global) SetConstant added in v1.2.0

func (g Global) SetConstant(constant bool) Global

SetConstant makes this global constant.

func (Global) Value

func (g Global) Value(b *Builder) *Value

Value returns a Value for the global.

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.

func (Integer) AlignInBits added in v1.2.0

func (t Integer) AlignInBits() int

func (Integer) SizeInBits added in v1.2.0

func (t Integer) SizeInBits() int

func (Integer) String

func (t Integer) String() string

func (Integer) TypeName

func (t Integer) TypeName() string

type Module

type Module struct {
	Types Types
	// contains filtered or unexported fields
}

Module is a JIT module.

func NewModule

func NewModule(name string, target *device.ABI) *Module

NewModule returns a new module with the specified name.

func (*Module) AlignOf added in v1.2.0

func (m *Module) AlignOf(ty Type) Const

AlignOf returns the alignment of the type in bytes.

func (*Module) Array added in v1.2.0

func (m *Module) Array(v interface{}, elTy Type) Const

Array returns an constant array with the value v and element type ty.

func (*Module) ConstStruct

func (m *Module) ConstStruct(ty *Struct, fields map[string]interface{}) Const

ConstStruct returns a constant struct with the value v.

func (*Module) Ctor added in v1.2.0

func (m *Module) Ctor(priority int32, cb func(*Builder))

Ctor creates and builds a new module constructor.

func (*Module) EmitDebug added in v1.2.0

func (m *Module) EmitDebug()

EmitDebug enables debug info generation for the module.

func (*Module) Executor

func (m *Module) Executor(optimize bool) (*Executor, error)

Executor constructs an executor.

func (*Module) Extern

func (m *Module) Extern(name string, ty Type) Global

Extern returns a global variable declared externally with the given name and type.

func (*Module) Function

func (m *Module) Function(resTy Type, name string, paramTys ...Type) *Function

Function creates a new function with the given name, result type and parameters.

func (*Module) Global

func (m *Module) Global(name string, val Const) Global

Global returns a new global variable intiailized with the specified constant value.

func (*Module) Object

func (m *Module) Object(optimize bool) ([]byte, error)

Object compiles the module down to an object file.

func (*Module) OffsetOf added in v1.2.0

func (m *Module) OffsetOf(ty *Struct, name string) Const

OffsetOf returns the field offset in bytes.

func (*Module) Optimize

func (m *Module) Optimize()

Optimize optimizes the module.

func (*Module) ParseFunctionSignature

func (m *Module) ParseFunctionSignature(sig string) *Function

ParseFunctionSignature returns a function parsed from a C-style signature. Example:

"void* Foo(uint8_t i, bool b)"

func (*Module) Scalar

func (m *Module) Scalar(v interface{}) Const

Scalar returns an inferred type constant scalar with the value v.

func (*Module) ScalarOfType added in v1.2.0

func (m *Module) ScalarOfType(v interface{}, ty Type) Const

ScalarOfType returns a constant scalar with the value v with the given type.

func (*Module) SizeOf added in v1.2.0

func (m *Module) SizeOf(ty Type) Const

SizeOf returns the size of the type in bytes as a uint64.

func (*Module) String

func (m *Module) String() string

func (*Module) Verify

func (m *Module) Verify() error

Verify checks correctness of the module.

func (*Module) Zero added in v1.2.0

func (m *Module) Zero(ty Type) Const

Zero returns a constant zero value of type ty.

func (*Module) ZeroGlobal

func (m *Module) ZeroGlobal(name string, ty Type) Global

ZeroGlobal returns a zero-initialized new global variable with the specified name and type.

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.

func (Pointer) AlignInBits added in v1.2.0

func (t Pointer) AlignInBits() int

func (Pointer) SizeInBits added in v1.2.0

func (t Pointer) SizeInBits() int

func (Pointer) String

func (t Pointer) String() string

func (Pointer) TypeName

func (t Pointer) TypeName() string

type Signature

type Signature struct {
	Parameters TypeList
	Result     Type
	Variadic   bool
}

Signature holds signature information about a function.

type Struct

type Struct struct {
	// contains filtered or unexported fields
}

Struct is the type of a structure.

func (*Struct) AlignInBits added in v1.2.0

func (t *Struct) AlignInBits() int

func (*Struct) Field

func (t *Struct) Field(name string) Field

Field returns the field with the given name. Field panics if the struct does not contain the given field.

func (*Struct) FieldIndex added in v1.2.0

func (t *Struct) FieldIndex(name string) int

FieldIndex returns the index of the field with the given name, or -1 if the struct does not have a field with the given name.

func (*Struct) FieldOffsetInBits added in v1.2.0

func (t *Struct) FieldOffsetInBits(idx int) int

FieldOffsetInBits returns the field offset in bits from the start of the struct.

func (*Struct) Fields

func (t *Struct) Fields() []Field

func (*Struct) SetBody

func (t *Struct) SetBody(packed bool, fields ...Field) *Struct

SetBody sets the fields of the declared struct.

func (*Struct) SizeInBits added in v1.2.0

func (t *Struct) SizeInBits() int

func (*Struct) String

func (t *Struct) String() string

func (*Struct) TypeName

func (t *Struct) TypeName() string

type SwitchCase

type SwitchCase struct {
	Conditions func() []*Value
	Block      func()
}

SwitchCase is a single condition and block used as a case statement in a switch.

type Triple added in v1.2.0

type Triple struct {
	// contains filtered or unexported fields
}

Triple represents an LLVM target triple.

func NewTriple added in v1.2.0

func NewTriple(arch, vendor, os, abi string) Triple

NewTriple returns a new Triple.

func TargetTriple added in v1.2.0

func TargetTriple(dev *device.ABI) Triple

TargetTriple returns an LLVM target triple for the given ABI in the form:

<arch><sub>-<vendor>-<os>-<abi>

References: https://github.com/llvm-mirror/llvm/blob/master/lib/Support/Triple.cpp https://clang.llvm.org/docs/CrossCompilation.html

func (Triple) String added in v1.2.0

func (t Triple) String() string

type Type

type Type interface {
	String() string
	TypeName() string

	SizeInBits() int
	AlignInBits() int
	// contains filtered or unexported methods
}

Type represents a codegen type.

func Scalar

func Scalar(ty Type) Type

Scalar returns the element type if ty is a vector, otherwise it returns ty.

func Underlying added in v1.2.0

func Underlying(ty Type) Type

Underlying returns the underlying non-aliased type for ty.

type TypeList

type TypeList []Type

TypeList is a slice of types.

func (TypeList) String

func (l TypeList) String() string

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) Alias added in v1.2.0

func (t *Types) Alias(name string, to Type) Alias

Alias creates a new alias type.

func (*Types) Array

func (t *Types) Array(el Type, n int) *Array

Array returns an n-element array type of el.

func (*Types) DeclarePackedStruct

func (t *Types) DeclarePackedStruct(name string) *Struct

DeclarePackedStruct creates a new, packed empty struct type.

func (*Types) DeclareStruct

func (t *Types) DeclareStruct(name string) *Struct

DeclareStruct creates a new, empty struct type.

func (*Types) Enum added in v1.2.0

func (t *Types) Enum(name string) Enum

Enum creates a new enum type.

func (*Types) FieldsOf added in v1.2.0

func (t *Types) FieldsOf(v interface{}) []Field

FieldsOf returns the codegen fields of the given struct type. FieldsOf may also accept a reflect.Type.

func (*Types) Function added in v1.2.0

func (t *Types) Function(resTy Type, paramTys ...Type) *FunctionType

Function returns a type representing the given function signature.

func (*Types) PackedStruct

func (t *Types) PackedStruct(name string, fields ...Field) *Struct

PackedStruct creates a new packed struct type.

func (*Types) Pointer

func (t *Types) Pointer(el Type) Pointer

Pointer returns a pointer type of el.

func (*Types) Struct

func (t *Types) Struct(name string, fields ...Field) *Struct

Struct creates a new unpacked struct type.

func (*Types) TypeOf

func (t *Types) TypeOf(v interface{}) Type

TypeOf returns the corresponding codegen type for the type of value v. TypeOf may also accept a reflect.Type, Type, *Function or Const.

func (*Types) Vector

func (t *Types) Vector(el Type, count int) Vector

Vector returns a pointer type of el.

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value represents a value.

func (*Value) Bitcast

func (v *Value) Bitcast(ty Type) *Value

Bitcast performs a bitwise cast of the value v to the type ty.

func (*Value) Cast

func (v *Value) Cast(ty Type) *Value

Cast casts the value v to the type ty.

func (*Value) EmitDebug added in v1.2.0

func (v *Value) EmitDebug(name string) *Value

EmitDebug emits debug info for the 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) IsNull

func (v *Value) IsNull() *Value

IsNull returns true if the pointer value v is null.

func (*Value) Load

func (v *Value) Load() *Value

Load loads the element from the pointer value.

func (*Value) LoadUnaligned

func (v *Value) LoadUnaligned() *Value

LoadUnaligned loads the element from the pointer value, it allows the loaded value to be unaligned

func (*Value) Name

func (v *Value) Name() string

Name returns the value's name.

func (*Value) SetName

func (v *Value) SetName(name string) *Value

SetName assigns a name to the value.

func (*Value) Store

func (v *Value) Store(val *Value)

Store stores val to the pointer ptr.

func (*Value) StoreUnaligned

func (v *Value) StoreUnaligned(val *Value)

StoreUnaligned stores val to the pointer ptr. It assumes that the destination address may be unaligned

func (*Value) Type

func (v *Value) Type() Type

Type returns the type of the value.

type ValueIndexOrName

type ValueIndexOrName interface{}

ValueIndexOrName can be an index (Value or int) or field name (string).

type Vector

type Vector struct {
	Element Type // The type of the vector elements.
	Count   int  // Number of elements in a vector.
	// contains filtered or unexported fields
}

Vector represents a vector type.

func (Vector) AlignInBits added in v1.2.0

func (t Vector) AlignInBits() int

func (Vector) SizeInBits added in v1.2.0

func (t Vector) SizeInBits() int

func (Vector) String

func (t Vector) String() string

func (Vector) TypeName

func (t Vector) TypeName() string

Directories

Path Synopsis
Package call provides methods for invoking C function pointers.
Package call provides methods for invoking C function pointers.

Jump to

Keyboard shortcuts

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