-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecl.cpp
35 lines (29 loc) · 810 Bytes
/
Decl.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
#include "Decl.hpp"
#include "asm.hpp"
PrintDecl::PrintDecl(const Expr* exp) {
this->addExpr(exp);
}
void PrintDecl::addExpr(const Expr* exp) {
_exprs.emplace_back(exp);
}
void PrintDecl::eval(std::ostream& out) const {
out << "# Begin print" << std::endl;
i32_t val;
std::string ident;
for (auto& exp : _exprs) {
if (exp->cte(&val)) {
gas::push(out, val);
gas::call(out, "_print_int");
} else if (exp->cte(&ident)) {
gas::push(out, ident);
gas::call(out, "_print_str");
} else {
exp->eval(out);
gas::push(out, E_AX);
gas::call(out, "_print_int");
}
gas::add(out, 4, P_STACK);
}
gas::call(out, "_print_ln");
out << "# End print" << std::endl;
}