Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Object.h
Go to the documentation of this file.
1 // Copyright (c) 2018 the Talvos developers. All rights reserved.
2 //
3 // This file is distributed under a three-clause BSD license. For full license
4 // terms please see the LICENSE file distributed with this source code.
5 
8 
9 #ifndef TALVOS_OBJECT_H
10 #define TALVOS_OBJECT_H
11 
12 #include <cstdint>
13 #include <iosfwd>
14 #include <vector>
15 
16 namespace talvos
17 {
18 
19 class Memory;
20 class Type;
21 
25 {
27  enum
28  {
31  } Order;
32 
35  uint32_t Stride = 0;
36 
38  operator bool() const { return Stride != 0; }
39 };
40 
43 {
44  uint64_t Address;
45  uint64_t NumBytes;
46 };
47 
51 class Object
52 {
53 public:
55  Object() { Data = nullptr; }
56 
60  Object(const Type *Ty, const uint8_t *Data = nullptr);
61 
64  template <typename T> Object(const Type *Ty, T Value);
65 
67  ~Object();
68 
70  Object(const Object &Src);
71 
73  Object &operator=(const Object &Src);
74 
76  Object(Object &&Src) noexcept;
77 
80  Object extract(const std::vector<uint32_t> &Indices) const;
81 
85  template <typename T> T get(uint32_t Element = 0) const;
86 
88  uint8_t *getData() { return Data; }
89 
91  const uint8_t *getData() const { return Data; }
92 
95 
98  const PtrMatrixLayout &getMatrixLayout() const;
99 
101  const Type *getType() const { return Ty; }
102 
104  void insert(const std::vector<uint32_t> &Indices, const Object &Element);
105 
107  operator bool() const { return Data ? true : false; }
108 
111  friend std::ostream &operator<<(std::ostream &Stream, const Object &O);
112 
116  template <typename T> void set(T Value, uint32_t Element = 0);
117 
120  void setDescriptorElements(const DescriptorElement *DAE);
121 
124  void setMatrixLayout(const PtrMatrixLayout &ML);
125 
127  void store(Memory &Mem, uint64_t Address) const;
128 
130  void store(Memory &Mem, const Object &Pointer) const;
131 
133  void zero();
134 
136  static Object load(const Type *Ty, const Memory &Mem, uint64_t Address);
137 
139  static Object load(const Type *Ty, const Memory &Mem, const Object &Pointer);
140 
141 private:
142  const Type *Ty;
143  uint8_t *Data;
144 
148 
152 };
153 
154 } // namespace talvos
155 
156 #endif
const DescriptorElement * getDescriptorElements() const
Returns the descriptor array element information.
Definition: Object.cpp:106
~Object()
Destroy this object.
Definition: Object.cpp:38
void setDescriptorElements(const DescriptorElement *DAE)
Set the descriptor array elements for this object.
Definition: Object.cpp:304
const uint8_t * getData() const
Returns an immutable pointer to the raw data backing this object.
Definition: Object.h:91
Structure to describe the memory layout of a matrix.
Definition: Object.h:24
void store(Memory &Mem, uint64_t Address) const
Store the value of this object to memory at Address.
Definition: Object.cpp:317
void set(T Value, uint32_t Element=0)
Set the value of this object to a scalar of type T.
Definition: Object.cpp:295
static Object load(const Type *Ty, const Memory &Mem, uint64_t Address)
Create an object of type Ty from the data at Address.
Definition: Object.cpp:137
enum talvos::PtrMatrixLayout::@4 Order
Specifies the order of the elements in memory.
const DescriptorElement * DescriptorElements
Descriptor array element information.
Definition: Object.h:151
uint32_t Stride
The stride in bytes between columns (COL_MAJOR) or rows (ROW_MAJOR).
Definition: Object.h:35
This class represents an address space in the virtual device.
Definition: Memory.h:37
uint8_t * Data
The raw data backing this object.
Definition: Object.h:143
Structure used to hold information about an element of a descriptor array.
Definition: Object.h:42
PtrMatrixLayout MatrixLayout
The memory layout of a matrix that this object points to.
Definition: Object.h:147
void zero()
Set all of the value bits in this object to zero.
Definition: Object.cpp:367
void setMatrixLayout(const PtrMatrixLayout &ML)
Set the matrix layout for this object.
Definition: Object.cpp:310
Object()
Create an empty, uninitialized object.
Definition: Object.h:55
uint8_t * getData()
Returns a mutable pointer to the raw data backing this object.
Definition: Object.h:88
const Type * getType() const
Returns the type of this object.
Definition: Object.h:101
Object & operator=(const Object &Src)
Copy-assign to this object, cloning the data from Src.
Definition: Object.cpp:53
uint64_t NumBytes
Size of descriptor element.
Definition: Object.h:45
const PtrMatrixLayout & getMatrixLayout() const
Get the matrix layout for this object.
Definition: Object.cpp:111
This class represents a SPIR-V type.
Definition: Type.h:33
void insert(const std::vector< uint32_t > &Indices, const Object &Element)
Insert the value of Element into a composite object.
Definition: Object.cpp:118
This class represents an instruction result.
Definition: Object.h:51
T get(uint32_t Element=0) const
Get the value of this object as a scalar of type T.
Definition: Object.cpp:97
Object extract(const std::vector< uint32_t > &Indices) const
Extract an element from a composite object.
Definition: Object.cpp:75
friend std::ostream & operator<<(std::ostream &Stream, const Object &O)
Allow an Object to be inserted into an output stream.
Definition: Object.cpp:283
uint64_t Address
Address of descriptor element.
Definition: Object.h:44
const Type * Ty
The type of this object.
Definition: Object.h:142