-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphVhdl.py
59 lines (50 loc) · 1.73 KB
/
GraphVhdl.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
import sys
from antlr4 import *
from antlr_generated.VhdlLexer import VhdlLexer
from antlr_generated.VhdlParser import VhdlParser
from VhdlListenerForGraph import VhdlListenerForGraph
def parse_file(file_path):
inp = FileStream(file_path)
lexer = VhdlLexer(inp)
stream = CommonTokenStream(lexer)
parser = VhdlParser(stream)
listener = VhdlListenerForGraph()
parser._interp.predictionMode = PredictionMode.LL
tree = parser.design_file()
walker = ParseTreeWalker()
walker.walk(listener, tree)
return listener
def main(argv):
input = FileStream(argv[1])
lexer = VhdlLexer(input)
stream = CommonTokenStream(lexer)
parser = VhdlParser(stream)
listener = VhdlListenerForGraph()
parser_option = argv[2]
if (parser_option == "SLL"):
parser._interp.predictionMode = PredictionMode.SLL
try:
print("Parsing with SLL...")
tree = parser.design_file()
except:
print("SLL didn't work, parsing with LL...")
stream.reset()
parser.reset()
parser._interp.predictionMode = PredictionMode.LL
tree = parser.design_file()
finally:
print("Done parsing, walking parse tree...")
walker = ParseTreeWalker()
walker.walk(listener, tree)
elif (parser_option == "LL"):
print("Parsing with LL...")
parser._interp.predictionMode = PredictionMode.LL
tree = parser.design_file()
print("Done parsing, walking parse tree...")
walker = ParseTreeWalker()
walker.walk(listener, tree)
print(len(listener.components_list))
# grapher = VhdlVisitorForGraph()
# grapher.visit(tree)
if __name__ == '__main__':
main(sys.argv)