I am rewriting a Verilog project to Chisel HDL. The project has several de-coupled subcomponents like (ex.v
, mem.v
, or wb.v
) and a configuration file named defines.v
, which is `included
in the subcomponents. For example,
Contents in defines.v
`define RstEnable 1'b1
`define RstDisable 1'b0
`define ZeroWord 32'h00000000
`define WriteEnable 1'b1
`define WriteDisable 1'b0
`define ReadEnable 1'b1
`define ReadDisable 1'b0
... ...
Contents in ex.v
`include "defines.v"
module ex(
input wire rst,
input wire[`AluOpBus] aluop_i,
input wire[`AluSelBus] alusel_i,
input wire[`RegBus] reg1_i,
input wire[`RegBus] reg2_i,
... ...
);
always @ (*) begin
if(rst == `RstEnable) begin
logicout <= `ZeroWord;
end else begin
case (aluop_i);
`EXE_OR_OP: begin
logicout <= reg1_i | reg2_i;
end
`EXE_AND_OP: begin
logicout <= reg1_i & reg2_i;
end
... ...
default: begin
logicout <= `ZeroWord;
end
endcase
end //if
end //always
... ...
endmodule
I'm unfamiliar with Scala, so its new LISP-style macro system is a little too powerful for me to fully understand. All I want is a simple C/C++ preprocessor style macro which does text substitution.
I have tried using variables
package cpu
import chisel3._
import chisel3.util._
object Defines {
val RstEnable = "b1".U(1.W)
val RstDisable = "b0".U(1.W)
... ...
}
The variable definitions are used in Scala as follow
class Ex extends Module {
val io = IO(new Bundle {
... ...
val aluop_i = Input(UInt(AluOpBus))
... ...
})
... ...
logicout := io.aluop_i match {
case EXE_OR_OP => logicout
case _ => 0.U
}
}
This almost works, except the following error which signals that match
isn't happy with a variable
[error] /Users/nalzok/Developer/DonkeyMIPS/chisel/src/main/scala/cpu/ex/Ex.scala:88:10: type mismatch;
[error] found : chisel3.UInt
[error] required: Unit
[error] case EXE_OR_OP => logicout
[error] ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 3 s, completed Jun 14, 2020 9:42:13 AM