Skip to content

Commit ad0c545

Browse files
author
Oron Port
committed
fix verilog.v95/v2001 default parameters issues and remove wrong verilator linting suppression
1 parent a3e4cd5 commit ad0c545

File tree

30 files changed

+683
-22
lines changed

30 files changed

+683
-22
lines changed

compiler/stages/src/main/scala/dfhdl/compiler/stages/verilog/VerilogOwnerPrinter.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ protected trait VerilogOwnerPrinter extends AbstractOwnerPrinter:
2323
printer.dialect match
2424
case VerilogDialect.v95 => false
2525
case _ => true
26+
val noDefaultParamSupport: Boolean =
27+
printer.dialect match
28+
case VerilogDialect.v95 | VerilogDialect.v2001 => false
29+
case _ => true
2630
def csModuleDcl(design: DFDesignBlock): String =
2731
val designMembers = design.members(MemberView.Folded)
2832
val ports = designMembers.view.collect { case p @ DclPort() =>
@@ -71,7 +75,18 @@ protected trait VerilogOwnerPrinter extends AbstractOwnerPrinter:
7175
}
7276
)
7377
val designParamList = designMembers.collect { case param: DesignParam =>
74-
val defaultValue = if (design.isTop) s" = ${param.dfValRef.refCodeString}" else ""
78+
val defaultValue =
79+
if (design.isTop) s" = ${param.dfValRef.refCodeString}"
80+
else
81+
param.defaultRef.get match
82+
case DFMember.Empty =>
83+
// missing default values are supported
84+
if (noDefaultParamSupport) ""
85+
// missing default values are not supported, so we fetch a valid constant data
86+
// (different instances may have different constant data, but for default,
87+
// a single module description can have any valid data, just to satisfy the standard)
88+
else s" = ${printer.csConstData(param.dfType, param.getConstData.get)}"
89+
case _ => s" = ${param.defaultRef.refCodeString}"
7590
s"parameter ${printer.csDFType(param.dfType)} ${param.getName}$defaultValue"
7691
}
7792
val designParamCS =

compiler/stages/src/main/scala/dfhdl/compiler/stages/verilog/VerilogValPrinter.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ protected trait VerilogValPrinter extends AbstractValPrinter:
1919
if (supportGlobalParameters || !dfVal.isGlobal)
2020
val arrRange = printer.csDFVectorRanges(dfVal.dfType)
2121
val endOfStatement = if (dfVal.isGlobal) ";" else ""
22-
s"parameter ${printer.csDFType(dfVal.dfType).emptyOr(_ + " ")}${dfVal.getName}${arrRange} = ${csDFValExpr(dfVal)}$endOfStatement"
22+
val default = dfVal match
23+
// for non-top-level design parameters, we fetch the default value if it is defined.
24+
// for all other cases, we get the parameter constant data and use that as default value.
25+
// using the constant data only happens in verilog.v95, since parameters are declared in
26+
// the body and must have defaults.
27+
case param: DesignParam =>
28+
param.defaultRef.get match
29+
case defaultVal: CanBeExpr if !param.getOwnerDesign.isTop => csDFValExpr(defaultVal)
30+
case _ => printer.csConstData(param.dfType, param.getConstData.get)
31+
case _ => csDFValExpr(dfVal)
32+
s"parameter ${printer.csDFType(dfVal.dfType).emptyOr(_ + " ")}${dfVal.getName}${arrRange} = $default$endOfStatement"
2333
else s"`define ${dfVal.getName} ${csDFValExpr(dfVal).replace("\n", " \\\n")}"
2434

2535
def csDFValDclWithoutInit(dfVal: Dcl): String =

compiler/stages/src/test/scala/StagesSpec/PrintVerilogCodeSpec.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ class PrintVerilogCodeSpec extends StageSpec:
106106
}
107107

108108
test("Basic hierarchy design with parameters") {
109-
class ID(val width: Int <> CONST) extends DFDesign:
109+
class ID(val width: Int <> CONST = 7) extends DFDesign:
110110
val x = SInt(width) <> IN
111111
val y = SInt(width) <> OUT
112112
y := x
113113

114-
class IDTop(val width: Int <> CONST) extends DFDesign:
114+
class IDTop(val width: Int <> CONST = 9) extends DFDesign:
115115
val x = SInt(width) <> IN
116116
val y = SInt(width) <> OUT
117117
val id1 = ID(width)
@@ -126,7 +126,7 @@ class PrintVerilogCodeSpec extends StageSpec:
126126
|`timescale 1ns/1ps
127127
|`include "IDTop_defs.svh"
128128
|
129-
|module ID#(parameter int width)(
129+
|module ID#(parameter int width = 7)(
130130
| input wire logic signed [width - 1:0] x,
131131
| output logic signed [width - 1:0] y
132132
|);
@@ -169,12 +169,12 @@ class PrintVerilogCodeSpec extends StageSpec:
169169

