Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
talvos::Type Class Reference

This class represents a SPIR-V type. More...

#include <talvos/Type.h>

Public Types

enum  TypeId {
  VOID, BOOL, INT, FLOAT,
  VECTOR, MATRIX, IMAGE, SAMPLER,
  SAMPLED_IMAGE, ARRAY, RUNTIME_ARRAY, STRUCT,
  POINTER, FUNCTION
}
 Identifiers that distinguish between different base types. More...
 

Public Member Functions

uint32_t getBitWidth () const
 Returns the bit-width of this type. More...
 
uint32_t getDimensionality () const
 Returns the dimensionality of an image type. More...
 
uint32_t getElementCount () const
 Returns the number of elements in this array, struct, or vector type. More...
 
size_t getElementOffset (uint64_t Index) const
 Returns the byte offset of the element at Index. More...
 
const TypegetElementType (uint64_t Index=0) const
 Returns the type of the element at Index. More...
 
const TypegetScalarType () const
 Returns the element type for vector types, or this for scalar types. More...
 
size_t getSize () const
 Returns the size of this type in bytes. More...
 
uint32_t getStorageClass () const
 Returns the storage class of this type. More...
 
const std::map< uint32_t,
uint32_t > & 
getStructMemberDecorations (uint32_t Index) const
 Returns the decoration map for the structure member at Index. More...
 
TypeId getTypeId () const
 Returns the type ID of this type. More...
 
bool isArray () const
 Returns true if this is an array type. More...
 
bool isArrayedImage () const
 Returns the Arrayed flag of an image type. More...
 
bool isBool () const
 Returns true if this is a bool type. More...
 
bool isComposite () const
 Returns true if this is an array, struct, or vector type. More...
 
bool isFloat () const
 Returns true if this is a floating point type. More...
 
bool isInt () const
 Returns true if this is an integer type. More...
 
bool isMatrix () const
 Returns true if this is a matrix type. More...
 
bool isPointer () const
 Returns true if this is a pointer type. More...
 
bool isScalar () const
 Returns true if this is a scalar type. More...
 
bool isStruct () const
 Returns true if this is a struct type. More...
 
bool isVector () const
 Returns true if this is a vector type. More...
 

Static Public Member Functions

static std::unique_ptr< TypegetArray (const Type *ElemType, uint32_t ElementCount, uint32_t ArrayStride)
 Create an array type. More...
 
static std::unique_ptr< TypegetBool ()
 Create a boolean type. More...
 
static std::unique_ptr< TypegetFloat (uint32_t Width)
 Create a floating point type. More...
 
static std::unique_ptr< TypegetInt (uint32_t Width)
 Create an integer type. More...
 
static std::unique_ptr< TypegetFunction (const Type *ReturnType, const std::vector< const Type * > &ArgTypes)
 Create a function type. More...
 
static std::unique_ptr< TypegetImage (const Type *SampledType, uint32_t Dim, uint32_t Depth, bool Arrayed, bool MS, uint32_t Sampled, uint32_t Format)
 Create an image type. More...
 
static std::unique_ptr< TypegetMatrix (const Type *ColumnType, uint32_t NumColumns)
 Create a matrix type. More...
 
static std::unique_ptr< TypegetPointer (uint32_t StorageClass, const Type *ElemType, uint32_t ArrayStride)
 Create a pointer type. More...
 
static std::unique_ptr< TypegetRuntimeArray (const Type *ElemType, uint32_t ArrayStride)
 Create a runtime array type. More...
 
static std::unique_ptr< TypegetSampledImage (const Type *ImageType)
 Create a sampled image type. More...
 
static std::unique_ptr< TypegetSampler ()
 Create a sampler type. More...
 
static std::unique_ptr< TypegetStruct (const StructElementTypeList &ElemTypes)
 Create a structure type. More...
 
static std::unique_ptr< TypegetVector (const Type *ElemType, uint32_t ElemCount)
 Create a vector type. More...
 
static std::unique_ptr< TypegetVoid ()
 Create a void type. More...
 

Private Member Functions

 Type (TypeId Id, size_t ByteSize)
 Create a new type. More...
 

Private Attributes

TypeId Id
 The ID of this type. More...
 
size_t ByteSize
 The size of this type in bytes. More...
 
uint32_t BitWidth
 Valid for integer and floating point types. More...
 
uint32_t StorageClass
 Valid for pointer types. More...
 
const TypeElementType
 Valid for pointer and composite types. More...
 
uint32_t ElementCount
 Valid for composite types. More...
 
