blob: 28bd9816c9372475f16c01f6c37d967e51c6262b (
plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
#include "ast.hpp"
// General base Statement definition
Statement::Statement(Statement* statement)
: next_statement(statement) {}
void Statement::print() const
{
if(next_statement != nullptr)
next_statement->print();
}
void Statement::printxml() const
{
if(next_statement != nullptr)
next_statement->printxml();
}
void Statement::printasm() const
{
if(next_statement != nullptr)
next_statement->printasm();
}
// Compound Statement definition
CompoundStatement::CompoundStatement(Declaration* decl, Statement* statement)
: Statement(), m_decl(decl), m_statement(statement) {}
CompoundStatement::CompoundStatement(Statement* statement)
: m_statement(statement) {}
void CompoundStatement::print() const
{
if(m_decl != nullptr)
m_decl->print();
if(m_statement != nullptr)
m_statement->print();
}
void CompoundStatement::printxml() const
{
if(next_statement != nullptr)
next_statement->printxml();
std::cout << "<Scope>" << std::endl;
if(m_decl != nullptr)
m_decl->printxml();
if(m_statement != nullptr)
m_statement->printxml();
std::cout << "</Scope>" << std::endl;
}
void CompoundStatement::printasm() const
{}
// Selection Statement definition
SelectionStatement::SelectionStatement(Statement* _if, Statement* _else)
: Statement(), m_if(_if), m_else(_else) {}
void SelectionStatement::print() const
{
m_if->print();
m_else->print();
}
void SelectionStatement::printxml() const
{
if(next_statement != nullptr)
next_statement->printxml();
if(m_if != nullptr)
m_if->printxml();
if(m_else != nullptr)
m_else->printxml();
}
void SelectionStatement::printasm() const
{}
// Expression Statement definition
ExpressionStatement::ExpressionStatement(Expression* expr)
: Statement(), m_expr(expr) {}
void ExpressionStatement::print() const
{}
void ExpressionStatement::printxml() const
{}
void ExpressionStatement::printasm() const
{}
// Jump Statement definition
JumpStatement::JumpStatement(Expression* expr)
: m_expr(expr) {}
void JumpStatement::print() const
{}
void JumpStatement::printxml() const
{
if(next_statement != nullptr)
next_statement->printxml();
}
void JumpStatement::printasm() const
{
m_expr->printasm();
std::cout << "\tlw\t$2,8($fp)" << std::endl;
}
// Iteration Statement definition
IterationStatement::IterationStatement(Statement* statement)
: m_statement(statement) {}
void IterationStatement::print() const
{}
void IterationStatement::printxml() const
{
if(next_statement != nullptr)
next_statement->printxml();
if(m_statement != nullptr)
m_statement->printxml();
}
void IterationStatement::printasm() const
{}
|