GEGELATI

Loading...
Searching...
No Matches
instruction.h
1
39#ifndef INSTRUCTION_H
40#define INSTRUCTION_H
41
42#include <cstdint>
43#include <functional>
44#include <memory>
45#include <typeinfo>
46#include <vector>
47
48#include "data/untypedSharedPtr.h"
49
50namespace Instructions {
60 class Instruction
61 {
62
63#ifdef CODE_GENERATION
64 public:
72 virtual bool isPrintable() const;
73
81 virtual const std::string& getPrintTemplate() const;
82
92 virtual std::string getPrintablePrimitiveOperandType(
93 const uint64_t& opIdx) const;
94
95 protected:
105 Instruction(std::string printTemplate);
106
112 std::string printTemplate;
113
114 private:
146 inline static const std::string GET_PRINT_PRIMITIVE_OPERAND_TYPE{
147 "(const )?((struct )?[\\w:\\*]*)[ ]?(\\[(\\d)+\\])*"};
148
149#endif // CODE_GENERATION
150
151 public:
153 virtual ~Instruction() = default;
154
161 const std::vector<std::reference_wrapper<const std::type_info>>&
162 getOperandTypes() const;
163
171 unsigned int getNbOperands() const;
172
180 virtual bool checkOperandTypes(
181 const std::vector<Data::UntypedSharedPtr>& arguments) const;
182
196 virtual double execute(
197 const std::vector<Data::UntypedSharedPtr>& args) const = 0;
198
199 protected:
200#ifndef CODE_GENERATION
207 Instruction();
208#endif // CODE_GENERATION
213 std::vector<std::reference_wrapper<const std::type_info>> operandTypes;
214 };
215
216} // namespace Instructions
217#endif
Instructions::Instruction
This abstract class is the base class for any instruction to be used in a Program.
Definition instruction.h:61
Instructions::Instruction::getOperandTypes
const std::vector< std::reference_wrapper< const std::type_info > > & getOperandTypes() const
Get the list of operand types needed by the Instruction.
Definition instruction.cpp:57
Instructions::Instruction::getNbOperands
unsigned int getNbOperands() const
Get the number of operands required to execute the Instruction.
Definition instruction.cpp:62
Instructions::Instruction::getPrintablePrimitiveOperandType
virtual std::string getPrintablePrimitiveOperandType(const uint64_t &opIdx) const
Retrieve the primitive data type of the operand.
Definition instruction.cpp:114
Instructions::Instruction::execute
virtual double execute(const std::vector< Data::UntypedSharedPtr > &args) const =0
Execute the Instruction for the given arguments.
Definition instruction.cpp:82
Instructions::Instruction::Instruction
Instruction(std::string printTemplate)
Protected constructor to force the class abstract nature.
Definition instruction.cpp:99
Instructions::Instruction::getPrintTemplate
virtual const std::string & getPrintTemplate() const
This function return the printTemplate of the line of code used to represent the instruction.
Definition instruction.cpp:109
Instructions::Instruction::isPrintable
virtual bool isPrintable() const
function saying if an Instruction can be printed in a C file during the code gen.
Definition instruction.cpp:104
Instructions::Instruction::checkOperandTypes
virtual bool checkOperandTypes(const std::vector< Data::UntypedSharedPtr > &arguments) const
Check if a given vector contains elements whose types corresponds to the types of the Instruction ope...
Definition instruction.cpp:67
Instructions::Instruction::~Instruction
virtual ~Instruction()=default
Default virtual destructor for polyphormism.
Instructions::Instruction::printTemplate
std::string printTemplate
Definition instruction.h:112
Instructions
Definition addPrimitiveType.h:49