-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
49 lines (45 loc) · 1.5 KB
/
main.cpp
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
#include "TYPE.h"
#include "WordAnalysis/WordAnalysis.h"
#include "SyntaxAnalysis/SyntaxAnalysis.h"
using namespace std;
int main() {
ifstream inputCode;
inputCode.open("testfile.txt");
ofstream outputCode;
outputCode.open("mips.txt");
WordAnalysis wordAnalysis(inputCode);
SyntaxAnalysis syntaxAnalysis(wordAnalysis.getWords(), outputCode);
string midCode = symbolTable.toString();
cout << midCode;
string optim_mipsCode = symbolTable.Optim_MidCode_And_Prepare_Mips();
outputCode << ".data\n";
for (Variable v : globalStrings) {
string str = "";
for (char c : v.string_var) {
if (c == '\\') str += '\\';
str += c;
}
outputCode << "\t" + v.VariableName + ": .asciiz " + "\"" + str + "\"\n";
}
outputCode << ".text\n";
outputCode << "jal main\nli $v0, 10\nsyscall\n";
outputCode << optim_mipsCode;
ofstream outputCode1;
outputCode1.open("mips1.txt");
stringstream mips_with_tmp;
string mipsCode = symbolTable.toMips();
mips_with_tmp << ".data\n";
for (Variable v : globalStrings) {
string str = "";
for (char c : v.string_var) {
if (c == '\\') str += '\\';
str += c;
}
mips_with_tmp << "\t" + v.VariableName + ": .asciiz " + "\"" + str + "\"\n";
}
mips_with_tmp << ".text\n";
mips_with_tmp << "jal main\nli $v0, 10\nsyscall\n";
mips_with_tmp << mipsCode;
selectTempRegister(mips_with_tmp, outputCode1);
return 0;
}