forked from clothbot/gate-parser
/
full_parser.py
executable file
·130 lines (109 loc) · 3.29 KB
/
full_parser.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/python
# Encapsulation of lexer/parser pair
class PLYPair:
def __init__(self, l=None, p=None):
self.lexer = l
self.parser = p
self.result = None
def set_lexer(self, l):
self.lexer = l
def set_parser(self, p):
self.parser = p
def parse_file(self, fname):
f = open(fname, 'r')
a = f.read()
f.close()
return self.parse(a)
def parse(self, text):
self.result = self.parser.parse(text, lexer=self.lexer)
return self.result
import ply_verilog_netlist
import ply_liberty
import ply_boolean_expressions
from time import time
def prompt(vars=None):
prompt_message = "Brama Front End"
try:
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(argv=[''],banner=prompt_message,exit_msg="Goodbye")
return ipshell
except ImportError:
if vars is None: vars=globals()
import code
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")
# calling this with globals ensures we can see the environment
print prompt_message
shell = code.InteractiveConsole(vars)
return shell.interact
def dict_stats(d):
total = 0
max_len = 0
for k in d:
total += len(d[k])
max_len = max(max_len, len(d[k]))
print "Average Length =", total, "/", len(d), "=", total / float(len(d))
print "Max = ", max_len
if __name__ == "__main__":
# lsi_10k example
print "Parsing Library"
start = time()
lsi_lib = PLYPair()
lsi_lib.set_lexer(ply_liberty.create_lexer())
lsi_lib.set_parser(ply_liberty.create_parser())
lsi_lib.parse_file('Examples/lsi_10k.lib')
total = time() - start
print "Total Time:", total, "s"
# import pdb; pdb.set_trace()
print "Parsing Boolean Expressnions"
start = time()
be = PLYPair()
be.set_lexer(ply_boolean_expressions.create_lexer())
be.set_parser(ply_boolean_expressions.create_parser())
error_count = 0
for g in lsi_lib.result:
g = lsi_lib.result[g]
ply_boolean_expressions.update(g.getPinMap())
for p in g.pins:
if 'function' in g.pins[p]:
g.pins[p]['o_function'] = g.pins[p]['function']
g.pins[p]['function'] = be.parse(g.pins[p]['function'])
for s in g.specials:
s = g.specials[s]
for k in s.getBEatts():
s.atts['o_'+k] = s.atts[k]
s.atts[k] = be.parse(s.atts[k])
print "Total of", error_count, "boolean expression parsing errors"
total = time() - start
print "Total Time:", total, "s"
# import pdb; pdb.set_trace()
print "Parsing CCX"
start = time()
cd = {key : "CELL" for key in lsi_lib.result.keys()}
ccx = PLYPair()
ccx.set_lexer(ply_verilog_netlist.create_lexer(cd))
ccx.set_parser(ply_verilog_netlist.create_parser(lsi_lib.result))
ccx.parse_file('Examples/ccx_lsi.vSyn')
total = time() - start
print "Total Time:", total, "s"
# print ccx.result
# import pdb; pdb.set_trace()
print "Removing Wires from database"
start = time()
import wire_remover
wire_remover.main(ccx.result['wires'], ccx.result['gates'], lsi_lib.result)
total = time() - start
print "Total Time:", total, "s"
print "Writing Files"
start = time()
import file_writer
file_writer.out_files(ccx.result['gates'], lsi_lib.result, "test_ccx_ross")
total = time() - start
print "Total Time:", total, "s"
import pdb; pdb.set_trace()
ccx.result.stats()
ccx.result.net_stats()
ccx.result.wire_stats(lsi_lib.result)
p = prompt()
p()