-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.h
More file actions
69 lines (43 loc) · 1.38 KB
/
memory.h
File metadata and controls
69 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Created by erthax on 14.01.2021.
//
#ifndef CULTIVATED_COMPILER_MEMORY_H
#define CULTIVATED_COMPILER_MEMORY_H
#include <string>
#include <map>
#include <utility>
#include "variable.h"
class Register {
public:
explicit Register(std::string tName) : name(std::move(tName)) { this->full = false; }
void freeRegister() { this->full = false; }
void fillRegister() { this->full = true; }
std::string getName() { return this->name; }
bool isFull() const { return full; }
void setName(const std::string &tName) { Register::name = tName; }
void setFull(bool tFull) { this->full = tFull; }
private:
std::string name;
bool full = false;
};
class Memory {
public:
Memory();
Variable *getVariable(std::string tVarName);
void checkIfDeclared(std::string tVarName);
void declareVariable(std::string pid);
void declareArray(std::string pid, uint start, uint end);
void declareConstant(std::string tPid, uint value);
void declareIterator(std::string tPid);
void eraseIterator(std::string tPid);
Variable* getIterator(std::string tPid);
void freeRegisters();
Register *getFreeRegister();
uint iteratorCount{0};
private:
void createRegisters();
std::map<std::string, Register *> registers;
uint memoryAddresses{0};
std::map<std::string, Variable *> symbolTable;
};
#endif //CULTIVATED_COMPILER_MEMORY_H