传参
class adder(width: Int = 8) extends Module { val io = new Bundle { val a = in UInt(width bits) val b = in UInt(width bits) val sum = out UInt(width bits) } io.sum := io.a + io.b } class top extends Module { val adder0 = new adder(16) val adder1 = new adder(32) }
module top ( ); wire [15:0] adder0_io_a; wire [15:0] adder0_io_b; wire [31:0] adder1_io_a; wire [31:0] adder1_io_b; wire [15:0] adder0_io_sum; wire [31:0] adder1_io_sum; adder adder0 ( .io_a (adder0_io_a[15:0] ), //i .io_b (adder0_io_b[15:0] ), //i .io_sum (adder0_io_sum[15:0] ) //o ); adder_1 adder1 ( .io_a (adder1_io_a[31:0] ), //i .io_b (adder1_io_b[31:0] ), //i .io_sum (adder1_io_sum[31:0] ) //o ); endmodule module adder_1 ( input [31:0] io_a, input [31:0] io_b, output [31:0] io_sum ); assign io_sum = (io_a + io_b); endmodule module adder ( input [15:0] io_a, input [15:0] io_b, output [15:0] io_sum ); assign io_sum = (io_a + io_b); endmodule