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.
Index ¶
- Constants
- type C
- func (c *C) Alloc(s *S, count *codegen.Value, ty codegen.Type) *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) Fail(msg string, args ...interface{})
- func (c *C) Free(s *S, ptr *codegen.Value)
- func (c *C) IterateMap(s *S, mapPtr *codegen.Value, idxTy semantic.Type, ...)
- func (c *C) Log(s *S, severity log.Severity, msg string, args ...interface{})
- func (c *C) MakeSlice(s *S, size, count *codegen.Value) *codegen.Value
- func (c *C) MakeSliceAt(s *S, size, count, dstPtr *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) Realloc(s *S, old, count *codegen.Value) *codegen.Value
- type CommandInfo
- type ErrorCode
- type Location
- type MapInfo
- type Plugin
- type Program
- type S
- type Settings
- type StructInfo
- type Types
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 ( ContextLocation = "location" ContextGlobals = "globals" ContextArena = "arena" )
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 ( 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.
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
// API is the api that is being compiled.
API *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
// 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) 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, Location, Globals and Arena scope fields are automatically assigned.
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) 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) 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.
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 ErrorCode ¶
type ErrorCode uint32
ErrorCode is an error code returned (possibly in a <value, errcode> pair) by a command or subroutine.
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
Contains codegen.Function // bool(ctx*, M*, K)
Index codegen.Function // V*(ctx*, M*, K, addIfNotFound)
Lookup codegen.Function // V(ctx*, M*, K)
Remove codegen.Function // void(ctx*, M*, K)
Clear codegen.Function // void(ctx*, M*)
}
MapInfo holds the generated map info for a given semantic map type.
type Program ¶
type Program struct {
// Settings used to compile the program.
Settings Settings
// 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
// Locations is the array of source locations.
// Only generated if Settings.CodeLocations is true.
Locations []Location
// Module is the generated code module.
Module *codegen.Module
// Initializer is a function that initializes the globals with defaults.
// The function has the signature: void (ctx* ctx)
Initializer codegen.Function
}
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
// contains filtered or unexported fields
}
S is a nestable compiler scope. A scope holds parameters and local variables.
type Settings ¶
type Settings struct {
// TargetABI is the ABI used by the device running the compiled code.
TargetABI *device.ABI
// StorageABI is the ABI of the device used to generate data in serialized
// buffers.
StorageABI *device.ABI
// The mangler used for global functions and types.
Mangler mangling.Mangler
// Prefix for mangler
Namespaces []string
// EmitExec is true if the compiler should generate execution functions for
// each API command.
EmitExec bool
// CodeLocations is true if the compiler should emit writes to the context's
// location field with the currently executing statement.
CodeLocations 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 StructInfo ¶
StructInfo holds the generated structure for a given structure type.
type Types ¶
type Types struct {
codegen.Types
Ctx codegen.Type // 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*
Uint8Ptr codegen.Type // uint8_t*
VoidPtr codegen.Type // void* (aliased of uint8_t*)
Globals *codegen.Struct // API global variables structure.
GlobalsPtr codegen.Type // Pointer to Globals.
CmdParams map[*semantic.Function]codegen.Type // struct holding all command parameters and return value.
Maps map[*semantic.Map]*MapInfo
// 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) StorageABIAlignment ¶
StorageABIAlignment returns the alignment of this type in bytes when stored.
func (*Types) StorageAllocaSize ¶
StorageAllocaSize returns the number of bytes per object if you were to store two next to each other in memory.
func (*Types) StorageSize ¶
StorageSize returns the number of bytes needed to store this type.
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. |
|
Package testexterns implements some extern functions used for compiler tests.
|
Package testexterns implements some extern functions used for compiler tests. |