File: generics.v

package info (click to toggle)
iverilog 12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,148 kB
  • sloc: cpp: 109,972; ansic: 62,713; yacc: 10,216; sh: 3,470; vhdl: 3,246; perl: 1,814; makefile: 1,774; python: 78; csh: 2
file content (52 lines) | stat: -rw-r--r-- 1,172 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// A few simple tests of translating parameters to generics
module top();
  wire [7:0] v1, v2, v3;
  wire [7:0] w1, w2, w3;

  child c1(v1, w1);
  child c2(v2, w2);
  child c3(v3, w3);

  defparam c1.MY_VALUE = 6;
  defparam c2.MY_VALUE = 44;

  initial begin
    #2;
    $display("c1 reg value: %d", v1);
    $display("c2 reg value: %d", v2);
    $display("c3 reg value: %d", v3);
    $display("c1 wire value: %d", w1);
    $display("c2 wire value: %d", w2);
    $display("c3 wire value: %d", w3);
    if (v1 !== 6)
      $display("FAILED - v1 !== 6");
    else if (v2 !== 44)
      $display("FAILED - v2 !== 44");
    else if (v3 !== 12)
      $display("FAILED - v3 !== 12");
    else if (w1 !== 7)
      $display("FAILED - v1 !== 7");
    else if (w2 !== 45)
      $display("FAILED - v2 !== 45");
    else if (w3 !== 13)
      $display("FAILED - v3 !== 13");
    else
      $display("PASSED");
  end

endmodule // top

module child(value, value_w);
  output [7:0] value, value_w;
  reg [7:0]    value;

  parameter MY_VALUE = 12;

  assign value_w = MY_VALUE + 1;

  // Make a non-trivial process
  initial begin
    #1;
    value <= MY_VALUE;
  end
endmodule // child