-
Notifications
You must be signed in to change notification settings - Fork 2
/
ast_jump_statement.cpp
39 lines (35 loc) · 1.34 KB
/
ast_jump_statement.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
#include "ast/ast_jump_statement.hpp"
// Return will contain a single node
JumpStatement::JumpStatement(JumpType _statement_type, BaseExpression* _expression)
: statement_type(_statement_type), expression(_expression) {}
JumpStatement::~JumpStatement() {
if (expression){
delete expression;
}
}
// compile value of expression into correct register AO = 10
void JumpStatement::compile(std::ostream& os, Context& context, int destReg) const {
switch (statement_type) {
case JumpType::Return:
if (expression) {
if (context.current_func_type == Specifier::_float || context.current_func_type == Specifier::_double) {
// compile expression into reg fa5
expression->compile(os, context, 47);
} else {
// compile expression into reg a5
expression->compile(os, context, 15);
}
}
os << "j " << context.ret_label << std::endl;
break;
case JumpType::Continue:
os << "j " << context.getCurrentLoopStart() << std::endl;
break;
case JumpType::Break:
os << "j " << context.getCurrentLoopEnd() << std::endl;
break;
default:
// should not be possible to get here
exit(1);
}
}