|
| 1 | +from __future__ import absolute_import |
| 2 | +from __future__ import print_function |
| 3 | +import _list |
| 4 | + |
| 5 | +expected_verilog = """ |
| 6 | +module blinkled # |
| 7 | +( |
| 8 | + parameter WIDTH = 8 |
| 9 | +) |
| 10 | +( |
| 11 | + input CLK, |
| 12 | + input RST, |
| 13 | + output reg [WIDTH-1:0] LED_0, |
| 14 | + output reg [WIDTH-1:0] LED_1, |
| 15 | + output reg [WIDTH-1:0] LED_2, |
| 16 | + output reg [WIDTH-1:0] LED_3, |
| 17 | + output reg [WIDTH-1:0] LED_4, |
| 18 | + output reg [WIDTH-1:0] LED_5, |
| 19 | + output reg [WIDTH-1:0] LED_6, |
| 20 | + output reg [WIDTH-1:0] LED_7 |
| 21 | +); |
| 22 | +
|
| 23 | + reg [32-1:0] count; |
| 24 | +
|
| 25 | + always @(posedge CLK) begin |
| 26 | + if(RST) begin |
| 27 | + count <= 0; |
| 28 | + end else begin |
| 29 | + if(count == 1023) begin |
| 30 | + count <= 0; |
| 31 | + end else begin |
| 32 | + count <= count + 1; |
| 33 | + end |
| 34 | + end |
| 35 | + end |
| 36 | +
|
| 37 | +
|
| 38 | + always @(*) begin |
| 39 | + case(count % 8) |
| 40 | + 0: begin |
| 41 | + LED_0 = count[WIDTH-1:0]; |
| 42 | + end |
| 43 | + 1: begin |
| 44 | + LED_1 = count[WIDTH-1:0]; |
| 45 | + end |
| 46 | + 2: begin |
| 47 | + LED_2 = count[WIDTH-1:0]; |
| 48 | + end |
| 49 | + 3: begin |
| 50 | + LED_3 = count[WIDTH-1:0]; |
| 51 | + end |
| 52 | + 4: begin |
| 53 | + LED_4 = count[WIDTH-1:0]; |
| 54 | + end |
| 55 | + 5: begin |
| 56 | + LED_5 = count[WIDTH-1:0]; |
| 57 | + end |
| 58 | + 6: begin |
| 59 | + LED_6 = count[WIDTH-1:0]; |
| 60 | + end |
| 61 | + 7: begin |
| 62 | + LED_7 = count[WIDTH-1:0]; |
| 63 | + end |
| 64 | + endcase |
| 65 | + end |
| 66 | +endmodule |
| 67 | +""" |
| 68 | + |
| 69 | +def test(): |
| 70 | + test_module = _list.mkLed() |
| 71 | + code = test_module.to_verilog() |
| 72 | + |
| 73 | + from pyverilog.vparser.parser import VerilogParser |
| 74 | + from pyverilog.ast_code_generator.codegen import ASTCodeGenerator |
| 75 | + parser = VerilogParser() |
| 76 | + expected_ast = parser.parse(expected_verilog) |
| 77 | + codegen = ASTCodeGenerator() |
| 78 | + expected_code = codegen.visit(expected_ast) |
| 79 | + |
| 80 | + assert(expected_code == code) |
0 commit comments