types

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: 0BSD, Unlicense Imports: 4 Imported by: 100

Documentation

Overview

Package types declares the data types of LLVM IR.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Basic types.
	Void     = &VoidType{}     // void
	MMX      = &MMXType{}      // x86_mmx
	Label    = &LabelType{}    // label
	Token    = &TokenType{}    // token
	Metadata = &MetadataType{} // metadata
	// Integer types.
	I1    = &IntType{BitSize: 1}    // i1
	I2    = &IntType{BitSize: 2}    // i2
	I3    = &IntType{BitSize: 3}    // i3
	I4    = &IntType{BitSize: 4}    // i4
	I5    = &IntType{BitSize: 5}    // i5
	I6    = &IntType{BitSize: 6}    // i6
	I7    = &IntType{BitSize: 7}    // i7
	I8    = &IntType{BitSize: 8}    // i8
	I16   = &IntType{BitSize: 16}   // i16
	I32   = &IntType{BitSize: 32}   // i32
	I64   = &IntType{BitSize: 64}   // i64
	I128  = &IntType{BitSize: 128}  // i128
	I256  = &IntType{BitSize: 256}  // i256
	I512  = &IntType{BitSize: 512}  // i512
	I1024 = &IntType{BitSize: 1024} // i1024
	// Floating-point types.
	Half      = &FloatType{Kind: FloatKindHalf}      // half
	Float     = &FloatType{Kind: FloatKindFloat}     // float
	Double    = &FloatType{Kind: FloatKindDouble}    // double
	X86_FP80  = &FloatType{Kind: FloatKindX86_FP80}  // x86_fp80
	FP128     = &FloatType{Kind: FloatKindFP128}     // fp128
	PPC_FP128 = &FloatType{Kind: FloatKindPPC_FP128} // ppc_fp128
	// Integer pointer types.
	I1Ptr   = &PointerType{ElemType: I1}   // i1*
	I8Ptr   = &PointerType{ElemType: I8}   // i8*
	I16Ptr  = &PointerType{ElemType: I16}  // i16*
	I32Ptr  = &PointerType{ElemType: I32}  // i32*
	I64Ptr  = &PointerType{ElemType: I64}  // i64*
	I128Ptr = &PointerType{ElemType: I128} // i128*
)

Convenience types.

Functions

func Equal

func Equal(t, u Type) bool

Equal reports whether t and u are of equal type.

func IsArray

func IsArray(t Type) bool

IsArray reports whether the given type is an array type.

func IsFloat

func IsFloat(t Type) bool

IsFloat reports whether the given type is a floating-point type.

func IsFunc

func IsFunc(t Type) bool

IsFunc reports whether the given type is a function type.

func IsInt

func IsInt(t Type) bool

IsInt reports whether the given type is an integer type.

func IsLabel

func IsLabel(t Type) bool

IsLabel reports whether the given type is a label type.

func IsMMX

func IsMMX(t Type) bool

IsMMX reports whether the given type is an MMX type.

func IsMetadata

func IsMetadata(t Type) bool

IsMetadata reports whether the given type is a metadata type.

func IsPointer

func IsPointer(t Type) bool

IsPointer reports whether the given type is a pointer type.

func IsStruct

func IsStruct(t Type) bool

IsStruct reports whether the given type is a struct type.

func IsToken

func IsToken(t Type) bool

IsToken reports whether the given type is a token type.

func IsVector

func IsVector(t Type) bool

IsVector reports whether the given type is a vector type.

func IsVoid

func IsVoid(t Type) bool

IsVoid reports whether the given type is a void type.

Types

type AddrSpace

type AddrSpace uint64

AddrSpace is an LLVM IR pointer type address space.

func (AddrSpace) String

func (a AddrSpace) String() string

String returns the string representation of the pointer type address space.

type ArrayType

type ArrayType struct {
	// Type name; or empty if not present.
	TypeName string
	// Array length.
	Len uint64
	// Element type.
	ElemType Type
}

ArrayType is an LLVM IR array type.

func NewArray

func NewArray(len uint64, elemType Type) *ArrayType

NewArray returns a new array type based on the given array length and element type.

func (*ArrayType) Equal

func (t *ArrayType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*ArrayType) LLString

