GEGELATI

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Instructions::Instruction Class Referenceabstract

This abstract class is the base class for any instruction to be used in a Program. More...

`#include <instruction.h>`

Inheritance diagram for Instructions::Instruction:

## Public Member Functions
virtual bool | isPrintable () const
| function saying if an Instruction can be printed in a C file during the code gen.
virtual const std::string & | getPrintTemplate () const
| This function return the printTemplate of the line of code used to represent the instruction.
virtual std::string | getPrintablePrimitiveOperandType (const uint64_t &opIdx) const
| Retrieve the primitive data type of the operand.
virtual | ~Instruction ()=default
| Default virtual destructor for polyphormism.
const std::vector< std::reference_wrapper< const std::type_info > > & | getOperandTypes () const
| Get the list of operand types needed by the Instruction.
unsigned int | getNbOperands () const
| Get the number of operands required to execute the Instruction.
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 operands.
virtual double | execute (const std::vector< Data::UntypedSharedPtr > &args) const =0
| Execute the Instruction for the given arguments.

## Protected Member Functions
| Instruction (std::string printTemplate)
| Protected constructor to force the class abstract nature.

## Protected Attributes
std::string | printTemplate
std::vector< std::reference_wrapper< const std::type_info > > | operandTypes
| List of the types of the operands needed to execute the instruction.

## Detailed Description

This abstract class is the base class for any instruction to be used in a Program.

An Instruction declares a list of operands it needs to be executed. This information will be used to fetch the required operands from any ProgramLine, and to ensure the compatibility of the type of the fetched operands with the instruction before executing it.

## Constructor & Destructor Documentation

## ◆ Instruction()

Instruction::Instruction | ( | std::string | printTemplate | ) |
| protected

Protected constructor to force the class abstract nature.

The definition of this constructor initialize the string printTemplate with the format given as parameter.

Parameters

  [in] | printTemplate | of the line used to represent the instruction in the C files generated.

## Member Function Documentation

## ◆ checkOperandTypes()

bool Instruction::checkOperandTypes | ( | const std::vector< Data::UntypedSharedPtr > & | arguments | ) | const
| virtual

Check if a given vector contains elements whose types corresponds to the types of the Instruction operands.

Parameters

  [in] | arguments | a const list of shared pointers to any type of object. (not doable at compile time)

Reimplemented in Instructions::LambdaInstruction< First, Rest >.

## ◆ execute()

double Instruction::execute | ( | const std::vector< Data::UntypedSharedPtr > & | args | ) | const
| pure virtual

Execute the Instruction for the given arguments.

Derived class should implement their own behavior for this method. In case of invalid arguments, for type or number or value reason, this method should always return 0.0.

Parameters

  [in] | args | the vector of UntypedSharedPtr passed to the Instruction.

Returns
  the default implementation of the Instruction class returns 0.0 if the given params or arguments are not valid. Otherwise, 1.0 is returned.

Implemented in Instructions::AddPrimitiveType< T >, Instructions::LambdaInstruction< First, Rest >, and Instructions::MultByConstant< T >.

## ◆ getNbOperands()

unsigned int Instructions::Instruction::getNbOperands | ( |  | ) | const

Get the number of operands required to execute the Instruction.

Returns
  an unsigned int value corresponding to the number of operands required by the Instruction.

## ◆ getOperandTypes()

const std::vector< std::reference_wrapper< const std::type_info > > & Instruction::getOperandTypes | ( |  | ) | const

Get the list of operand types needed by the Instruction.

Returns
  a const reference on the list of operand type_info of the Instruction.

## ◆ getPrintablePrimitiveOperandType()

std::string Instruction::getPrintablePrimitiveOperandType | ( | const uint64_t & | opIdx | ) | const
| virtual

Retrieve the primitive data type of the operand.

Parameters

  [in] | opIdx | const uint64_t reference to the index of the operand of the instruction

Returns
  The type of the operand. If the operand is an array return the type of the element of the array.

## ◆ getPrintTemplate()

const std::string & Instruction::getPrintTemplate | ( |  | ) | const
| virtual

This function return the printTemplate of the line of code used to represent the instruction.

Returns
  The printTemplate of the line of code used to represent the instruction in the C program.

## ◆ isPrintable()

bool Instruction::isPrintable | ( |  | ) | const
| virtual

function saying if an Instruction can be printed in a C file during the code gen.

Returns
  true if the printTemplate of the Instruction is not empty, false in other case.

## Member Data Documentation

## ◆ printTemplate

std::string Instructions::Instruction::printTemplate
| protected

printTemplate of the instruction used to generate the code. The result of the function is represented with $0. The first parameter correspond to $1 the second to $2...

The documentation for this class was generated from the following files:

- D:/a/gegelati/gegelati/gegelatilib/include/instructions/instruction.h
- D:/a/gegelati/gegelati/gegelatilib/src/instructions/instruction.cpp