Skip to content

Commit af6aefc

Browse files
committed
Indent size of embedded code is changed.
1 parent aae1e4f commit af6aefc

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

pyverilog/ast_code_generator/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,4 +1021,4 @@ def visit_SingleStatement(self, node):
10211021
return rslt
10221022

10231023
def visit_EmbeddedCode(self, node):
1024-
return self.indent(node.code)
1024+
return node.code
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from __future__ import absolute_import
2+
from __future__ import print_function
3+
import os
4+
import sys
5+
6+
import pyverilog.vparser.ast as vast
7+
from pyverilog.ast_code_generator.codegen import ASTCodeGenerator
8+
9+
expected = """\
10+
11+
module top
12+
(
13+
input CLK,
14+
input RST,
15+
output reg [7:0] led
16+
);
17+
18+
19+
// Embedded code
20+
reg [31:0] count;
21+
always @(posedge CLK) begin
22+
if(RST) begin
23+
count <= 0;
24+
led <= 0;
25+
end else begin
26+
if(count == 1024 - 1) begin
27+
count <= 0;
28+
led <= led + 1;
29+
end else begin
30+
count <= count + 1;
31+
end
32+
end
33+
end
34+
35+
36+
endmodule
37+
"""
38+
39+
def test():
40+
params = vast.Paramlist( [] )
41+
clk = vast.Ioport( vast.Input('CLK') )
42+
rst = vast.Ioport( vast.Input('RST') )
43+
width = vast.Width( vast.IntConst('7'), vast.IntConst('0') )
44+
led = vast.Ioport( vast.Output('led', width=width), vast.Reg('led', width=width) )
45+
ports = vast.Portlist( (clk, rst, led) )
46+
items = [ vast.EmbeddedCode("""
47+
// Embedded code
48+
reg [31:0] count;
49+
always @(posedge CLK) begin
50+
if(RST) begin
51+
count <= 0;
52+
led <= 0;
53+
end else begin
54+
if(count == 1024 - 1) begin
55+
count <= 0;
56+
led <= led + 1;
57+
end else begin
58+
count <= count + 1;
59+
end
60+
end
61+
end
62+
""") ]
63+
ast = vast.ModuleDef("top", params, ports, items)
64+
65+
codegen = ASTCodeGenerator()
66+
rslt = codegen.visit(ast)
67+
68+
print(rslt)
69+
assert(expected == rslt)
70+
71+
if __name__ == '__main__':
72+
test()

0 commit comments

Comments
 (0)