GEGELATI
line.h
1
37#ifndef LINE_H
38#define LINE_H
39
40#include "environment.h"
41#include <cstring>
42
43namespace Program {
47 class Line
48 {
49
50 protected:
53
56
60
63 std::pair<uint64_t, uint64_t>* const operands;
64
66 Line() = delete;
67
68 public:
77 Line(const Environment& env)
79 operands{(std::pair<uint64_t, uint64_t>*)calloc(
80 env.getMaxNbOperands(),
81 sizeof(std::pair<uint64_t, uint64_t>))} {};
82
91 Line(const Line& other)
92 : environment{other.environment},
95 operands{(std::pair<uint64_t, uint64_t>*)calloc(
96 other.environment.getMaxNbOperands(),
97 sizeof(std::pair<uint64_t, uint64_t>))}
98 {
99 // Check needed to avoid compilation warnings
100 if (this->operands != NULL) {
101 // Copy operand values
102 for (auto idx = 0; idx < this->environment.getMaxNbOperands();
103 idx++) {
104 this->operands[idx] = other.operands[idx];
105 }
106 }
107 };
108
115 Line& operator=(const Line& other) = delete;
116
123 {
124 free((void*)this->operands);
125 }
126
132 const Environment& getEnvironment() const;
133
139 uint64_t getDestinationIndex() const;
140
155 bool setDestinationIndex(const uint64_t dest, const bool check = true);
156
162 uint64_t getInstructionIndex() const;
163
178 bool setInstructionIndex(const uint64_t instr, const bool check = true);
179
189 const std::pair<uint64_t, uint64_t>& getOperand(
190 const uint64_t idx) const;
191
216 bool setOperand(const uint64_t idx, const uint64_t dataIndex,
217 const uint64_t location, const bool check = true);
218
226 bool operator==(const Line& other) const;
227
231 bool operator!=(const Line& other) const;
232 };
233}; // namespace Program
234
235#endif
The Environment class contains all information needed to execute a Program.
Definition: environment.h:84
size_t getMaxNbOperands() const
Get the size of the maximum number of operands of Instructions::Set.
Definition: environment.cpp:182
Definition: line.h:48
uint64_t destinationIndex
Definition: line.h:59
const Environment & getEnvironment() const
Get the environment within which the Line was created.
Definition: line.cpp:42
Line()=delete
Delete the default constructor.
std::pair< uint64_t, uint64_t > *const operands
Definition: line.h:63
const Environment & environment
Environment within which the Program will be executed.
Definition: line.h:52
bool setOperand(const uint64_t idx, const uint64_t dataIndex, const uint64_t location, const bool check=true)
Setter for the operands of this Line.
Definition: line.cpp:85
Line(const Line &other)
Copy constructor of a Line performing a deep copy.
Definition: line.h:91
~Line()
Definition: line.h:122
bool operator!=(const Line &other) const
Opposite of the operator==.
Definition: line.cpp:128
bool operator==(const Line &other) const
Comparison operator between Line.
Definition: line.cpp:109
uint64_t instructionIndex
index of the Instruction of the Set of the Environment.
Definition: line.h:55
uint64_t getInstructionIndex() const
Getter for the instructionIndex of this Line.
Definition: line.cpp:61
bool setInstructionIndex(const uint64_t instr, const bool check=true)
Setter for the instructionIndex of this Line.
Definition: line.cpp:66
Line(const Environment &env)
Constructor for a Line of a program.
Definition: line.h:77
bool setDestinationIndex(const uint64_t dest, const bool check=true)
Setter for the destinationIndex of this Line.
Definition: line.cpp:52
uint64_t getDestinationIndex() const
Getter for the destinationIndex of this Line.
Definition: line.cpp:47
Line & operator=(const Line &other)=delete
const std::pair< uint64_t, uint64_t > & getOperand(const uint64_t idx) const
Getter for the operands of this Line.
Definition: line.cpp:75
Definition: line.h:43