Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Function.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_FUNCTION_H
10 #define TALVOS_FUNCTION_H
11 
12 #include <map>
13 #include <memory>
14 #include <vector>
15 
16 namespace talvos
17 {
18 
19 class Block;
20 class Type;
21 
23 class Function
24 {
25 public:
27  Function(uint32_t Id, const Type *FunctionType);
28 
29  // Do not allow Function objects to be copied.
31  Function(const Function &) = delete;
32  Function &operator=(const Function &) = delete;
34 
36  void addBlock(std::unique_ptr<Block> B);
37 
39  void addParam(uint32_t Id) { Parameters.push_back(Id); }
40 
42  const Block *getBlock(uint32_t Id) const { return Blocks.at(Id).get(); }
43 
45  const Block *getFirstBlock() const { return Blocks.at(FirstBlockId).get(); }
46 
48  uint32_t getFirstBlockId() const { return FirstBlockId; }
49 
51  uint32_t getId() const { return Id; }
52 
54  uint32_t getParamId(uint32_t I) const { return Parameters[I]; }
55 
57  size_t getNumParams() const { return Parameters.size(); }
58 
60  void setFirstBlock(uint32_t Id) { FirstBlockId = Id; }
61 
62 private:
64  typedef std::map<uint32_t, std::unique_ptr<Block>> BlockMap;
65 
66  uint32_t Id;
67  const Type *FunctionType;
68  uint32_t FirstBlockId;
70 
71  std::vector<uint32_t> Parameters;
72 };
73 
74 } // namespace talvos
75 
76 #endif
Function(uint32_t Id, const Type *FunctionType)
Create a new function with an ID and a type.
Definition: Function.cpp:18
Function & operator=(const Function &)=delete
void addParam(uint32_t Id)
Add a parameter to this function.
Definition: Function.h:39
uint32_t Id
The ID of this function.
Definition: Function.h:66
This class represents a function in a SPIR-V Module.
Definition: Function.h:23
std::vector< uint32_t > Parameters
The function parameter IDs.
Definition: Function.h:71
void setFirstBlock(uint32_t Id)
Sets the ID of the entry block in this function.
Definition: Function.h:60
uint32_t getFirstBlockId() const
Returns the ID of the first block in this function.
Definition: Function.h:48
BlockMap Blocks
The blocks in the function.
Definition: Function.h:69
size_t getNumParams() const
Returns the number of parameters in this function.
Definition: Function.h:57
std::map< uint32_t, std::unique_ptr< Block > > BlockMap
A mapping from IDs to Blocks.
Definition: Function.h:64
void addBlock(std::unique_ptr< Block > B)
Add a block to this function.
Definition: Function.cpp:24
uint32_t getParamId(uint32_t I) const
Returns the ID of the parameter at index I.
Definition: Function.h:54
uint32_t getId() const
Returns the ID of this function.
Definition: Function.h:51
const Block * getFirstBlock() const
Returns the first block in this function.
Definition: Function.h:45
This class represents a SPIR-V type.
Definition: Type.h:33
const Type * FunctionType
The function type.
Definition: Function.h:67
const Block * getBlock(uint32_t Id) const
Returns the block with ID Id.
Definition: Function.h:42
uint32_t FirstBlockId
The ID of the first block.
Definition: Function.h:68
A block of instructions ending with a termination instruction.
Definition: Block.h:21