uint32_t ArrayStride
 Valid for array and pointer types. More...
 
StructElementTypeList ElementTypes
 Valid for struct types. More...
 
std::vector< size_t > ElementOffsets
 Valid for struct types. More...
 
const TypeReturnType
 Valid for function types. More...
 
std::vector< const Type * > ArgumentTypes
 Valid for function types. More...
 
uint32_t Dimensionality
 Valid for image types. More...
 
uint32_t Depth
 Valid for image types. More...
 
bool Arrayed
 Valid for image types. More...
 
bool Multisampled
 Valid for image types. More...
 
uint32_t Sampled
 Valid for image types. More...
 
uint32_t Format
 Valid for image types. More...
 

Friends

std::ostream & operator<< (std::ostream &Stream, const Type *Ty)
 Allow a Type to be inserted into an output stream. More...
 

Detailed Description

This class represents a SPIR-V type.

Factory methods are provided to create specific type instances. Some methods of this class are only valid for certain types.

Definition at line 33 of file Type.h.

Member Enumeration Documentation

Identifiers that distinguish between different base types.

Enumerator
VOID 
BOOL 
INT 
FLOAT 
VECTOR 
MATRIX 
IMAGE 
SAMPLER 
SAMPLED_IMAGE 
ARRAY 
RUNTIME_ARRAY 
STRUCT 
POINTER 
FUNCTION 

Definition at line 37 of file Type.h.

Constructor & Destructor Documentation

talvos::Type::Type ( TypeId  Id,
size_t  ByteSize 
)
inlineprivate

Create a new type.

Used by the factory functions, which will populate class members directly.

Definition at line 186 of file Type.h.

Member Function Documentation

std::unique_ptr< Type > talvos::Type::getArray ( const Type ElemType,
uint32_t  ElementCount,
uint32_t  ArrayStride 
)
static

Create an array type.

Definition at line 230 of file Type.cpp.

uint32_t talvos::Type::getBitWidth ( ) const

Returns the bit-width of this type.

Valid for integer and floating point types.

Definition at line 20 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getBool ( )
static

Create a boolean type.

Definition at line 242 of file Type.cpp.

uint32_t talvos::Type::getDimensionality ( ) const
inline

Returns the dimensionality of an image type.

Definition at line 60 of file Type.h.

uint32_t talvos::Type::getElementCount ( ) const
inline

Returns the number of elements in this array, struct, or vector type.

Returns 1 for any scalar type.

Definition at line 64 of file Type.h.

size_t talvos::Type::getElementOffset ( uint64_t  Index) const

Returns the byte offset of the element at Index.

Valid for array, pointer, runtime array, struct, and vector types.

Definition at line 26 of file Type.cpp.

const Type * talvos::Type::getElementType ( uint64_t  Index = 0) const

Returns the type of the element at Index.

Valid for array, pointer, runtime array, struct, and vector types. For non-structure types, the value of Index is ignored.

Definition at line 38 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getFloat ( uint32_t  Width)
static

Create a floating point type.

Definition at line 247 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getFunction ( const Type ReturnType,
const std::vector< const Type * > &  ArgTypes 
)
static

Create a function type.

Definition at line 262 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getImage ( const Type SampledType,
uint32_t  Dim,
uint32_t  Depth,
bool  Arrayed,
bool  MS,
uint32_t  Sampled,
uint32_t  Format 
)
static

Create an image type.

Definition at line 271 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getInt ( uint32_t  Width)
static

Create an integer type.

Definition at line 254 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getMatrix ( const Type ColumnType,
uint32_t  NumColumns 
)
static

Create a matrix type.

Definition at line 286 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getPointer ( uint32_t  StorageClass,
const Type ElemType,
uint32_t  ArrayStride 
)
static

Create a pointer type.

Definition at line 295 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getRuntimeArray ( const Type ElemType,
uint32_t  ArrayStride 
)
static

Create a runtime array type.

Definition at line 306 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getSampledImage ( const Type ImageType)
static

Create a sampled image type.

Definition at line 316 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getSampler ( )
static

Create a sampler type.

Definition at line 323 of file Type.cpp.

const Type * talvos::Type::getScalarType ( ) const

Returns the element type for vector types, or this for scalar types.

Not valid for any other type.

Definition at line 49 of file Type.cpp.

size_t talvos::Type::getSize ( ) const
inline

Returns the size of this type in bytes.

Returns zero for void, function, and runtime array types.

Definition at line 81 of file Type.h.

