GEGELATI
Loading...
Searching...
No Matches
line.h
1
38#ifndef LINE_H
39#define LINE_H
40
41#include "environment.h"
42#include <cstring>
43
44namespace Program {
48 class Line
49 {
50
51 protected:
54
57
61
64 std::pair<uint64_t, uint64_t>* const operands;
65
67 Line() = delete;
68
69 public:
78 Line(const Environment& env)
80 operands{(std::pair<uint64_t, uint64_t>*)calloc(
81 env.getMaxNbOperands(),
82 sizeof(std::pair<uint64_t, uint64_t>))} {};
83
92 Line(const Line& other)
93 : environment{other.environment},
96 operands{(std::pair<uint64_t, uint64_t>*)calloc(
97 other.environment.getMaxNbOperands(),
98 sizeof(std::pair<uint64_t, uint64_t>))}
99 {
100 // Check needed to avoid compilation warnings
101 if (this->operands != NULL) {
102 // Copy operand values
103 for (auto idx = 0; idx < this->environment.getMaxNbOperands();
104 idx++) {
105 this->operands[idx] = other.operands[idx];
106 }
107 }
108 };
109
116 Line& operator=(const Line& other) = delete;
117
124 {
125 free((void*)this->operands);
126 }
127
133 const Environment& getEnvironment() const;
134
140 uint64_t getDestinationIndex() const;
141
156 bool setDestinationIndex(const uint64_t dest, const bool check = true);
157
163 uint64_t getInstructionIndex() const;
164
179 bool setInstructionIndex(const uint64_t instr, const bool check = true);
180
190 const std::pair<uint64_t, uint64_t>& getOperand(
191 const uint64_t idx) const;
192
217 bool setOperand(const uint64_t idx, const uint64_t dataIndex,
218 const uint64_t location, const bool check = true);
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:86
size_t getMaxNbOperands() const
Get the size of the maximum number of operands of Instructions::Set.
Definition environment.cpp:183
Definition line.h:49
uint64_t destinationIndex
Definition line.h:60
const Environment & getEnvironment() const
Get the environment within which the Line was created.
Definition line.cpp:43
Line()=delete
Delete the default constructor.
std::pair< uint64_t, uint64_t > *const operands
Definition line.h:64
const Environment & environment
Environment within which the Program will be executed.
Definition line.h:53
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:86
Line(const Line &other)
Copy constructor of a Line performing a deep copy.
Definition line.h:92
~Line()
Definition line.h:123
bool operator!=(const Line &other) const
Opposite of the operator==.
Definition line.cpp:129
bool operator==(const Line &other) const
Comparison operator between Line.
Definition line.cpp:110
uint64_t instructionIndex
index of the Instruction of the Set of the Environment.
Definition line.h:56
uint64_t getInstructionIndex() const
Getter for the instructionIndex of this Line.
Definition line.cpp:62
bool setInstructionIndex(const uint64_t instr, const bool check=true)
Setter for the instructionIndex of this Line.
Definition line.cpp:67
Line(const Environment &env)
Constructor for a Line of a program.
Definition line.h:78
bool setDestinationIndex(const uint64_t dest, const bool check=true)
Setter for the destinationIndex of this Line.
Definition line.cpp:53
uint64_t getDestinationIndex() const
Getter for the destinationIndex of this Line.
Definition line.cpp:48
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:76
Definition line.h:44