-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigs.py
101 lines (80 loc) · 3.02 KB
/
configs.py
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
from enum import Enum
class SK:
# entries ={}
# outerScope = {}
def print_all(self, more_print_line=False):
print()
if more_print_line:
print("===PRINT_ALL>>>===")
for x in self.global_scope:
print("G|" + x + ": " + str(self.global_scope[x]))
if self.local_scope:
print("------------------------------------------------------------")
for x in self.local_scope:
print("L|" + x + ": " + str(self.local_scope[x]))
if more_print_line:
print("===PRINT_ALL<<<===")
def nr_global_vars(self):
return len(self.global_scope)
def __repr__(self):
return (
"global: " + str(self.global_scope) + "\n local: " + str(self.local_scope)
)
def __init__(self) -> None:
self.global_scope = {}
self.local_scope = {}
def lookup(self, var_name):
if var_name in self.local_scope:
return self.local_scope.get(var_name)
return self.global_scope.get(var_name)
def in_globals(self, var_name):
return var_name in self.global_scope
def in_locals(self, var_name):
return var_name in self.local_scope
def reset_locals(self):
self.local_scope = {}
# TODO: refctor to in selfscope
def set_local_var(self, name, info):
if not self.local_scope.get(name):
self.local_scope[name] = info
def set_global_var(self, name, info):
if not self.global_scope.get(name):
self.global_scope[name] = info
def update_global_POS(self, name, position=None):
if not position:
self.global_scope[name]["POS"].append(self.global_scope[name]["POS"][-1] + 1)
else:
raise NotImplemented("def update_global_POS(self,name, position=None):")
def get_global_addr(self, var_name):
entry = self.global_scope.get(var_name)
if not entry:
raise Exception(f"{var_name} not in global!")
return entry["addr"]
def get_local_addr(self, var_name):
entry = self.local_scope.get(var_name)
if not entry:
raise Exception(f"{var_name} not in local!")
return entry["addr"]
def get_local_or_global_addr(self, var_name):
entry = self.local_scope.get(var_name)
if not entry:
entry = self.global_scope.get(var_name)
if not entry:
raise Exception(f"{var_name} not in local and global!")
return entry["addr"]
class Configs(Enum):
GENERATED_DIR = "/Users/dominik/HOME/DEV/Compiler/incc24/dom/arm/generated"
GENERATED_IR_CODE_DIR = (
"/Users/dominik/HOME/DEV/Compiler/incc24/dom/arm/generated/ir_code"
)
CODE_DIR = "/Users/dominik/HOME/DEV/Compiler/incc24/dom/arm/code"
SHOW_IR_IN_ASM = True
ADD_COMMENTS_IR_TO_ARM_EACH_LINE = False
ENV_GLOBAL_NAME = "__global"
ENV_LOCAL_NAME = "__local"
# ENV = {}
# ENV[ENV_GLOBAL_NAME] = {}
# ENV[ENV_LOCAL_NAME] = {}
ENV_SYMBOL_TABLE = SK()
ENV = SK()
STACK_SIZE_ARM = 16