GEGELATI
environment.h
1
37#ifndef ENVIRONMENT_H
38#define ENVIRONMENT_H
39
40#include <cmath>
41#include <iostream>
42
43#include "data/constantHandler.h"
44#include "data/dataHandler.h"
45#include "data/primitiveTypeArray.h"
46#include "instructions/instruction.h"
47#include "instructions/set.h"
48
50typedef struct LineSize
51{
64
66 operator size_t() const
67 {
68 return totalNbBits;
69 }
70} LineSize;
71
84{
85 protected:
88
90 const std::vector<std::reference_wrapper<const Data::DataHandler>>
92
94 const size_t nbRegisters;
95
97 const size_t nbConstants;
98
100 std::vector<std::reference_wrapper<const Data::DataHandler>>
102
105
108
110 const size_t nbInstructions;
111
113 const size_t maxNbOperands;
114
116 const size_t nbDataSources;
117
120
123
134 static size_t computeLargestAddressSpace(
135 const size_t nbRegisters, const size_t nbConstants,
136 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
137 dHandlers);
138
157 static const LineSize computeLineSize(const Environment& env);
158
171 const Instructions::Set& iSet, const size_t nbRegisters,
172 const size_t nbConstants,
173 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
175
176 private:
178 Environment() = delete;
179
180 public:
196 const Instructions::Set& iSet,
197 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
198 dHandlers,
199 const size_t nbRegs, const size_t nbConst = 0)
200 : instructionSet{filterInstructionSet(iSet, nbRegs, nbConst,
201 dHandlers)},
202 dataSources{dHandlers}, nbRegisters{nbRegs}, nbConstants{nbConst},
203 fakeRegisters(nbRegs), fakeConstants(nbConst),
207 dHandlers.size() +
208 (nbConst > 0 ? 2
209 : 1)}, // if Constants are used, we need an extra
210 // datasource to store them in the environment
212 computeLargestAddressSpace(nbRegs, nbConst, dHandlers)},
214 {
215 this->fakeDataSources.push_back(
216 (std::reference_wrapper<const Data::DataHandler>)this
217 ->fakeRegisters);
218
219 if (nbConst > 0) {
220 this->fakeDataSources.push_back(this->fakeConstants);
221 }
222
223 for (auto& elem : this->dataSources)
224 this->fakeDataSources.push_back(elem);
225 };
226
232 size_t getNbRegisters() const;
233
239 size_t getNbConstant() const;
240
247 size_t getNbInstructions() const;
248
255 size_t getMaxNbOperands() const;
256
262 size_t getNbDataSources() const;
263
269 size_t getLargestAddressSpace() const;
270
276 const LineSize& getLineSize() const;
277
284 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
285 getDataSources() const;
286
295 const std::vector<std::reference_wrapper<const Data::DataHandler>>&
296 getFakeDataSources() const;
297
305};
306
307#endif
Data::DataHandler used by Program::Program to handle their set of Constant values.
Definition: constantHandler.h:56
The Environment class contains all information needed to execute a Program.
Definition: environment.h:84
const std::vector< std::reference_wrapper< const Data::DataHandler > > & getDataSources() const
Get the DataHandler of the Environment.
Definition: environment.cpp:203
const Data::PrimitiveTypeArray< double > fakeRegisters
DataHandler whost type corresponds to registers.
Definition: environment.h:104
size_t getLargestAddressSpace() const
Get the size of the largestAddressSpace of DataHandlers.
Definition: environment.cpp:192
Environment(const Instructions::Set &iSet, const std::vector< std::reference_wrapper< const Data::DataHandler > > &dHandlers, const size_t nbRegs, const size_t nbConst=0)
Constructor with initialization of all attributes.
Definition: environment.h:195
const LineSize & getLineSize() const
Get the size of the line for this environment (in bits).
Definition: environment.cpp:197
const Data::ConstantHandler fakeConstants
DataHandler whost type corresponds to the programs constants.
Definition: environment.h:107
const LineSize lineSize
Size of lines within this Environment.
Definition: environment.h:122
const std::vector< std::reference_wrapper< const Data::DataHandler > > dataSources
List of DataHandler that can be accessed within this Environment.
Definition: environment.h:91
size_t getNbInstructions() const
Get the size of the number of Instruction within the Instructions::Set.
Definition: environment.cpp:177
const size_t nbRegisters
Number of registers.
Definition: environment.h:94
std::vector< std::reference_wrapper< const Data::DataHandler > > fakeDataSources
Vector of DataHandlers containing the environment's dataSources.
Definition: environment.h:101
size_t getNbConstant() const
Get the number of constants used by programs.
Definition: environment.cpp:172
const size_t maxNbOperands
Maxmimum number of operands of the Instructions::Set.
Definition: environment.h:113
static Instructions::Set filterInstructionSet(const Instructions::Set &iSet, const size_t nbRegisters, const size_t nbConstants, const std::vector< std::reference_wrapper< const Data::DataHandler > > &dataSources)
Filter an InstructionSet to keep only Instruction with operand types provided by the given DataHandle...
Definition: environment.cpp:55
const size_t nbConstants
Number of constants.
Definition: environment.h:97
const std::vector< std::reference_wrapper< const Data::DataHandler > > & getFakeDataSources() const
Definition: environment.cpp:209
size_t getMaxNbOperands() const
Get the size of the maximum number of operands of Instructions::Set.
Definition: environment.cpp:182
const Instructions::Set instructionSet
Set of Instruction used by Program running within this Environment.
Definition: environment.h:87
size_t getNbDataSources() const
Get the size of the number of DataHandlers.
Definition: environment.cpp:187
const size_t nbDataSources
Number of DataHandler from which data can be accessed.
Definition: environment.h:116
const size_t largestAddressSpace
Size of the largestAddressSpace of DataHandlers.
Definition: environment.h:119
const size_t nbInstructions
Number of Instruction in the Instructions::Set.
Definition: environment.h:110
const Instructions::Set & getInstructionSet() const
Get the Instruction Set of the Environment.
Definition: environment.cpp:214
size_t getNbRegisters() const
Get the size of the number of registers of this Environment.
Definition: environment.cpp:167
static const LineSize computeLineSize(const Environment &env)
Static method used to compute the size of Program lines based on information from the Enviroment.
Definition: environment.cpp:124
static size_t computeLargestAddressSpace(const size_t nbRegisters, const size_t nbConstants, const std::vector< std::reference_wrapper< const Data::DataHandler > > &dHandlers)
Static method used when constructing a new Environment to compute the largest AddressSpace of a set o...
Definition: environment.cpp:42
Class for storing a set of Instruction.
Definition: set.h:53
LineSize structure to be used within the Environment.
Definition: environment.h:51
size_t nbInstructionBits
Number of bits used to encode the instructionIndex.
Definition: environment.h:53
size_t nbOperandLocationBits
Number of bits used for each operand pair, to encode location.
Definition: environment.h:61
size_t nbDestinationBits
Number of bits used to encode the destinationIndex.
Definition: environment.h:55
size_t nbOperandsBits
Total number of bits used to encode the operands info.
Definition: environment.h:57
size_t nbOperandDataSourceIndexBits
Number of bits used for each operand pair, to encode dataSourceIndex.
Definition: environment.h:59
size_t totalNbBits
Total number of bits to encode a program line.
Definition: environment.h:63