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
44 namespace Program {
48 class Line
49 {
50
51 protected:
53 const Environment& environment;
54
56 uint64_t instructionIndex;
57
60 uint64_t destinationIndex;
61
64 std::pair<uint64_t, uint64_t>* const operands;
65
67 Line() = delete;
68
69 public:
78 Line(const Environment& env)
79 : environment{env}, instructionIndex{0}, destinationIndex{0},
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},
94 instructionIndex{other.instructionIndex},
95 destinationIndex{other.destinationIndex},
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
123 ~Line()
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
Environment
The Environment class contains all information needed to execute a Program.
Definition environment.h:86
Environment::getMaxNbOperands
size_t getMaxNbOperands() const
Get the size of the maximum number of operands of Instructions::Set.
Definition environment.cpp:183
Program::Line
Definition line.h:49
Program::Line::destinationIndex
uint64_t destinationIndex
Definition line.h:60
Program::Line::getEnvironment
const Environment & getEnvironment() const
Get the environment within which the Line was created.
Definition line.cpp:43
Program::Line::Line
Line()=delete
Delete the default constructor.
Program::Line::operands
std::pair< uint64_t, uint64_t > *const operands
Definition line.h:64
Program::Line::environment
const Environment & environment
Environment within which the Program will be executed.
Definition line.h:53
Program::Line::setOperand
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
Program::Line::Line
Line(const Line &other)
Copy constructor of a Line performing a deep copy.
Definition line.h:92
Program::Line::~Line
~Line()
Definition line.h:123
Program::Line::operator!=
bool operator!=(const Line &other) const
Opposite of the operator==.
Definition line.cpp:129
Program::Line::operator==
bool operator==(const Line &other) const
Comparison operator between Line.
Definition line.cpp:110
Program::Line::instructionIndex
uint64_t instructionIndex
index of the Instruction of the Set of the Environment.
Definition line.h:56
Program::Line::getInstructionIndex
uint64_t getInstructionIndex() const
Getter for the instructionIndex of this Line.
Definition line.cpp:62
Program::Line::setInstructionIndex
bool setInstructionIndex(const uint64_t instr, const bool check=true)
Setter for the instructionIndex of this Line.
Definition line.cpp:67
Program::Line::Line
Line(const Environment &env)
Constructor for a Line of a program.
Definition line.h:78
Program::Line::setDestinationIndex
bool setDestinationIndex(const uint64_t dest, const bool check=true)
Setter for the destinationIndex of this Line.
Definition line.cpp:53
Program::Line::getDestinationIndex
uint64_t getDestinationIndex() const
Getter for the destinationIndex of this Line.
Definition line.cpp:48
Program::Line::operator=
Line & operator=(const Line &other)=delete
Program::Line::getOperand
const std::pair< uint64_t, uint64_t > & getOperand(const uint64_t idx) const
Getter for the operands of this Line.
Definition line.cpp:76
Program
Definition line.h:44