func (t *ArrayType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

'[' Len=UintLit 'x' Elem=Type ']'

func (*ArrayType) Name

func (t *ArrayType) Name() string

Name returns the type name of the type.

func (*ArrayType) SetName

func (t *ArrayType) SetName(name string)

SetName sets the type name of the type.

func (*ArrayType) String

func (t *ArrayType) String() string

String returns the string representation of the array type.

type FloatKind

type FloatKind uint8

FloatKind represents the set of floating-point kinds.

const (
	// 16-bit floating-point type (IEEE 754 half precision).
	FloatKindHalf FloatKind = iota // half
	// 32-bit floating-point type (IEEE 754 single precision).
	FloatKindFloat // float
	// 64-bit floating-point type (IEEE 754 double precision).
	FloatKindDouble // double
	// 128-bit floating-point type (IEEE 754 quadruple precision).
	FloatKindFP128 // fp128
	// 80-bit floating-point type (x86 extended precision).
	FloatKindX86_FP80 // x86_fp80
	// 128-bit floating-point type (PowerPC double-double arithmetic).
	FloatKindPPC_FP128 // ppc_fp128
)

Floating-point kinds.

func (FloatKind) String

func (i FloatKind) String() string

type FloatType

type FloatType struct {
	// Type name; or empty if not present.
	TypeName string
	// Floating-point kind.
	Kind FloatKind
}

FloatType is an LLVM IR floating-point type.

func (*FloatType) Equal

func (t *FloatType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*FloatType) LLString

func (t *FloatType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

FloatKind

func (*FloatType) Name

func (t *FloatType) Name() string

Name returns the type name of the type.

func (*FloatType) SetName

func (t *FloatType) SetName(name string)

SetName sets the type name of the type.

func (*FloatType) String

func (t *FloatType) String() string

String returns the string representation of the floating-point type.

type FuncType

type FuncType struct {
	// Type name; or empty if not present.
	TypeName string
	// Return type.
	RetType Type
	// Function parameters.
	Params []Type
	// Variable number of function arguments.
	Variadic bool
}

FuncType is an LLVM IR function type.

func NewFunc

func NewFunc(retType Type, params ...Type) *FuncType

NewFunc returns a new function type based on the given return type and function parameter types.

func (*FuncType) Equal

func (t *FuncType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*FuncType) LLString

func (t *FuncType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

RetType=Type '(' Params ')'

func (*FuncType) Name

func (t *FuncType) Name() string

Name returns the type name of the type.

func (*FuncType) SetName

func (t *FuncType) SetName(name string)

SetName sets the type name of the type.

func (*FuncType) String

func (t *FuncType) String() string

String returns the string representation of the function type.

type IntType

type IntType struct {
	// Type name; or empty if not present.
	TypeName string
	// Integer size in number of bits.
	BitSize uint64
}

IntType is an LLVM IR integer type.

func NewInt

func NewInt(bitSize uint64) *IntType

NewInt returns a new integer type based on the given integer bit size.

func (*IntType) Equal

func (t *IntType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*IntType) LLString

func (t *IntType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

int_type_tok

func (*IntType) Name

func (t *IntType) Name() string

Name returns the type name of the type.

func (*IntType) SetName

func (t *IntType) SetName(name string)

SetName sets the type name of the type.

func (*IntType) String

func (t *IntType) String() string

String returns the string representation of the integer type.

type LabelType

type LabelType struct {
	// Type name; or empty if not present.
	TypeName string
}

LabelType is an LLVM IR label type, which is used for basic block values.

func (*LabelType) Equal

func (t *LabelType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*LabelType) LLString

func (t *LabelType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

'label'

func (*LabelType) Name

func (t *LabelType) Name() string

Name returns the type name of the type.

func (*LabelType) SetName

func (t *LabelType) SetName(name string)

SetName sets the type name of the type.

func (*LabelType) String

func (t *LabelType) String() string

String returns the string representation of the label type.

type MMXType

type MMXType struct {
	// Type name; or empty if not present.
	TypeName string
}

MMXType is an LLVM IR MMX type.

func (*MMXType) Equal

func (t *MMXType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*MMXType) LLString

func (t *MMXType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

'x86_mmx'

func (*MMXType) Name

func (t *MMXType) Name() string

Name returns the type name of the type.

func (*MMXType) SetName

func (t *MMXType) SetName(name string)

SetName sets the type name of the type.

func (*MMXType) String

func (t *MMXType) String() string

String returns the string representation of the MMX type.

type MetadataType

type MetadataType struct {
	// Type name; or empty if not present.
	TypeName string
}

MetadataType is an LLVM IR metadata type.

func (*MetadataType) Equal

func (t *MetadataType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*MetadataType) LLString

func (t *MetadataType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

'metadata'

func (*MetadataType) Name

func (t *MetadataType) Name() string

Name returns the type name of the type.

func (*MetadataType) SetName

func (t *MetadataType) SetName(name string)

SetName sets the type name of the type.

func (*MetadataType) String

func (t *MetadataType) String() string

String returns the string representation of the metadata type.

type PointerType

type PointerType struct {
	// Type name; or empty if not present.
	TypeName string
	// Element type.
	ElemType Type
	// Address space; or zero value for default address space.
	AddrSpace AddrSpace
}

PointerType is an LLVM IR pointer type.

func NewPointer

func NewPointer(elemType Type) *PointerType

NewPointer returns a new pointer type based on the given element type.

func (*PointerType) Equal

func (t *PointerType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*PointerType) LLString

func (t *PointerType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

Elem=Type AddrSpaceopt '*'

func (*PointerType) Name

func (t *PointerType) Name() string

Name returns the type name of the type.

func (*PointerType) SetName

func (t *PointerType) SetName(name string)

SetName sets the type name of the type.

func (*PointerType) String

func (t *PointerType) String() string

String returns the string representation of the pointer type.

type StructType

type StructType struct {
	// Type name; or empty if not present.
	TypeName string
	// Packed memory layout.
	Packed bool
	// Struct fields.
	Fields []Type
	// Opaque struct type.
	Opaque bool
}

StructType is an LLVM IR structure type. Identified (named) struct types are uniqued by type names, not by structural identity.

func NewStruct

func NewStruct(fields ...Type) *StructType

NewStruct returns a new struct type based on the given field types.

func (*StructType) Equal

func (t *StructType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*StructType) LLString

func (t *StructType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

Opaque struct type.

'opaque'

Struct type.

'{' Fields=(Type separator ',')+? '}'

Packed struct type.

'<' '{' Fields=(Type separator ',')+? '}' '>'   -> PackedStructType

func (*StructType) Name

func (t *StructType) Name() string

Name returns the type name of the type.

func (*StructType) SetName

func (t *StructType) SetName(name string)

SetName sets the type name of the type.

func (*StructType) String

func (t *StructType) String() string

String returns the string representation of the structure type.

type TokenType

type TokenType struct {
	// Type name; or empty if not present.
	TypeName string
}

TokenType is an LLVM IR token type.

func (*TokenType) Equal

func (t *TokenType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*TokenType) LLString

func (t *TokenType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

'token'

func (*TokenType) Name

func (t *TokenType) Name() string

Name returns the type name of the type.

func (*TokenType) SetName

func (t *TokenType) SetName(name string)

SetName sets the type name of the type.

func (*TokenType) String

func (t *TokenType) String() string

String returns the string representation of the token type.

type Type

type Type interface {
	fmt.Stringer
	// LLString returns the LLVM syntax representation of the definition of the
	// type.
	LLString() string
	// Equal reports whether t and u are of equal type.
	Equal(u Type) bool
	// Name returns the type name of the type.
	Name() string
	// SetName sets the type name of the type.
	SetName(name string)
}

Type is an LLVM IR type.

A Type has one of the following underlying types.

*types.VoidType       // https://pkg.go.dev/github.com/llir/llvm/ir/types#VoidType
*types.FuncType       // https://pkg.go.dev/github.com/llir/llvm/ir/types#FuncType
*types.IntType        // https://pkg.go.dev/github.com/llir/llvm/ir/types#IntType
*types.FloatType      // https://pkg.go.dev/github.com/llir/llvm/ir/types#FloatType
*types.MMXType        // https://pkg.go.dev/github.com/llir/llvm/ir/types#MMXType
*types.PointerType    // https://pkg.go.dev/github.com/llir/llvm/ir/types#PointerType
*types.VectorType     // https://pkg.go.dev/github.com/llir/llvm/ir/types#VectorType
*types.LabelType      // https://pkg.go.dev/github.com/llir/llvm/ir/types#LabelType
*types.TokenType      // https://pkg.go.dev/github.com/llir/llvm/ir/types#TokenType
*types.MetadataType   // https://pkg.go.dev/github.com/llir/llvm/ir/types#MetadataType
*types.ArrayType      // https://pkg.go.dev/github.com/llir/llvm/ir/types#ArrayType
*types.StructType     // https://pkg.go.dev/github.com/llir/llvm/ir/types#StructType

type VectorType

type VectorType struct {
	// Type name; or empty if not present.
	TypeName string
	// Scalable vector type.
	Scalable bool
	// Vector length.
	Len uint64
	// Element type.
	ElemType Type
}

VectorType is an LLVM IR vector type.

func NewVector

func NewVector(len uint64, elemType Type) *VectorType

NewVector returns a new vector type based on the given vector length and element type.

func (*VectorType) Equal

func (t *VectorType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*VectorType) LLString

func (t *VectorType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

scalable: '<' 'vscale' 'x' Len=UintLit 'x' Elem=Type '>' non-scalable: '<' Len=UintLit 'x' Elem=Type '>'

func (*VectorType) Name

func (t *VectorType) Name() string

Name returns the type name of the type.

func (*VectorType) SetName

func (t *VectorType) SetName(name string)

SetName sets the type name of the type.

func (*VectorType) String

func (t *VectorType) String() string

String returns the string representation of the vector type.

type VoidType

type VoidType struct {
	// Type name; or empty if not present.
	TypeName string
}

VoidType is an LLVM IR void type.

func (*VoidType) Equal

func (t *VoidType) Equal(u Type) bool

Equal reports whether t and u are of equal type.

func (*VoidType) LLString

func (t *VoidType) LLString() string

LLString returns the LLVM syntax representation of the definition of the type.

'void'

func (*VoidType) Name

func (t *VoidType) Name() string

Name returns the type name of the type.

func (*VoidType) SetName

func (t *VoidType) SetName(name string)

SetName sets the type name of the type.

func (*VoidType) String

func (t *VoidType) String() string

String returns the string representation of the void type.

Jump to

Keyboard shortcuts

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