8000 Fix parameters referencing interface fields (#1593) (#5910) · verilator/verilator@353a4b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 353a4b7

Browse files
authored
Fix parameters referencing interface fields (#1593) (#5910)
1 parent 6d1e82b commit 353a4b7

9 files changed

+39
-11
lines changed

src/V3AstNodeExpr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5742,6 +5742,7 @@ class AstVarXRef final : public AstNodeVarRef {
57425742
string m_name;
57435743
string m_dotted; // Dotted part of scope the name()'ed reference is under or ""
57445744
string m_inlinedDots; // Dotted hierarchy flattened out
5745+
bool m_containsGenBlock = false; // Contains gen block reference
57455746
public:
57465747
AstVarXRef(FileLine* fl, const string& name, const string& dotted, const VAccess& access)
57475748
: ASTGEN_SUPER_VarXRef(fl, nullptr, access)
@@ -5757,6 +5758,8 @@ class AstVarXRef final : public AstNodeVarRef {
57575758
void dotted(const string& dotted) { m_dotted = dotted; }
57585759
string inlinedDots() const { return m_inlinedDots; }
57595760
void inlinedDots(const string& flag) { m_inlinedDots = flag; }
5761+
bool containsGenBlock() const { return m_containsGenBlock; }
5762+
void containsGenBlock(const bool flag) { m_containsGenBlock = flag; }
57605763
string emitVerilog() override { V3ERROR_NA_RETURN(""); }
57615764
string emitC() override { V3ERROR_NA_RETURN(""); }
57625765
bool cleanOut() const override { return true; }

src/V3AstNodes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,6 +2509,7 @@ AstNodeVarRef* AstNodeVarRef::varRefLValueRecurse(AstNode* nodep) {
25092509

25102510
void AstVarXRef::dump(std::ostream& str) const {
25112511
this->AstNodeVarRef::dump(str);
2512+
if (containsGenBlock()) str << " [GENBLK]";
25122513
str << ".=" << dotted() << " ";
25132514
if (inlinedDots() != "") str << " inline.=" << inlinedDots() << " - ";
25142515
if (varScopep()) {
@@ -2520,6 +2521,7 @@ void AstVarXRef::dump(std::ostream& str) const {
25202521
}
25212522
}
25222523
void AstVarXRef::dumpJson(std::ostream& str) const {
2524+
dumpJsonBoolFunc(str, containsGenBlock);
25232525
dumpJsonStrFunc(str, dotted);
25242526
dumpJsonStrFunc(str, inlinedDots);
25252527
dumpJsonGen(str);

src/V3LinkDot.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,6 +226 8000 6,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
22662266
bool m_super; // Starts with super reference
22672267
bool m_unresolvedCell; // Unresolved cell, needs help from V3Param
22682268
bool m_unresolvedClass; // Unresolved class reference, needs help from V3Param
2269+
bool m_genBlk; // Contains gen block reference
22692270
AstNode* m_unlinkedScopep; // Unresolved scope, needs corresponding VarXRef
22702271
bool m_dotErr; // Error found in dotted resolution, ignore upwards
22712272
string m_dotText; // String of dotted names found in below parseref
@@ -2280,6 +2281,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
22802281
m_dotText = "";
22812282
m_unresolvedCell = false;
22822283
m_unresolvedClass = false;
2284+
m_genBlk = false;
22832285
m_unlinkedScopep = nullptr;
22842286
}
22852287
string ascii() const {
@@ -2295,6 +2297,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
22952297
if (m_super) sstr << " [super]";
22962298
if (m_unresolvedCell) sstr << " [unrCell]";
22972299
if (m_unresolvedClass) sstr << " [unrClass]";
2300+
if (m_genBlk) sstr << " [genBlk]";
22982301
sstr << " txt=" << m_dotText;
22992302
return sstr.str();
23002303
}
@@ -3075,6 +3078,9 @@ class LinkDotResolveVisitor final : public VNVisitor {
30753078
m_ds.m_dotText = VString::dot(m_ds.m_dotText, ".", nodep->name());
30763079
m_ds.m_dotSymp = foundp;
30773080
m_ds.m_dotPos = DP_SCOPE;
3081+
if (const AstBegin* const beginp = VN_CAST(foundp->nodep(), Begin)) {
3082+
if (beginp->generate()) m_ds.m_genBlk = true;
3083+
}
30783084
// Upper AstDot visitor will handle it from here
30793085
} else if (VN_IS(foundp->nodep(), Cell) && allowVar) {
30803086
AstCell* const cellp = VN_AS(foundp->nodep(), Cell);
@@ -3135,6 +3141,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
31353141
= new AstVarXRef{nodep->fileline(), nodep->name(), m_ds.m_dotText,
31363142
VAccess::READ}; // lvalue'ness computed later
31373143
refp->varp(varp);
3144+
refp->containsGenBlock(m_ds.m_genBlk);
31383145
if (varp->attrSplitVar()) {
31393146
refp->v3warn(
31403147
SPLITVAR,

src/V3Param.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,10 @@ class ParamVisitor final : public VNVisitor {
12921292
}
12931293
}
12941294
}
1295-
nodep->varp(nullptr); // Needs relink, as may remove pointed-to var
1295+
if (nodep->containsGenBlock()) {
1296+
// Needs relink, as may remove pointed-to var
1297+
nodep->varp(nullptr);
1298+
}
12961299
}
12971300

12981301
void visit(AstDot* nodep) override {

test_regress/t/t_interface_param_acc_bits.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
9E88
@@ -11,8 +11,8 @@
1111

1212
test.scenarios('simulator')
1313

14-
test.compile(
15-
fails=test.vlt_all, # Unsupported bug1523
16-
expect_filename=test.golden_filename)
14+
test.compile()
15+
16+
test.execute()
1717

1818
test.passes()

test_regress/t/t_interface_param_acc_bits.v

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@
44
// without warranty, 2017 by Johan Bjork.
55
// SPDX-License-Identifier: CC0-1.0
66

7-
// bug1593
8-
97
interface simple_bus #(PARAMETER = 0);
8+
typedef struct packed {
9+
logic [31:0] data;
10+
logic [3:0] mask;
11+
} payload_t;
12+
1013
parameter [6:0] dummy = 22;
14+
payload_t payload;
15+
logic [1:0] x;
1116
endinterface
1217

1318
module t ();
1419
simple_bus sb_intf();
20+
localparam LP = $bits(sb_intf.payload.data);
1521
simple_bus #(.PARAMETER($bits(sb_intf.dummy))) simple();
22+
simple_bus #(.PARAMETER($bits(sb_intf.x))) simple2();
1623
initial begin
24+
if (LP != 32) $stop;
1725
if (simple.PARAMETER != 7) $stop;
26+
if (simple2.PARAMETER != 2) $stop;
1827
$write("*-* All Finished *-*\n");
1928
$finish;
2029
end
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
%Error: t/t_interface_param_another_bad.v:9:42: Parameter-resolved constants must not use dotted references: 'dummy'
1+
%Error: t/t_interface_param_another_bad.v:9:36: Expecting expression to be constant, but variable isn't const: 'dummy'
22
: ... note: In instance 't'
3-
9 | simple_bus #(.PARAMETER($bits(sb_intf.dummy))) simple();
4-
| ^~~~~
3+
9 | simple_bus #(.PARAMETER(sb_intf.dummy)) simple();
4+
| ^~~~~
5+
%Error: t/t_interface_param_another_bad.v:9:18: Can't convert defparam value to constant: Param 'PARAMETER' of 'simple'
6+
: ... note: In instance 't'
7+
9 | simple_bus #(.PARAMETER(sb_intf.dummy)) simple();
8+
| ^~~~~~~~~
59
%Error: Exiting due to

test_regress/t/t_interface_param_another_bad.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
module t ();
88
simple_bus sb_intf();
9-
simple_bus #(.PARAMETER($bits(sb_intf.dummy))) simple();
9+
simple_bus #(.PARAMETER(sb_intf.dummy)) simple();
1010
initial begin
1111
$write("*-* All Finished *-*\n");
1212
$finish;

test_regress/t/t_json_only_tag.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{"type":"VAR","name":"dotted","addr":"(R)","loc":"d,33:16,33:22","dtypep":"(S)","origName":"dotted","isSc":false,"isPrimaryIO":false,"direction":"NONE","isConst":false,"isPullup":false,"isPulldown":false,"isUsedClock":false,"isSigPublic":false,"isLatched":false,"isUsedLoopIdx":false,"noReset":false,"attrIsolateAssign":false,"attrFileDescr":false,"isDpiOpenArray":false,"isFuncReturn":false,"isFuncLocal":false,"attrClocker":"UNKNOWN","lifetime":"VSTATIC","varType":"WIRE","dtypeName":"logic","isSigUserRdPublic":false,"isSigUserRWPublic":false,"isGParam":false,"isParam":false,"attrScBv":false,"attrSFormat":false,"ignorePostWrite":false,"ignoreSchedWrite":false,"sensIfacep":"UNLINKED","childDTypep": [],"delayp": [],"valuep": [],"attrsp": []},
1313
{"type":"ASSIGNW","name":"","addr":"(T)","loc":"d,33:23,33:24","dtypep":"(S)",
1414
"rhsp": [
15-
{"type":"VARXREF","name":"value","addr":"(U)","loc":"d,33:30,33:35","dtypep":"(V)","dotted":"itop","inlinedDots":"","access":"RD","varp":"(W)","varScopep":"UNLINKED","classOrPackagep":"UNLINKED"}
15+
{"type":"VARXREF","name":"value","addr":"(U)","loc":"d,33:30,33:35","dtypep":"(V)","containsGenBlock":false,"dotted":"itop","inlinedDots":"","access":"RD","varp":"(W)","varScopep":"UNLINKED","classOrPackagep":"UNLINKED"}
1616
],
1717
"lhsp": [
1818
{"type":"VARREF","name":"dotted","addr":"(X)","loc":"d,33:16,33:22","dtypep":"(S)","access":"WR","varp":"(R)","varScopep":"UNLINKED","classOrPackagep":"UNLINKED"}

0 commit comments

Comments
 (0)
0