Fixed issue with return address in cpu_sim.py. Fixed bugs in compiler generation...
[trinary.git] / extended / Records.py
blobaa6142aead03692ff62004d82154f7d238988007
2 import sys
3 import Node
5 class Records(object):
7 def __init__(self):
8 self.global_table = {}
9 self.local_table = {}
10 self.counter = 0
11 self.label_counter = 0
12 self.start_node = Node()
13 self.end_node = Node()
14 self.crnt_node = self.start_node
16 # counter access functions
17 def increment_counter(self):
18 self.counter = self.counter + 1
20 def reset_counter(self):
21 self.counter = 0
23 def get_counter(self):
24 return self.counter
26 def increment_label_counter(self):
27 self.label_counter = self.label_counter + 1
29 def get_label_counter(self):
30 return self.label_counter
32 # add to table functions
33 def add_to_global(self, key, value):
34 if key in self.global_table:
35 return False
36 self.global_table[key] = value
37 return True
39 def add_to_local(self, key, value):
40 return self.crnt_function.add_to_members(key, value)
42 # set local table
43 def set_local(self, function):
44 self.local_table = function.get_table()
45 self.crnt_function = function
47 # return the value of 'key' (if present) from the tables
48 def get_value(self, key, structure = False):
50 # find in structure
51 if structure != False and key in structure.in_members(key):
52 return structure.get_member(key)
54 # find in local table
55 elif key in self.local_table:
56 return self.local_table[key]
58 # find in global table
59 elif key in self.global_table:
60 return self.global_table[key]
62 else:
63 print "id '" + key + "' not defined"
64 raise SystemExit
66 def in_local(self, key):
67 if key in self.local_table:
68 return True
69 else:
70 return False
72 def in_global(self, key):
73 if key in self.global_table:
74 return True
75 else:
76 return False
78 # Function return value access functions
79 def get_func_ret(self):
80 return self.function_return_type
82 def set_func_ret(self, rtn_type):
83 self.fuction_return_type = rtn_type
85 # Number of parameters access functions
86 def set_num_params(self, num_params):
87 self.crnt_function.set_num_params(num_params)
89 def get_num_params(self):
90 return self.crnt_fuctions.get_num_params()
92 # current node access methods
93 def set_crnt_node(self, node):
94 self.crnt_node = node
96 def get_crnt_node(self):
97 return self.crnt_node
99 def get_start_node(self):
100 return self.start_node
102 def get_end_node(self):
103 return self.end_node