-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTac.cpp
80 lines (64 loc) · 2.21 KB
/
Tac.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Tac.hpp"
#include "BytecodeMethodBlock.hpp"
#include <iostream>
void Tac::print(std::ostream &os) const {
os << result << " := " << lhs << " " << op << " " << rhs << "\n";
}
void NotTac::print(std::ostream &os) const {
os << result << " := ! " << rhs << "\n";
}
void CopyTac::print(std::ostream &os) const {
os << result << " := " << rhs << "\n";
}
void CopyTac::generateBytecode(BytecodeMethodBlock &block) {
block.push(rhsOp).store(result);
}
void ArrayCopyTac::print(std::ostream &os) const {
os << result << "[" << lhs << "]"
<< " := " << rhs << "\n";
}
void ArrayAccessTac::print(std::ostream &os) const {
os << result << " := " << lhs << "[" << rhs << "]\n";
}
void ArrayLengthTac::print(std::ostream &os) const {
os << result << " := length " << rhs << "\n";
}
void NewTac::print(std::ostream &os) const {
os << result << " := new " << rhs << "\n";
}
void NewArrayTac::print(std::ostream &os) const {
os << result << " := new int, " << rhs << "\n";
}
void JumpTac::print(std::ostream &os) const { os << "goto " << result << "\n"; }
void JumpTac::generateBytecode(BytecodeMethodBlock &block) {
block.jump(result);
}
void CondJumpTac::print(std::ostream &os) const {
os << "iffalse " << lhs << " goto " << rhs << "\n";
}
void CondJumpTac::generateBytecode(BytecodeMethodBlock &block) {
block.push(lhs).cjump(rhs);
}
void MethodCallTac::print(std::ostream &os) const {
os << result << " := call " << lhs << ", " << rhs << "\n";
}
void MethodCallTac::generateBytecode(BytecodeMethodBlock &block) {
block.call(lhs + "." + op).store(result);
}
void ParamTac::print(std::ostream &os) const { os << "param " << rhs << "\n"; }
void ParamTac::generateBytecode(BytecodeMethodBlock &block) {
block.push(rhsOp);
}
void ReturnTac::print(std::ostream &os) const {
os << "return " << rhs << "\n";
}
void ReturnTac::generateBytecode(BytecodeMethodBlock &block) {
block.push(rhsOp).ret();
}
void PrintTac::print(std::ostream &os) const { os << "print " << rhs << "\n"; }
void PrintTac::generateBytecode(BytecodeMethodBlock &block) {
block.push(rhsOp).write();
}
void NotTac::generateBytecode(BytecodeMethodBlock &block) {
block.push(rhsOp).l_not().store(result);
}