-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3ac_prog.cpp
62 lines (51 loc) · 1.27 KB
/
3ac_prog.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
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "3ac.hpp"
#include "vector"
#include "type_analysis.hpp"
namespace holeyc {
Procedure * IRProgram::makeProc(std::string name){
Procedure * proc = new Procedure(this, name);
procs.push_back(proc);
return proc;
}
OpdWidth IRProgram::opWidth(ASTNode * node){
return Opd::width(ta->nodeType(node));
}
Label * IRProgram::makeLabel(){
Label * label = new Label(std::to_string(max_label++));
return label;
}
SymOpd * IRProgram::getGlobal(SemSymbol * sym){
if (globals.find(sym) != globals.end()){
return globals[sym];
}
return nullptr;
}
void IRProgram::gatherGlobal(SemSymbol * sym){
OpdWidth width = Opd::width(sym->getDataType());
SymOpd * res = new SymOpd(sym, width);
globals[sym] = res;
}
Opd * IRProgram::makeString(std::string val){
std::string name = "str_" + std::to_string(str_idx++);
AuxOpd * opd = new AuxOpd(name, ADDR);
strings[opd] = val;
return opd;
}
std::string IRProgram::toString(bool verbose){
std::string res = "";
res += "[BEGIN GLOBALS]\n";
for (auto entry : globals){
res += entry.second->getName() + "\n";
}
for (auto entry : strings){
res += entry.first->locString();
res += " " + entry.second;
res += "\n";
}
res += "[END GLOBALS]\n";
for (Procedure * proc : procs){
res += proc->toString(verbose);
}
return res;
}
}