GEGELATI
instruction.h
1
38#ifndef INSTRUCTION_H
39#define INSTRUCTION_H
40
41#include <functional>
42#include <memory>
43#include <typeinfo>
44#include <vector>
45
46#include "data/untypedSharedPtr.h"
47
48namespace Instructions {
59 {
60
61#ifdef CODE_GENERATION
62 public:
70 virtual bool isPrintable() const;
71
79 virtual const std::string& getPrintTemplate() const;
80
90 virtual std::string getPrintablePrimitiveOperandType(
91 const uint64_t& opIdx) const;
92
93 protected:
103 Instruction(std::string printTemplate);
104
110 std::string printTemplate;
111
112 private:
144 inline static const std::string GET_PRINT_PRIMITIVE_OPERAND_TYPE{
145 "(const )?((struct )?[\\w:\\*]*)[ ]?(\\[(\\d)+\\])*"};
146
147#endif // CODE_GENERATION
148
149 public:
151 virtual ~Instruction() = default;
152
159 const std::vector<std::reference_wrapper<const std::type_info>>&
160 getOperandTypes() const;
161
169 unsigned int getNbOperands() const;
170
178 virtual bool checkOperandTypes(
179 const std::vector<Data::UntypedSharedPtr>& arguments) const;
180
194 virtual double execute(
195 const std::vector<Data::UntypedSharedPtr>& args) const = 0;
196
197 protected:
198#ifndef CODE_GENERATION
205 Instruction();
206#endif // CODE_GENERATION
211 std::vector<std::reference_wrapper<const std::type_info>> operandTypes;
212 };
213
214} // namespace Instructions
215#endif
This abstract class is the base class for any instruction to be used in a Program.
Definition: instruction.h:59
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:56
unsigned int getNbOperands() const
Get the number of operands required to execute the Instruction.
Definition: instruction.cpp:61
virtual std::string getPrintablePrimitiveOperandType(const uint64_t &opIdx) const
Retrieve the primitive data type of the operand.
Definition: instruction.cpp:113
virtual double execute(const std::vector< Data::UntypedSharedPtr > &args) const =0
Execute the Instruction for the given arguments.
Definition: instruction.cpp:81
Instruction(std::string printTemplate)
Protected constructor to force the class abstract nature.
Definition: instruction.cpp:98
virtual const std::string & getPrintTemplate() const
This function return the printTemplate of the line of code used to represent the instruction.
Definition: instruction.cpp:108
virtual bool isPrintable() const
function saying if an Instruction can be printed in a C file during the code gen.
Definition: instruction.cpp:103
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:66
virtual ~Instruction()=default
Default virtual destructor for polyphormism.
std::string printTemplate
Definition: instruction.h:110
Definition: addPrimitiveType.h:48