Skip to content

Commit d64edfb

Browse files
committed
A pytest module for ast_code_generator is added. Jinja2 template of moduledef is updated.
1 parent 3c7a04d commit d64edfb

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

pyverilog/ast_code_generator/codegen.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,8 @@ def showVersion():
984984
default=False,help="Show the version")
985985
optparser.add_option("-I","--include",dest="include",action="append",
986986
default=[],help="Include path")
987+
optparser.add_option("-D",dest="define",action="append",
988+
default=[],help="Macro Definition")
987989
(options, args) = optparser.parse_args()
988990

989991
filelist = args
@@ -996,7 +998,10 @@ def showVersion():
996998
if len(filelist) == 0:
997999
showVersion()
9981000

999-
codeparser = VerilogCodeParser(filelist, preprocess_include=options.include)
1001+
codeparser = VerilogCodeParser(filelist,
1002+
preprocess_include=options.include,
1003+
preprocess_define=options.define)
1004+
10001005
ast = codeparser.parse()
10011006
directives = codeparser.get_directives()
10021007

pyverilog/ast_code_generator/template/moduledef.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ module {{ modulename }}{% if paramlist != '' %} #
1111
{% for item in items %}{{ item }}
1212
{% endfor %}
1313
endmodule
14+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
TEST=*.py
2+
ARGS=
3+
4+
PYTHON=python3
5+
#PYTHON=python
6+
#OPT=-m pdb
7+
#OPT=-m cProfile -s time
8+
#OPT=-m cProfile -o profile.rslt
9+
10+
.PHONY: all
11+
all: test
12+
13+
.PHONY: test
14+
test:
15+
$(PYTHON) -m pytest -vv $(TEST)
16+
17+
.PHONY: clean
18+
clean:
19+
rm -rf *.pyc __pycache__ parsetab.py *.out
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../pyverilog/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import sys
3+
import pyverilog.vparser.ast as vast
4+
from pyverilog.ast_code_generator.codegen import ASTCodeGenerator
5+
6+
expected = """\
7+
8+
module top
9+
(
10+
input CLK,
11+
input RST,
12+
output [7:0] led
13+
);
14+
15+
assign led = 8;
16+
17+
endmodule
18+
"""
19+
20+
def test():
21+
params = vast.Paramlist(())
22+
clk = vast.Ioport( vast.Input('CLK') )
23+
rst = vast.Ioport( vast.Input('RST') )
24+
width = vast.Width( vast.IntConst('7'), vast.IntConst('0') )
25+
led = vast.Ioport( vast.Output('led', width=width) )
26+
ports = vast.Portlist( (clk, rst, led) )
27+
items = ( vast.Assign( vast.Identifier('led'), vast.IntConst('8') ) ,)
28+
ast = vast.ModuleDef("top", params, ports, items)
29+
30+
codegen = ASTCodeGenerator()
31+
rslt = codegen.visit(ast)
32+
33+
print(rslt)
34+
assert(rslt == expected)
35+
36+
if __name__ == '__main__':
37+
test()

0 commit comments

Comments
 (0)