blob: 80375e767b0bb2a7bfa66dd1b9738847f70520b8 (
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
|
#include "bindings.hpp"
#include <iostream>
// VariableStackBindings definition
VariableStackBindings::VariableStackBindings()
: stack_counter(4), current_register(2)
{}
void VariableStackBindings::insertBinding(std::string id, TypePtr type, int32_t stack_position)
{
DeclarationData decl_data;
decl_data.type = type;
decl_data.stack_position = stack_position;
bindings.insert(std::pair<std::string, DeclarationData>(id, decl_data));
}
void VariableStackBindings::increaseStackPosition()
{
stack_counter += 4;
}
void VariableStackBindings::resetRegister()
{
current_register = 2;
}
void VariableStackBindings::increaseRegister()
{
if(current_register == 15)
current_register = 24;
else if(current_register == 25)
std::cerr << "Error : cannot allocate more registers" << std::endl;
else
current_register++;
}
int32_t VariableStackBindings::getCurrentStackPosition() const
{
return stack_counter;
}
int32_t VariableStackBindings::getStackPosition(const std::string &id) const
{
auto binding = bindings.find(id);
if(binding != bindings.end())
return (*binding).second.stack_position;
else return 0;
}
int8_t VariableStackBindings::getCurrentRegister() const
{
return current_register;
}
bool VariableStackBindings::bindingExists(const std::string &id) const
{
auto binding = bindings.find(id);
if(binding == bindings.end())
return false;
else
return true;
}
|