Documentation ¶
Overview ¶
Package compiler implements the core gapil language compiler.
The compiler will generate types and command execution functions using LLVM for a resolved API. The compiler can be extended with Plugins for additional functionality.
Package compiler implements the core gapil language compiler.
The compiler will generate types and command execution functions using LLVM for a resolved API. The compiler can be extended with Plugins for additional functionality.
Index ¶
- Constants
- type C
- func (c *C) Alloc(s *S, count *codegen.Value, ty codegen.Type) *codegen.Value
- func (c *C) AppendBuffer(s *S, bufPtr, size, bytes *codegen.Value)
- func (c *C) AppendBufferData(s *S, bufPtr, ptr *codegen.Value)
- func (c *C) Build(f *codegen.Function, do func(*S))
- func (c *C) CopySlice(s *S, dst, src *codegen.Value)
- func (c *C) CopySliceByPtr(s *S, dst, src *codegen.Value)
- func (c *C) CurrentAPI() *semantic.API
- func (c *C) CurrentExpression() semantic.Expression
- func (c *C) CurrentStatement() semantic.Statement
- func (c *C) Delegate(from, to *codegen.Function)
- func (c *C) ExpressionStack() []semantic.Expression
- func (c *C) Fail(msg string, args ...interface{})
- func (c *C) Free(s *S, ptr *codegen.Value)
- func (c *C) InitBuffer(s *S, bufPtr, initialCapacity *codegen.Value)
- func (c *C) IterateMap(s *S, mapPtr *codegen.Value, idxTy semantic.Type, ...)
- func (c *C) LoadParameters(s *S, f *semantic.Function)
- func (c *C) Log(s *S, severity log.Severity, msg string, args ...interface{})
- func (c *C) LogF(s *S, msg string, args ...interface{})
- func (c *C) LogI(s *S, msg string, args ...interface{})
- func (c *C) MakeSlice(s *S, size, count *codegen.Value) *codegen.Value
- func (c *C) MakeSliceAt(s *S, size, count, slice *codegen.Value)
- func (c *C) MakeString(s *S, length, data *codegen.Value) *codegen.Value
- func (c *C) Mangle(ty codegen.Type) mangling.Type
- func (c *C) Method(isConst bool, owner codegen.Type, retTy codegen.Type, name string, ...) *codegen.Function
- func (c *C) Parameter(s *S, e *semantic.Parameter) *codegen.Value
- func (c *C) Realloc(s *S, old, count *codegen.Value) *codegen.Value
- func (c *C) SliceDataForRead(s *S, slice *codegen.Value, elType codegen.Type) *codegen.Value
- func (c *C) SliceDataForWrite(s *S, slice *codegen.Value, elType codegen.Type) *codegen.Value
- func (c *C) SourceLocation() SourceLocation
- func (c *C) SourceLocationFor(n semantic.Node) SourceLocation
- func (c *C) SourceLocationForCST(n cst.Node) SourceLocation
- func (c *C) StatementStack() []semantic.Statement
- func (c *C) StorageTypes(layout *device.MemoryLayout, prefix string) *StorageTypes
- func (c *C) TermBuffer(s *S, bufPtr *codegen.Value)
- type CommandInfo
- type ContextDataPlugin
- type ContextField
- type ErrorCode
- type FunctionExposerPlugin
- type MapInfo
- type MapMethods
- type OnBeginCommandListener
- type OnEndCommandListener
- type OnFenceListener
- type OnReadListener
- type OnWriteListener
- type Plugin
- type Program
- type S
- func (s *S) ForN(n *codegen.Value, cb func(s *S, iterator *codegen.Value) (cont *codegen.Value))
- func (s *S) If(cond *codegen.Value, onTrue func(s *S))
- func (s *S) IfElse(cond *codegen.Value, onTrue, onFalse func(s *S))
- func (s *S) Return(val *codegen.Value)
- func (s *S) Switch(cases []SwitchCase, defaultCase func(s *S))
- type Settings
- type SourceLocation
- type StorageTypes
- type StructInfo
- type SwitchCase
- type Types
- func (t *Types) AlignOf(layout *device.MemoryLayout, ty semantic.Type) uint64
- func (t *Types) Capture(ty semantic.Type) codegen.Type
- func (t *Types) SizeOf(layout *device.MemoryLayout, ty semantic.Type) uint64
- func (t *Types) StrideOf(layout *device.MemoryLayout, ty semantic.Type) uint64
- func (t *Types) Target(ty semantic.Type) codegen.Type
Constants ¶
const ( // ErrSuccess is the error code for a success. ErrSuccess = ErrorCode(C.GAPIL_ERR_SUCCESS) // ErrAborted is the error code for a command that called abort(). ErrAborted = ErrorCode(C.GAPIL_ERR_ABORTED) )
const ( ContextGlobals = "globals" ContextArena = "arena" ContextThread = "thread" ContextCmdID = "cmd_id" ContextCmdArgs = "cmd_args" ContextNextPoolID = "next_pool_id" )
Field names for the context_t runtime type.
const ( SlicePool = "pool" SliceRoot = "root" SliceBase = "base" SliceSize = "size" SliceCount = "count" )
Field names for the slice_t runtime type.
const ( RTTIKind = "kind" RTTIAPIIndex = "api_index" RTTITypeIndex = "type_index" RTTITypeName = "type_name" RTTIReference = "reference" RTTIRelease = "release" )
Field names for the gapil_rtti_t runtime type.
const ( AnyRefCount = "ref_count" AnyArena = "arena" AnyRTTI = "rtti" AnyValue = "value" )
Field names for the gapil_any_t runtime type.
const ( MsgArgName = "name" MsgArgValue = "value" )
Field names for the gapil_msg_arg_t runtime type.
const ( MsgRefCount = "ref_count" MsgArena = "arena" MsgIdentifier = "identifier" MsgArgs = "args" )
Field names for the gapil_msg_t runtime type.
const ( PoolRefCount = "ref_count" PoolID = "id" PoolSize = "size" PoolBuffer = "buffer" )
Field names for the pool_t runtime type.
const ( MapRefCount = "ref_count" MapArena = "arena" MapCount = "count" MapCapacity = "capacity" MapElements = "elements" )
Field names for the map_t runtime type.
const ( StringRefCount = "ref_count" StringArena = "arena" StringLength = "length" StringData = "data" )
Field names for the string_t runtime type.
const ( RefRefCount = "ref_count" RefArena = "arena" RefValue = "value" )
Field names for the ref_t runtime type.
const ( BufArena = "arena" BufData = "data" BufCap = "capacity" BufSize = "size" BufAlign = "alignment" )
Field names for the buffer_t runtime type.
const ( Read = C.GAPIL_READ Write = C.GAPIL_WRITE )
gapil_data_access enumerator values.
const ( KindBool = uint32(C.GAPIL_KIND_BOOL) KindU8 = uint32(C.GAPIL_KIND_U8) KindS8 = uint32(C.GAPIL_KIND_S8) KindU16 = uint32(C.GAPIL_KIND_U16) KindS16 = uint32(C.GAPIL_KIND_S16) KindF32 = uint32(C.GAPIL_KIND_F32) KindU32 = uint32(C.GAPIL_KIND_U32) KindS32 = uint32(C.GAPIL_KIND_S32) KindF64 = uint32(C.GAPIL_KIND_F64) KindU64 = uint32(C.GAPIL_KIND_U64) KindS64 = uint32(C.GAPIL_KIND_S64) KindInt = uint32(C.GAPIL_KIND_INT) KindUint = uint32(C.GAPIL_KIND_UINT) KindSize = uint32(C.GAPIL_KIND_SIZE) KindChar = uint32(C.GAPIL_KIND_CHAR) KindArray = uint32(C.GAPIL_KIND_ARRAY) KindClass = uint32(C.GAPIL_KIND_CLASS) KindEnum = uint32(C.GAPIL_KIND_ENUM) KindMap = uint32(C.GAPIL_KIND_MAP) KindPointer = uint32(C.GAPIL_KIND_POINTER) KindReference = uint32(C.GAPIL_KIND_REFERENCE) KindSlice = uint32(C.GAPIL_KIND_SLICE) KindString = uint32(C.GAPIL_KIND_STRING) )
gapil_kind enumerator values.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type C ¶
type C struct { // T holds the compiler types. T Types // M is the codegen module for the program. M *codegen.Module // APIs are the apis that are being compiled. APIs []*semantic.API // Mangler is the symbol mangler in use. Mangler mangling.Mangler // Root is the namespace in which generated symbols should be placed. // This excludes gapil runtime symbols which have the prefix 'gapil_'. Root mangling.Scope // Settings are the configuration values used for this compile. Settings Settings // contains filtered or unexported fields }
C is the compiler context used to build the program.
func (*C) Alloc ¶
Alloc calls gapil_alloc to allocate a buffer big enough to hold count elements of type ty.
func (*C) AppendBuffer ¶ added in v1.2.0
AppendBuffer appends bytes to the buffer. size must be of type uint32. bytes must be of type void* (alias of uint8*).
func (*C) AppendBufferData ¶ added in v1.2.0
AppendBufferData appends a data to the buffer from the given pointer.
func (*C) Build ¶
Build implements the function f by creating a new scope and calling do to emit the function body. If the function has a parameter of type context_t* then the Ctx, Globals and Arena scope fields are automatically assigned.
func (*C) CopySliceByPtr ¶ added in v1.2.0
CopySliceByPtr copies the contents of slice at *src to the slice at *dst.
func (*C) CurrentAPI ¶ added in v1.2.0
CurrentAPI returns the API that is currently being built.
func (*C) CurrentExpression ¶ added in v1.2.0
func (c *C) CurrentExpression() semantic.Expression
CurrentExpression returns the expression that is currently being built.
func (*C) CurrentStatement ¶ added in v1.2.0
CurrentStatement returns the statement that is currently being built.
func (*C) Delegate ¶ added in v1.2.0
Delegate builds the function from with a simple body that calls to, with implicit casts for each of the parameters. If the function to returns a value, this is cast to the from return type and returned. Delegate can be used to produce stub functions that have equivalent signatures when lowered to LLVM types.
func (*C) ExpressionStack ¶ added in v1.2.0
func (c *C) ExpressionStack() []semantic.Expression
ExpressionStack returns the current build stack of expressions.
func (*C) Fail ¶
Fail is used to immediately terminate compilation due to an internal compiler error.
func (*C) Free ¶
Free calls gapil_free to release a buffer that was previously allocated with Alloc or Realloc.
func (*C) InitBuffer ¶ added in v1.2.0
InitBuffer initializes a buffer with the initial capacity. initialCapacity must be of type uint32.
func (*C) IterateMap ¶
func (c *C) IterateMap(s *S, mapPtr *codegen.Value, idxTy semantic.Type, cb func(i, k, v *codegen.Value))
IterateMap emits a map iteration calling cb for each element in the map where: i is a pointer to the sequential index of the element starting from 0 of type
idxTy.
k is a pointer to the element key. v is a pointer to the element value.
func (*C) LoadParameters ¶ added in v1.2.0
LoadParameters loads the command's parameters from the context's arguments field and stores them into s.Parameters.
func (*C) Log ¶
Log emits a call to gapil_logf with the given printf-style arguments. args can be a mix of codegen.Values or simple data types (which are automatically passed to codegen.Builder.Scalar).
func (*C) MakeSliceAt ¶
MakeSliceAt creates a new slice of the given size in bytes at the given slice pointer.
func (*C) MakeString ¶
MakeString creates a new string from the specified data and length in bytes.
func (*C) Method ¶
func (c *C) Method( isConst bool, owner codegen.Type, retTy codegen.Type, name string, params ...codegen.Type) *codegen.Function
Method declares a function as a member of owner using the compiler's mangler.
func (*C) Parameter ¶ added in v1.2.0
Parameter returns the loaded parameter value, failing if the parameter cannot be found.
func (*C) Realloc ¶
Realloc calls gapil_realloc to reallocate a buffer that was previously allocated with Alloc or Realloc.
func (*C) SliceDataForRead ¶ added in v1.2.0
SliceDataForRead returns a pointer to an array of slice elements. This pointer should be used to read (not write) from the slice. The pointer is only valid until the slice is touched again.
func (*C) SliceDataForWrite ¶ added in v1.2.0
SliceDataForWrite returns a pointer to an array of slice elements. This pointer should be used to write (not read) to the slice. The pointer is only valid until the slice is touched again.
func (*C) SourceLocation ¶ added in v1.2.0
func (c *C) SourceLocation() SourceLocation
SourceLocation returns the SoureLocation for the currently built expression, statement or function.
func (*C) SourceLocationFor ¶ added in v1.2.0
func (c *C) SourceLocationFor(n semantic.Node) SourceLocation
SourceLocationFor returns a string describing the source location of the given semantic node.
func (*C) SourceLocationForCST ¶ added in v1.2.0
func (c *C) SourceLocationForCST(n cst.Node) SourceLocation
SourceLocationForCST returns a string describing the source location of the given CST node.
func (*C) StatementStack ¶ added in v1.2.0
StatementStack returns the current build stack of statements.
func (*C) StorageTypes ¶ added in v1.2.0
func (c *C) StorageTypes(layout *device.MemoryLayout, prefix string) *StorageTypes
StorageTypes returns a StorageTypes built for the given ABI.
type CommandInfo ¶
type CommandInfo struct { // The execute function for the given command. // The function has the signature: void (ctx*, Params*) Execute *codegen.Function // The Params structure that is passed to Execute. Parameters *codegen.Struct }
CommandInfo holds the generated execute function for a given command.
type ContextDataPlugin ¶ added in v1.2.0
type ContextDataPlugin interface { // OnPreBuildContext is called just before the context structure is built. // This can be used to build any additional types that are returned by // ContextData(). OnPreBuildContext(*C) // ContextData returns a slice of additional ContextFields that will be // augmented to the context structure. ContextData(*C) []ContextField }
ContextDataPlugin is the interface implemented by plugins that require additional data to be stored in the runtime context.
type ContextField ¶ added in v1.2.0
type ContextField struct { Name string // Name of the field Type codegen.Type // Type of the field Init func(s *S, fieldPtr *codegen.Value) // Optional initializer Term func(s *S, fieldPtr *codegen.Value) // Optional terminator }
ContextField represents a single additional context field added by a ContextDataPlugin.
type ErrorCode ¶
type ErrorCode uint32
ErrorCode is an error code returned (possibly in a <value, errcode> pair) by a command or subroutine.
type FunctionExposerPlugin ¶ added in v1.2.0
FunctionExposerPlugin is the interface implemented by plugins that build public functions. These functions will be exposed on the output Program.
type MapInfo ¶
type MapInfo struct { Type *codegen.Struct // Maps are held as pointers to these structs Elements *codegen.Struct Key codegen.Type Val codegen.Type Element codegen.Type MapMethods }
MapInfo holds the generated map info for a given semantic map type.
type MapMethods ¶ added in v1.2.0
type MapMethods struct { Contains *codegen.Function // bool(M*, ctx*, K) Index *codegen.Function // V*(M*, ctx*, K, addIfNotFound) Remove *codegen.Function // void(M*, ctx*, K) Clear *codegen.Function // void(M*, ctx*) ClearKeep *codegen.Function // void(M*, ctx*) }
MapMethods are the functions that operate on a map.
type OnBeginCommandListener ¶ added in v1.2.0
OnBeginCommandListener is the interface implemented by plugins that generate custom logic at the start of the command.
type OnEndCommandListener ¶ added in v1.2.0
OnEndCommandListener is the interface implemented by plugins that generate custom logic at the end of the command.
type OnFenceListener ¶ added in v1.2.0
type OnFenceListener interface {
OnFence(s *S)
}
OnFenceListener is the interface implemented by plugins that generate custom logic at the fence of the command.
type OnReadListener ¶ added in v1.2.0
OnReadListener is the interface implemented by plugins that generate custom logic when slices are read.
type OnWriteListener ¶ added in v1.2.0
OnWriteListener is the interface implemented by plugins that generate custom logic when slices are written.
type Program ¶
type Program struct { // Settings used to compile the program. Settings Settings // APIs compiled for this program. APIs []*semantic.API // Commands is a map of command name to CommandInfo. Commands map[string]*CommandInfo // Structs is a map of struct name to StructInfo. Structs map[string]*StructInfo // Maps is a map of map name to MapInfo. Maps map[string]*MapInfo // Globals is the StructInfo of all the globals. Globals *StructInfo // Functions is a map of function name to plugin implemented functions. Functions map[string]*codegen.Function // Codegen is the codegen module. Codegen *codegen.Module // Module is the global that holds the generated gapil_module structure. Module codegen.Global }
Program is the output of a compilation.
type S ¶
type S struct { // The scope can emit any instructions into the current scope block. *codegen.Builder // Ctx is a pointer to the active context (context_t*). Ctx *codegen.Value // Location is a pointer to the current source code location (uint32_t*). Location *codegen.Value // Globals is a pointer to the current API's global state variables. Globals *codegen.Value // Arena is a pointer to the current memory arena (arena*). Arena *codegen.Value // Parameters is the current function's parameters. Parameters map[*semantic.Parameter]*codegen.Value // The identifier of the currently executing thread. CurrentThread *codegen.Value // contains filtered or unexported fields }
S is a nestable compiler scope. A scope holds parameters and local variables.
func (*S) ForN ¶ added in v1.2.0
ForN overrides codegen.Builder.ForN to ensure all the scopes are popped after cb reaches its last instruction.
func (*S) If ¶ added in v1.2.0
If overrides codegen.Builder.If to ensure all the scopes are popped after onTrue reaches its last instruction.
func (*S) IfElse ¶ added in v1.2.0
IfElse overrides codegen.Builder.IfElse to ensure all the scopes are popped after onTrue and onFalse reach their last instruction.
func (*S) Return ¶ added in v1.2.0
Return overrides codegen.Builder.Return to ensure all the scopes are popped before emitting the terminating instruction.
func (*S) Switch ¶ added in v1.2.0
func (s *S) Switch(cases []SwitchCase, defaultCase func(s *S))
Switch overrides codegen.Builder.Switch to ensure all the scopes are popped after each condition and block reach their last instruction.
type Settings ¶
type Settings struct { // The name of the module to produce. // This will be a global of the gapil_module type. Module string // TargetABI is the ABI used by the device running the compiled code. TargetABI *device.ABI // CaptureABI is the ABI of the device used to generate the capture data. CaptureABI *device.ABI // The mangler used for global functions and types. Mangler mangling.Mangler // Prefix for mangler Namespaces []string // EmitDebug is true if the compiler should emit DWARF debug info. EmitDebug bool // EmitContext is true if the compiler should generate context creation and // destruction functions. EmitContext bool // EmitExec is true if the compiler should generate execution functions for // each API command. Implies EmitContext. EmitExec bool // WriteToApplicationPool is true if writes to the application pool should // be performed. WriteToApplicationPool bool // Plugins are the list of extensions to include in the compilation. Plugins []Plugin }
Settings describe the options used to compile an API file.
type SourceLocation ¶ added in v1.2.0
SourceLocation associates a semantic node with its location in a source file.
func (SourceLocation) IsValid ¶ added in v1.2.0
func (l SourceLocation) IsValid() bool
IsValid returns true if the source location is valid.
func (SourceLocation) String ¶ added in v1.2.0
func (l SourceLocation) String() string
type StorageTypes ¶ added in v1.2.0
type StorageTypes struct {
// contains filtered or unexported fields
}
StorageTypes are types that can be persisted in buffers, with possibly a different ABI to the target.
func (*StorageTypes) AlignOf ¶ added in v1.2.0
func (s *StorageTypes) AlignOf(ty semantic.Type) uint64
AlignOf returns the alignment of this type in bytes.
func (*StorageTypes) Get ¶ added in v1.2.0
func (s *StorageTypes) Get(ty semantic.Type) codegen.Type
Get returns the codegen type used to store ty in a buffer.
type StructInfo ¶
StructInfo holds the generated structure for a given structure type.
type SwitchCase ¶ added in v1.2.0
SwitchCase is a single condition and block used as a case statement in a switch.
type Types ¶
type Types struct { codegen.Types Ctx *codegen.Struct // context_t CtxPtr codegen.Type // context_t* Pool codegen.Type // pool_t PoolPtr codegen.Type // pool_t* Sli codegen.Type // slice_t Str *codegen.Struct // string_t StrPtr codegen.Type // string_t* Arena *codegen.Struct // arena_t ArenaPtr codegen.Type // arena_t* Any *codegen.Struct // gapil_any_t AnyPtr codegen.Type // gapil_any_t* Msg *codegen.Struct // gapil_msg_t MsgPtr codegen.Type // gapil_msg_t* MsgArg *codegen.Struct // gapil_msg_arg_t MsgArgPtr codegen.Type // gapil_msg_arg_t* RTTI *codegen.Struct // gapil_rtti Uint8Ptr codegen.Type // uint8_t* VoidPtr codegen.Type // void* (aliased of uint8_t*) VoidPtrPtr codegen.Type // void** (aliased of uint8_t**) Globals *codegen.Struct // API global variables structure. GlobalsPtr codegen.Type // Pointer to Globals. Buf codegen.Type // buffer_t BufPtr codegen.Type // buffer_t* CmdParams map[*semantic.Function]*codegen.Struct // struct holding all command parameters and return value. DataAccess codegen.Type Maps map[*semantic.Map]*MapInfo CaptureTypes *StorageTypes // contains filtered or unexported fields }
Types holds all the codegen Types for semantic types and the runtime. Types augments the codegen.Types structure.
func (*Types) AlignOf ¶ added in v1.2.0
AlignOf returns the alignment of this type in bytes for the given memory layout.
func (*Types) Capture ¶ added in v1.2.0
Capture returns the codegen type used to represent ty when stored in a capture's buffer.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package mangling exposes a minimal collection of types used to build mangled strings using any of the sub-packages.
|
Package mangling exposes a minimal collection of types used to build mangled strings using any of the sub-packages. |
c
Package c implements a basic symbol mangling for that is compatible with C.
|
Package c implements a basic symbol mangling for that is compatible with C. |
ia64
Package ia64 implements a subset of the symbol mangling for the itanium ABI (standard for GCC).
|
Package ia64 implements a subset of the symbol mangling for the itanium ABI (standard for GCC). |
plugins
|
|
cloner
Package cloner is a plugin for the gapil compiler to generate deep clone functions for reference types, maps and commands.
|
Package cloner is a plugin for the gapil compiler to generate deep clone functions for reference types, maps and commands. |
encoder
Package encoder is a plugin for the gapil compiler to generate command and state encode functions.
|
Package encoder is a plugin for the gapil compiler to generate command and state encode functions. |
encoder/test/encoder_pb
Package encoder_pb describes the serialization format for the serialzation test api.
|
Package encoder_pb describes the serialization format for the serialzation test api. |
replay
Package replay is a plugin for the gapil compiler to generate replay streams for commands.
|
Package replay is a plugin for the gapil compiler to generate replay streams for commands. |
Package testutils implements reusable helpers for writing compiler tests.
|
Package testutils implements reusable helpers for writing compiler tests. |