170170
test("Basic hierarchy design with parameters verilog.v95") {
171171
given options.CompilerOptions.Backend = backends.verilog.v95
172-
class ID(val width: Int <> CONST) extends DFDesign:
172+
class ID(val width: Int <> CONST = 7) extends DFDesign:
173173
val x = SInt(width) <> IN
174174
val y = SInt(width) <> OUT
175175
y := x
176176

177-
class IDTop(val width: Int <> CONST) extends DFDesign:
177+
class IDTop(val width: Int <> CONST = 9) extends DFDesign:
178178
val x = SInt(width) <> IN
179179
val y = SInt(width) <> OUT
180180
val id1 = ID(width)
@@ -194,7 +194,7 @@ class PrintVerilogCodeSpec extends StageSpec:
194194
| y
195195
|);
196196
| `include "dfhdl_defs.vh"
197-
| parameter integer width = width;
197+
| parameter integer width = 7;
198198
| input wire [width - 1:0] x;
199199
| output wire [width - 1:0] y;
200200
| assign y = x;

lib/src/main/scala/dfhdl/tools/toolsCore/Verilator.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ class VerilatorConfigPrinter(verilatorVersion: String)(using
8282
|$commands
8383
|""".stripMargin
8484
def commands: String =
85-
lintOffUninitializedParams.emptyOr(_ + "\n") +
86-
lintOffHidden.emptyOr(_ + "\n") +
85+
lintOffHidden.emptyOr(_ + "\n") +
8786
lintOffBlackBoxes.emptyOr(_ + "\n") +
8887
lintOffOpenOutPorts.emptyOr(_ + "\n") +
8988
lintOffUnused.emptyOr(_ + "\n") +
@@ -101,12 +100,6 @@ class VerilatorConfigPrinter(verilatorVersion: String)(using
101100
val lineArg = lines.emptyOr(" -lines " + _)
102101
val matchWildArg = matchWild.emptyOr(m => s""" -match "$m"""")
103102
s"lint_off$ruleArg$fileArg$lineArg$matchWildArg"
104-
def lintOffUninitializedParams: String =
105-
lintOffCommand(
106-
rule = "NEWERSTD",
107-
file = "*.*",
108-
matchWild = "*Parameter requires default value*"
109-
)
110103
def lintOffHidden: String = lintOffCommand("VARHIDDEN")
111104
def lintOffBlackBoxes: String =
112105
designDB.srcFiles.flatMap {

lib/src/test/resources/ref/AES.CipherSpecNoOpaques/verilog.v2001/hdl/mulByte_0.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
`timescale 1ns/1ps
33
`include "CipherNoOpaques_defs.vh"
44

5-
module mulByte_0#(parameter logic [7:0] lhs)(
5+
module mulByte_0#(parameter logic [7:0] lhs = 8'h02)(
66
input wire [7:0] rhs,
77
output wire [7:0] o
88
);

lib/src/test/resources/ref/AES.CipherSpecNoOpaques/verilog.v2001/hdl/mulByte_1.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
`timescale 1ns/1ps
33
`include "CipherNoOpaques_defs.vh"
44

5-
module mulByte_1#(parameter logic [7:0] lhs)(
5+
module mulByte_1#(parameter logic [7:0] lhs = 8'h03)(
66
input wire [7:0] rhs,
77
output wire [7:0] o
88
);

lib/src/test/resources/ref/AES.CipherSpecNoOpaques/verilog.v2001/hdl/mulByte_2.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
`timescale 1ns/1ps
33
`include "CipherNoOpaques_defs.vh"
44

5-
module mulByte_2#(parameter logic [7:0] lhs)(
5+
module mulByte_2#(parameter logic [7:0] lhs = 8'h01)(
66
input wire [7:0] rhs,
77
output wire [7:0] o
88
);

lib/src/test/resources/ref/AES.CipherSpecWithOpaques/verilog.v2001/hdl/mulByte_0.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
`timescale 1ns/1ps
33
`include "Cipher_defs.vh"
44

5-
module mulByte_0#(parameter logic [7:0] lhs)(
5+
module mulByte_0#(parameter logic [7:0] lhs = 8'h02)(
66
input wire [7:0] rhs,
77
output wire [7:0] o
88
);

lib/src/test/resources/ref/AES.CipherSpecWithOpaques/verilog.v2001/hdl/mulByte_1.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
`timescale 1ns/1ps
33
`include "Cipher_defs.vh"
44

5-
module mulByte_1#(parameter logic [7:0] lhs)(
5+
module mulByte_1#(parameter logic [7:0] lhs = 8'h03)(
66
input wire [7:0] rhs,
77
output wire [7:0] o
88
);

lib/src/test/resources/ref/AES.CipherSpecWithOpaques/verilog.v2001/hdl/mulByte_2.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
`timescale 1ns/1ps
33
`include "Cipher_defs.vh"
44

5-
module mulByte_2#(parameter logic [7:0] lhs)(
5+
module mulByte_2#(parameter logic [7:0] lhs = 8'h01)(
66
input wire [7:0] rhs,
77
output wire [7:0] o
88
);

0 commit comments

Comments
 (0)