今天有用到define的一种用法,在这share一下,直接上例子~~
module top ;
`define A_SRAM_RW(dst_cc_num,src_cc_num)\
if(strm_sel[``dst_cc_num``] == 1'b1)begin\
force top.my_dut.strm_in``dst_cc_num``_en = top.my_dut.strm_in``src_cc_num``_en;\
end
initial begin
`A_SRAM_RW(1,0)
`A_SRAM_RW(2,0)
end
endmodule
result:
module top;
initial begin
if(strm_sel[1] == 1'b1)begin
force top.my_dut.strm_in1_en = top.my_dut.strm_in0_en;
end
if(strm_sel[2] == 1'b1)begin
force top.my_dut.strm_in2_en = top.my_dut.strm_in0_en;
end
end
endmodule
上栗中,dst_cc_num和src_cc_num是要传进来的参数,引用传进来的参数时要在参数前和后加``,不接收传进来的变量,比如
generate
for(genvar jj=1;jj<`CC_NUM;jj++)begin
`A_SRAM_RW(jj,0)
end
endgenerate
上面这种写法是不行的,相当于只是把jj传进了define中,并不会把jj所代表的值传进去。