一、SpinalConfig
1.reg、wire名称的前缀
在SpinalHDL中默认采用的前缀为zz,可以通过在SpinalConfig中配置“anonymSignalPrefix”字符串中的内容达到你想要的前缀,Scala中代码如下:
object Top extends App {
SpinalConfig(anonymSignalPrefix = "tmp").generateVerilog(new Top)
}
这样就会将SpinalHDL生成的“zz”前缀替换为“tmp”啦,简单又使用的技巧就此获得。
二、Component
1.设定module名称
在SpinalHDL中采用this.setDefinitionName达到module名称的目的,请看scala代码
class Sum(diw: Int, size: Int, stage: Int) extends Component{
this.setDefinitionName(s"sum_stage${stage}_n${size}_w${diw}")
val dow = diw + log2Up(size)
val io = new Bundle{
val nets = slave Flow(Vec(SInt(diw bits), size))
val sum = out(SInt(dow bits)).setAsReg()
}
when(io.nets.valid){
io.sum := io.nets.payload
.map(_.resize(dow bits))
.reduce(_ + _)
}
}
object Sum extends App {
SpinalVerilog(new Sum(8, 2, 0))
}
最终module名称为"sum_stage0_n2_w8",和SpinalHDL的设定一致。