Skip to content

Commit fc24c8b

Browse files
committed
final commit
1 parent 56eed97 commit fc24c8b

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/codegen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,6 @@ def op_if_not_zero_goto(self, instruction):
10951095
def op_goto(self, instruction):
10961096
self.emit_code("jmp", self.create_label(instruction[1]))
10971097

1098-
# Is function mein bahut saara code redundant hai within the if condisiton, and I think wo saari out of the if
10991098
def op_comparator(self, instruction):
11001099
"""
11011100
This function is currently only implemented

src/three_address_code.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
###############
2-
# Delete all coments
3-
###############
4-
5-
61
import copy
72

83

94
class three_address_code:
105
def __init__(self):
11-
self.code = [] # yaha bas statement seq upar neeche kari
6+
self.code = []
127
self.float_values = []
138
self.string_list = []
149
self.global_variables = []
@@ -29,7 +24,7 @@ def create_temp_var(self):
2924
temp_name = "$temp_var_" + str(self.counter_temp)
3025
return temp_name
3126

32-
def backpatch(self, p_list, lno): # changes here, added 3 variables
27+
def backpatch(self, p_list, lno):
3328
updated_lno = lno + 1
3429
for i in p_list:
3530
compare_str = "goto"
@@ -49,15 +44,15 @@ def emit(self, operator, destination, operand_1=None, operand_2=None):
4944
def find_symbol_in_symtab(self, symtab, identifier):
5045
if identifier is not None:
5146
found, entry = symtab.return_sym_tab_entry(identifier)
52-
compare_str = "temp" # replaced string and list with vars
47+
compare_str = "temp"
5348
to_check_list = found.keys()
5449
if compare_str in to_check_list:
5550
return found["temp"]
5651
else:
5752
new_temp = self.create_temp_var()
58-
symtab.modify_symbol(identifier, compare_str, new_temp) # here too
53+
symtab.modify_symbol(identifier, compare_str, new_temp)
5954
return new_temp
60-
return None # if-else, order changed and else removed
55+
return None
6156

6257
def print_code(self):
6358

@@ -71,23 +66,23 @@ def print_code(self):
7166
self.emit(f".comm", "", str(val[0]) + "," + str(val[1]), "")
7267
self.emit(".data", "", "", "")
7368

74-
deleted = 0 # changed ordering
69+
deleted = 0
7570
lines_dict = dict()
7671
temp_code = copy.deepcopy(self.code)
77-
check_ran = range(0, len(temp_code)) # added extra var
72+
check_ran = range(0, len(temp_code))
7873
self.code = []
7974
for i in check_ran:
8075
code = temp_code[i]
8176
lines_dict[i + 1] = i - deleted + 1
82-
compare_str = "goto" # replaced string and list with vars
77+
compare_str = "goto"
8378
compare_str_2 = "retq"
8479
to_check_list = code[0].split()
8580
to_check_list_2 = temp_code[i - 1][0].split()
8681
if compare_str in to_check_list:
8782
if code[1] == "" or code[1] == None:
8883
deleted = deleted + 1
8984
else:
90-
self.code.append(code) #### kaafi changes here
85+
self.code.append(code)
9186
elif compare_str_2 in to_check_list and (
9287
compare_str_2 in to_check_list_2 or "retq_struct" in to_check_list_2
9388
):
@@ -98,7 +93,7 @@ def print_code(self):
9893
for i in check_ran:
9994
code = self.code[i]
10095
compare_str = "goto"
101-
if compare_str in code[0].split(): # changess
96+
if compare_str in code[0].split():
10297
spec_elem = self.code[i][1]
10398
self.code[i][1] = lines_dict[spec_elem]
10499
check_ran = range(0, len(self.code))
@@ -117,16 +112,16 @@ def print_code(self):
117112
):
118113
check_ran = reversed(range(i))
119114
for j in check_ran:
120-
prev_code = self.code[j] # many changess variables added
115+
prev_code = self.code[j]
121116
check_code = "UNARY&"
122117
if len(prev_code[0]) <= 0:
123118
break
124119
elif prev_code[0] == check_code:
125-
self.code[j + 1] = prev_code # changed sequence
120+
self.code[j + 1] = prev_code
126121
self.code[j] = code
127122
break
128123
else:
129-
self.code[j + 1] = prev_code # changed sequence
124+
self.code[j + 1] = prev_code
130125
self.code[j] = code
131126
check_ran = range(0, len(self.code))
132127
for i in check_ran:

0 commit comments

Comments
 (0)