forked from PyHDI/Pyverilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_lexer.py
56 lines (42 loc) · 1.51 KB
/
example_lexer.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
from __future__ import absolute_import
from __future__ import print_function
import sys
import os
from optparse import OptionParser
# the next line can be removed after installation
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pyverilog
from pyverilog.vparser.preprocessor import preprocess
from pyverilog.vparser.lexer import dump_tokens
def main():
INFO = "Verilog Lexer"
VERSION = pyverilog.__version__
USAGE = "Usage: python example_lexer.py file ..."
def showVersion():
print(INFO)
print(VERSION)
print(USAGE)
sys.exit()
optparser = OptionParser()
optparser.add_option("-v", "--version", action="store_true", dest="showversion",
default=False, help="Show the version")
optparser.add_option("-I", "--include", dest="include", action="append",
default=[], help="Include path")
optparser.add_option("-D", dest="define", action="append",
default=[], help="Macro Definition")
(options, args) = optparser.parse_args()
filelist = args
if options.showversion:
showVersion()
for f in filelist:
if not os.path.exists(f):
raise IOError("file not found: " + f)
if len(filelist) == 0:
showVersion()
text = preprocess(filelist,
include=options.include,
define=options.define)
dump = dump_tokens(text)
print(dump)
if __name__ == '__main__':
main()