-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathblock.cpp
42 lines (37 loc) · 1.2 KB
/
block.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
/**
* Implementation for the block class
*/
#include "block.h"
#include "statements.h"
#include "variableDeclarations.h"
/**
* Default constructor
* @param variable_declarations variable declarations present in the block
* @param statements list of statements present in the block
*/
Block::Block(class variableDeclarations *variable_declarations, class Statements *statements) {
this->stype = stmtType::NonReturn;
this->declarations_list = variable_declarations;
this->statements_list = statements;
}
/**
* Tells whether this block returns a value
* @return True if block returns a value False otherwise
*/
bool Block::has_return() {
return statements_list->has_return();
}
Value *Block::generateCode(Constructs *compilerConstructs) {
Value *V;
std::map<std::string, llvm::AllocaInst *> Old_vals;
V = declarations_list->generateCode(Old_vals, compilerConstructs);
if (V == nullptr) {
return V;
}
V = statements_list->generateCode(compilerConstructs);
/* Adjust the values back to old values */
for (auto it = Old_vals.begin(); it != Old_vals.end(); it++) {
compilerConstructs->NamedValues[it->first] = Old_vals[it->first];
}
return V;
}