Skip to content

Commit 5fd2a6f

Browse files
committed
ast_code_generator sample
1 parent d12507a commit 5fd2a6f

File tree

1 file changed

+19
-0
lines changed
  • pyverilog/ast_code_generator/sample

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
import os
3+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) )
4+
5+
import pyverilog.vparser.ast as vast
6+
from pyverilog.ast_code_generator.codegen import ASTCodeGenerator
7+
8+
params = vast.Paramlist(())
9+
clk = vast.Ioport( vast.Input('CLK') )
10+
rst = vast.Ioport( vast.Input('RST') )
11+
width = vast.Width( vast.IntConst('7'), vast.IntConst('0') )
12+
led = vast.Ioport( vast.Output('led', width=width) )
13+
ports = vast.Portlist( (clk, rst, led) )
14+
items = ( vast.Assign( vast.Identifier('led'), vast.IntConst('8') ) ,)
15+
ast = vast.ModuleDef("top", params, ports, items)
16+
17+
codegen = ASTCodeGenerator()
18+
rslt = codegen.visit(ast)
19+
print(rslt)

0 commit comments

Comments
 (0)