-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
96 lines (90 loc) · 3.35 KB
/
run.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
import os
import time
from cgen_attemp import cgen
from cgen_attemp import CodeGenerator
import symbol_table_creation_attemp
if __name__ == '__main__':
acc = 0
total = 0
for file in os.listdir("phase3_tests/tests"):
CodeGenerator.current_scope = 'root'
symbol_table_creation_attemp.symbol_table_objects.clear()
symbol_table_creation_attemp.class_type_objects.clear()
symbol_table_creation_attemp.function_objects.clear()
symbol_table_creation_attemp.symbol_table.clear()
symbol_table_creation_attemp.class_table.clear()
symbol_table_creation_attemp.function_table.clear()
symbol_table_creation_attemp.stack.clear()
symbol_table_creation_attemp.stack.append('root')
symbol_table_creation_attemp.parent_classes.clear()
symbol_table_creation_attemp.init()
if file.endswith(".d"):
test = file[:-2]
if not('black' in test or 'balck' in test):
continue
# if 'sort' not in test:
# continue
# if 't00' in test:
# continue
# if 'black' not in file:
# continue
total += 1
print('Test_{}: {}'.format(total, file))
with open("phase3_tests/tests/" + file, "r") as f:
decaf = ''.join(f.readlines())
with open("phase3_tests/out/" + test + ".asm", "w") as f:
f.write(cgen(decaf))
asm = "phase3_tests/out/" + test + ".asm"
inp = 'phase3_tests/tests/' + test + '.in'
out = 'phase3_tests/tests/' + test + '.out'
if not os.path.exists(inp):
inp = 'phase3_tests/tests/heapsort.in'
os.system('spim -a -f "{}" < {} > "tmp"'.format(asm, inp))
# print(os.system('diff {} tmp'.format(out)))
with open("tmp", "r") as f:
f.readline()
f.readline()
f.readline()
f.readline()
f.readline()
res = ''.join(f.readlines())
try:
with open(out) as f:
# f.readline()
# f.readline()
# f.readline()
# f.readline()
# f.readline()
cor = ''.join(f.readlines())
except:
cor = ''
# print(out)
# print(res)
# print()
# print(cor)
print('_'*10)
if res == cor:
print('Accepted')
acc += 1
else:
# print(res.count('\n'))
print(out)
print('your output:\n')
print(res)
print('_'*10)
print('judge output:\n')
print(cor)
# print(cor.count('\n'))
print('Wrong')
# res = res.split('\n')
# cor = cor.split('\n')
# # print(len(res), len(cor))
# for i in range(len(res)):
# if(res[i] != cor[i]):
# print(res[i], cor[i])
# print(len(res[i]), len(cor[i]))
# print('_')
input()
# exit(0)
# time.sleep(1)
print('Passed {} from {} tests'.format(acc, total))