Skip to content

Commit

Permalink
Indent size of embedded code is changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
shtaxxx committed May 2, 2017
1 parent aae1e4f commit af6aefc
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyverilog/ast_code_generator/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,4 +1021,4 @@ def visit_SingleStatement(self, node):
return rslt

def visit_EmbeddedCode(self, node):
return self.indent(node.code)
return node.code
72 changes: 72 additions & 0 deletions tests/ast_code_generator_test/test_ast_embeddedcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

import pyverilog.vparser.ast as vast
from pyverilog.ast_code_generator.codegen import ASTCodeGenerator

expected = """\
module top
(
input CLK,
input RST,
output reg [7:0] led
);
// Embedded code
reg [31:0] count;
always @(posedge CLK) begin
if(RST) begin
count <= 0;
led <= 0;
end else begin
if(count == 1024 - 1) begin
count <= 0;
led <= led + 1;
end else begin
count <= count + 1;
end
end
end
endmodule
"""

def test():
params = vast.Paramlist( [] )
clk = vast.Ioport( vast.Input('CLK') )
rst = vast.Ioport( vast.Input('RST') )
width = vast.Width( vast.IntConst('7'), vast.IntConst('0') )
led = vast.Ioport( vast.Output('led', width=width), vast.Reg('led', width=width) )
ports = vast.Portlist( (clk, rst, led) )
items = [ vast.EmbeddedCode("""
// Embedded code
reg [31:0] count;
always @(posedge CLK) begin
if(RST) begin
count <= 0;
led <= 0;
end else begin
if(count == 1024 - 1) begin
count <= 0;
led <= led + 1;
end else begin
count <= count + 1;
end
end
end
""") ]
ast = vast.ModuleDef("top", params, ports, items)

codegen = ASTCodeGenerator()
rslt = codegen.visit(ast)

print(rslt)
assert(expected == rslt)

if __name__ == '__main__':
test()

0 comments on commit af6aefc

Please sign in to comment.