uint32_t talvos::Type::getStorageClass ( ) const

Returns the storage class of this type.

Valid for pointer types.

Definition at line 60 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getStruct ( const StructElementTypeList ElemTypes)
static

Create a structure type.

Definition at line 328 of file Type.cpp.

const std::map< uint32_t, uint32_t > & talvos::Type::getStructMemberDecorations ( uint32_t  Index) const

Returns the decoration map for the structure member at Index.

Definition at line 67 of file Type.cpp.

TypeId talvos::Type::getTypeId ( ) const
inline

Returns the type ID of this type.

Definition at line 92 of file Type.h.

std::unique_ptr< Type > talvos::Type::getVector ( const Type ElemType,
uint32_t  ElemCount 
)
static

Create a vector type.

Definition at line 368 of file Type.cpp.

std::unique_ptr< Type > talvos::Type::getVoid ( )
static

Create a void type.

Definition at line 377 of file Type.cpp.

bool talvos::Type::isArray ( ) const
inline

Returns true if this is an array type.

Definition at line 95 of file Type.h.

bool talvos::Type::isArrayedImage ( ) const
inline

Returns the Arrayed flag of an image type.

Definition at line 98 of file Type.h.

bool talvos::Type::isBool ( ) const
inline

Returns true if this is a bool type.

Definition at line 101 of file Type.h.

bool talvos::Type::isComposite ( ) const

Returns true if this is an array, struct, or vector type.

Definition at line 72 of file Type.cpp.

bool talvos::Type::isFloat ( ) const
inline

Returns true if this is a floating point type.

Definition at line 107 of file Type.h.

bool talvos::Type::isInt ( ) const
inline

Returns true if this is an integer type.

Definition at line 110 of file Type.h.

bool talvos::Type::isMatrix ( ) const
inline

Returns true if this is a matrix type.

Definition at line 113 of file Type.h.

bool talvos::Type::isPointer ( ) const
inline

Returns true if this is a pointer type.

Definition at line 116 of file Type.h.

bool talvos::Type::isScalar ( ) const

Returns true if this is a scalar type.

Definition at line 77 of file Type.cpp.

bool talvos::Type::isStruct ( ) const
inline

Returns true if this is a struct type.

Definition at line 122 of file Type.h.

bool talvos::Type::isVector ( ) const
inline

Returns true if this is a vector type.

Definition at line 125 of file Type.h.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  Stream,
const Type Ty 
)
friend

Allow a Type to be inserted into an output stream.

Converts the type to a human readable format.

Definition at line 82 of file Type.cpp.

Member Data Documentation

std::vector<const Type *> talvos::Type::ArgumentTypes
private

Valid for function types.

Definition at line 210 of file Type.h.

bool talvos::Type::Arrayed
private

Valid for image types.

Definition at line 214 of file Type.h.

uint32_t talvos::Type::ArrayStride
private

Valid for array and pointer types.

Definition at line 204 of file Type.h.

uint32_t talvos::Type::BitWidth
private

Valid for integer and floating point types.

Definition at line 198 of file Type.h.

size_t talvos::Type::ByteSize
private

The size of this type in bytes.

Definition at line 196 of file Type.h.

uint32_t talvos::Type::Depth
private

Valid for image types.

Definition at line 213 of file Type.h.

uint32_t talvos::Type::Dimensionality
private

Valid for image types.

Definition at line 212 of file Type.h.

uint32_t talvos::Type::ElementCount
private

Valid for composite types.

Definition at line 203 of file Type.h.

std::vector<size_t> talvos::Type::ElementOffsets
private

Valid for struct types.

Definition at line 207 of file Type.h.

const Type* talvos::Type::ElementType
private

Valid for pointer and composite types.

Definition at line 202 of file Type.h.

StructElementTypeList talvos::Type::ElementTypes
private

Valid for struct types.

Definition at line 206 of file Type.h.

uint32_t talvos::Type::Format
private

Valid for image types.

Definition at line 217 of file Type.h.

TypeId talvos::Type::Id
private

The ID of this type.

Definition at line 192 of file Type.h.

bool talvos::Type::Multisampled
private

Valid for image types.

Definition at line 215 of file Type.h.

const Type* talvos::Type::ReturnType
private

Valid for function types.

Definition at line 209 of file Type.h.

uint32_t talvos::Type::Sampled
private

Valid for image types.

Definition at line 216 of file Type.h.

uint32_t talvos::Type::StorageClass
private

Valid for pointer types.

Definition at line 200 of file Type.h.