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

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

#include <talvos/Instruction.h>

Public Member Functions

 Instruction (uint16_t Opcode, uint16_t NumOperands, const uint32_t *Operands, const Type *ResultType)
 Create a new instruction. More...
 
 ~Instruction ()
 Destroy this instruction. More...
 
uint16_t getNumOperands () const
 Returns the number of operands this instruction has. More...
 
uint16_t getOpcode () const
 Returns the opcode. More...
 
uint32_t getOperand (unsigned i) const
 Returns the operand at index i;. More...
 
const uint32_t * getOperands () const
 Returns the operands. More...
 
const TypegetResultType () const
 Returns the result type of this instruction, or nullptr if it does not produce a result. More...
 
void insertAfter (Instruction *I)
 Insert this instruction into a sequence, immediately following I. More...
 
const Instructionnext () const
 Get the next instruction in the containing block. More...
 
const Instructionprevious () const
 Get the previous instruction in the containing block. More...
 
void print (std::ostream &O, bool Align=true) const
 Print a human-readable form of this instruction to O. More...
 
 Instruction (const Instruction &)=delete
 
const Instructionoperator= (const Instruction &)=delete
 

Static Public Member Functions

static const char * opcodeToString (uint16_t Opcode)
 Return the string representation of an instruction opcode. More...
 

Private Attributes

const TypeResultType
 The type of the instruction result. More...
 
uint16_t Opcode
 The instruction opcode. More...
 
uint16_t NumOperands
 The number of operands in this instruction. More...
 
uint32_t * Operands
 The operand values. More...
 
std::unique_ptr< InstructionNext
 The next instruction in the block. More...
 
const InstructionPrevious
 The previous instruction in the block. More...
 

Detailed Description

This class represents a SPIR-V instruction.

An instance of this class has an opcode, a set of operands, and possibly a return type. It is also a node in a linked list of instructions, forming a sequence that represents the instructions within a block. After creation, an Instruction should be inserted into a instruction sequence or the beginning of a block.

Definition at line 27 of file Instruction.h.

Constructor & Destructor Documentation

talvos::Instruction::Instruction ( uint16_t  Opcode,
uint16_t  NumOperands,
const uint32_t *  Operands,
const Type ResultType 
)

Create a new instruction.

Definition at line 19 of file Instruction.cpp.

talvos::Instruction::~Instruction ( )
inline

Destroy this instruction.

If the instruction has been inserted into a sequence, this will also destroy any instructions that follow it.

Definition at line 37 of file Instruction.h.

talvos::Instruction::Instruction ( const Instruction )
delete

Member Function Documentation

uint16_t talvos::Instruction::getNumOperands ( ) const
inline

Returns the number of operands this instruction has.

Definition at line 46 of file Instruction.h.

uint16_t talvos::Instruction::getOpcode ( ) const
inline

Returns the opcode.

Definition at line 49 of file Instruction.h.

uint32_t talvos::Instruction::getOperand ( unsigned  i) const
inline

Returns the operand at index i;.

Definition at line 52 of file Instruction.h.

const uint32_t* talvos::Instruction::getOperands ( ) const
inline

Returns the operands.

Definition at line 55 of file Instruction.h.

const Type* talvos::Instruction::getResultType ( ) const
inline

Returns the result type of this instruction, or nullptr if it does not produce a result.

Definition at line 59 of file Instruction.h.

void talvos::Instruction::insertAfter ( Instruction I)

Insert this instruction into a sequence, immediately following I.

This transfers ownership of this instruction to the containing block.

Definition at line 32 of file Instruction.cpp.

const Instruction* talvos::Instruction::next ( ) const
inline

Get the next instruction in the containing block.

Returns
the next instruction, or nullptr if this instruction is a terminator.

Definition at line 68 of file Instruction.h.

const char * talvos::Instruction::opcodeToString ( uint16_t  Opcode)
static

Return the string representation of an instruction opcode.

Definition at line 72 of file Instruction.cpp.

const Instruction& talvos::Instruction::operator= ( const Instruction )
delete
const Instruction* talvos::Instruction::previous ( ) const
inline

Get the previous instruction in the containing block.

Returns
the previous instruction, or nullptr if this instruction is the first in its block.

Definition at line 73 of file Instruction.h.

void talvos::Instruction::print ( std::ostream &  O,
bool  Align = true 
) const

Print a human-readable form of this instruction to O.

If Align is true then whitespace will be added to align output with any other instructions printed using this method.

Definition at line 43 of file Instruction.cpp.

Member Data Documentation

std::unique_ptr<Instruction> talvos::Instruction::Next
private

The next instruction in the block.

Definition at line 89 of file Instruction.h.

uint16_t talvos::Instruction::NumOperands
private

The number of operands in this instruction.

Definition at line 86 of file Instruction.h.

uint16_t talvos::Instruction::Opcode
private

The instruction opcode.

Definition at line 85 of file Instruction.h.

uint32_t* talvos::Instruction::Operands
private

The operand values.

Definition at line 87 of file Instruction.h.

const Instruction* talvos::Instruction::Previous
private

The previous instruction in the block.

Definition at line 91 of file Instruction.h.

const Type* talvos::Instruction::ResultType
private

The type of the instruction result.

Definition at line 84 of file Instruction.h.