|
import chisel3._
import chisel3.util._
class DeCoder extends RawModule{
val io = IO(new Bundle{
val a = Input(UInt(1.W))
val b = Input(UInt(1.W))
val c = Output(UInt(4.W))
})
val sel = Cat(io.a,io.b)
io.c := 0.U //必须要有默认值 否则:firrtl.passes.CheckInitialization$RefNotInitializedException
switch(sel) {
is(0.U) { io.c := 1.U}
is(1.U) { io.c := 2.U}
is(2.U) { io.c := 3.U}
is(3.U) { io.c := 4.U}
}
}
对应的verilog文件内容如下:
module DeCoder(
input io_a,
input io_b,
output [3:0] io_c
);
wire [1:0] sel = {io_a,io_b}; // @[Cat.scala 30:58]
wire _T = 2'h0 == sel; // @[Conditional.scala 37:30]
wire _T_1 = 2'h1 == sel; // @[Conditional.scala 37:30]
wire _T_2 = 2'h2 == sel; // @[Conditional.scala 37:30]
wire _T_3 = 2'h3 == sel; // @[Conditional.scala 37:30]
wire [2:0] _GEN_0 = _T_3 ? 3'h4 : 3'h0; // @[Conditional.scala 39:67]
wire [2:0] _GEN_1 = _T_2 ? 3'h3 : _GEN_0; // @[Conditional.scala 39:67]
wire [2:0] _GEN_2 = _T_1 ? 3'h2 : _GEN_1; // @[Conditional.scala 39:67]
wire [2:0] _GEN_3 = _T ? 3'h1 : _GEN_2; // @[Conditional.scala 40:58]
assign io_c = {{1'd0}, _GEN_3}; // @[DeCoder.scala 12:8 DeCoder.scala 14:20 DeCoder.scala 15:20 DeCoder.scala 16:20 DeCoder.scala 17:20]
endmodule
|
|