简体   繁体   中英

localparam / parameter with unpack array : icarus

I am trying to initilize unpack parameter.

module dut #(parameter int arr[3]) 
(
input logic clk
);
endmodule

module main;
int t[3];
initial begin
t[0] = 0;
t[1] = 1;
t[2] = 2;
end
localparam int arr1[3] = t; //'{1,2,3};

localparam int A0 = 1;
localparam int A1 = 1;
localparam int A2 = 1;

localparam int [3] arr = '{A0, A1, A2};
logic clk;
                   
dut
# (.arr (arr)) 
dut_inst1
(.clk(clk));

dut
# (.arr (arr1)) 
dut_inst1
(.clk(clk));

endmodule

Icarus does not like any unpack initilization I tried.

I would have used pack initilization but then I have problem using it when generating based on it.

Icarus is not a system verilog compiler. it implements some features but not all of them. The following example is a legal system verilog, but not an icarus one.

It looks like icarus 0.10 (from eda playground) does not understand parameter arrays and assignment patterns. So, most likely there is no good way to do it without using separate parameter per array element. I do not have newer versions though. Talk to icarus community.

As for correct system verilog syntax, in the following example I fixes your t by using the previously commented aggregate assignment and fixes your declaration of parameters in dut and localparam in main. It is compilable with a commercial simulators but not with icarus.

module dut #(parameter int arr[3] = '{0,0,0}) 
(
input logic clk
);
endmodule

module main;
/*
int t[3];
initial begin
t[0] = 0;
t[1] = 1;
t[2] = 2;
end
*/
  
  localparam int arr1[3] = '{1,2,3};

localparam int A0 = 1;
localparam int A1 = 1;
localparam int A2 = 1;

  localparam int arr [3] = '{A0, A1, A2};
logic clk;

 
dut
# (.arr (arr)) 
dut_inst1
(.clk(clk));

dut
# (.arr (arr1)) 
dut_inst2
(.clk(clk));

  
endmodule

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM