Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Variable.cpp
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 #include <cassert>
10 #include <spirv/unified1/spirv.h>
11 
12 #include "talvos/Type.h"
13 #include "talvos/Variable.h"
14 
15 namespace talvos
16 {
17 
18 Variable::Variable(uint32_t Id, const Type *Ty, uint32_t Initializer)
19  : Id(Id), Ty(Ty), Initializer(Initializer)
20 {}
21 
22 void Variable::addDecoration(uint32_t Decoration, uint32_t Data)
23 {
24  Decorations[Decoration] = Data;
25 }
26 
27 uint32_t Variable::getDecoration(uint32_t Decoration) const
28 {
29  assert(Decorations.count(Decoration));
30  return Decorations.at(Decoration);
31 }
32 
33 bool Variable::hasDecoration(uint32_t Decoration) const
34 {
35  return Decorations.count(Decoration);
36 }
37 
39 {
40  if (Ty->getStorageClass() == SpvStorageClassStorageBuffer ||
41  Ty->getStorageClass() == SpvStorageClassUniform ||
42  Ty->getStorageClass() == SpvStorageClassUniformConstant)
43  return true;
44  else
45  return false;
46 }
47 
48 } // namespace talvos
bool isBufferVariable() const
Returns true if this variable has a buffer or uniform storage class.
Definition: Variable.cpp:38
Variable(uint32_t Id, const Type *Ty, uint32_t Initializer=0)
Create a module scope variable with an optional initializer.
Definition: Variable.cpp:18
std::map< uint32_t, uint32_t > Decorations
Map of decorations.
Definition: Variable.h:60
uint32_t getDecoration(uint32_t Decoration) const
Returns the decoration data associated with this variable.
Definition: Variable.cpp:27
This file declares the Type class.
uint32_t getStorageClass() const
Returns the storage class of this type.
Definition: Type.cpp:60
void addDecoration(uint32_t Decoration, uint32_t Data)
Add a decoration to this variable.
Definition: Variable.cpp:22
const Type * Ty
Type of the variable.
Definition: Variable.h:54
This class represents a SPIR-V type.
Definition: Type.h:33
This file declares the Variable class.
bool hasDecoration(uint32_t Decoration) const
Returns true if this variable has been decorated with Decoration.
Definition: Variable.cpp:33