Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Instruction.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_INSTRUCTION_H
10 #define TALVOS_INSTRUCTION_H
11 
12 #include <cstdint>
13 #include <memory>
14 
15 namespace talvos
16 {
17 
18 class Type;
19 
28 {
29 public:
31  Instruction(uint16_t Opcode, uint16_t NumOperands, const uint32_t *Operands,
32  const Type *ResultType);
33 
37  ~Instruction() { delete[] Operands; }
38 
39  // Do not allow Instruction objects to be copied.
41  Instruction(const Instruction &) = delete;
42  const Instruction &operator=(const Instruction &) = delete;
44 
46  uint16_t getNumOperands() const { return NumOperands; }
47 
49  uint16_t getOpcode() const { return Opcode; }
50 
52  uint32_t getOperand(unsigned i) const { return Operands[i]; }
53 
55  const uint32_t *getOperands() const { return Operands; }
56 
59  const Type *getResultType() const { return ResultType; }
60 
63  void insertAfter(Instruction *I);
64 
68  const Instruction *next() const { return Next.get(); }
69 
73  const Instruction *previous() const { return Previous; }
74 
78  void print(std::ostream &O, bool Align = true) const;
79 
81  static const char *opcodeToString(uint16_t Opcode);
82 
83 private:
84  const Type *ResultType;
85  uint16_t Opcode;
86  uint16_t NumOperands;
87  uint32_t *Operands;
88 
89  std::unique_ptr<Instruction> Next;
90 
92 };
93 
94 } // namespace talvos
95 
96 #endif
uint16_t Opcode
The instruction opcode.
Definition: Instruction.h:85
const Instruction & operator=(const Instruction &)=delete
std::unique_ptr< Instruction > Next
The next instruction in the block.
Definition: Instruction.h:89
uint32_t getOperand(unsigned i) const
Returns the operand at index i;.
Definition: Instruction.h:52
uint32_t * Operands
The operand values.
Definition: Instruction.h:87
void insertAfter(Instruction *I)
Insert this instruction into a sequence, immediately following I.
Definition: Instruction.cpp:32
uint16_t getOpcode() const
Returns the opcode.
Definition: Instruction.h:49
const Type * ResultType
The type of the instruction result.
Definition: Instruction.h:84
~Instruction()
Destroy this instruction.
Definition: Instruction.h:37
Instruction(uint16_t Opcode, uint16_t NumOperands, const uint32_t *Operands, const Type *ResultType)
Create a new instruction.
Definition: Instruction.cpp:19
void print(std::ostream &O, bool Align=true) const
Print a human-readable form of this instruction to O.
Definition: Instruction.cpp:43
const Instruction * previous() const
Get the previous instruction in the containing block.
Definition: Instruction.h:73
uint16_t getNumOperands() const
Returns the number of operands this instruction has.
Definition: Instruction.h:46
const Type * getResultType() const
Returns the result type of this instruction, or nullptr if it does not produce a result.
Definition: Instruction.h:59
const uint32_t * getOperands() const
Returns the operands.
Definition: Instruction.h:55
uint16_t NumOperands
The number of operands in this instruction.
Definition: Instruction.h:86
This class represents a SPIR-V type.
Definition: Type.h:33
const Instruction * next() const
Get the next instruction in the containing block.
Definition: Instruction.h:68
This class represents a SPIR-V instruction.
Definition: Instruction.h:27
const Instruction * Previous
The previous instruction in the block.
Definition: Instruction.h:91
static const char * opcodeToString(uint16_t Opcode)
Return the string representation of an instruction opcode.
Definition: Instruction.cpp:72