-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_writer.h
More file actions
79 lines (48 loc) · 1.9 KB
/
Copy pathcode_writer.h
File metadata and controls
79 lines (48 loc) · 1.9 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
70
71
72
73
74
75
76
77
78
79
//
// Created by erthax on 15.01.2021.
//
#ifndef CULTIVATED_COMPILER_CODE_WRITER_H
#define CULTIVATED_COMPILER_CODE_WRITER_H
#include <string>
#include <vector>
#include <fstream>
class Instruction {
public:
Instruction(std::string tOrder) : order(tOrder), RegName1(""), RegName2("") {}
Instruction(std::string tOrder, std::string tRegName) : order(tOrder), RegName1(tRegName), RegName2("") {}
Instruction(std::string tOrder, std::string tRegName1, std::string tRegName2) : order(tOrder), RegName1(tRegName1),
RegName2(tRegName2) {}
std::string to_string() { return this->order + " " + this->RegName1 + " " + this->RegName2; }
private:
std::string order;
std::string RegName1;
std::string RegName2;
};
class CodeWriter {
public:
CodeWriter() = default;;
void writeOutput(const std::string& tFileName);
void loadNumberToRegister(std::string tRegisterName, uint value);
void putInstructionAtIndex(Instruction* instruction, uint index);
void get(std::string tRegName);
void put(std::string tRegName);
void load(std::string tRegName1, std::string tRegName2);
void store(std::string tRegName1, std::string tRegName2);
void add(std::string tRegName1, std::string tRegName2);
void sub(std::string tRegName1, std::string tRegName2);
void reset(std::string tRegName);
void inc(std::string tRegName);
void dec(std::string tRegName);
void shr(std::string tRegName);
void shl(std::string tRegName);
void jump(int j);
void jzero(std::string tRegName, int j);
void jodd(std::string tRegName, int j);
void halt();
uint getInstructionCount() const;
void setInstructionCount(uint instructionCount);
private:
std::vector<Instruction *> instructionList;
uint instructionCount{0};
};
#endif //CULTIVATED_COMPILER_CODE_WRITER_H