Support pre_randomize and post_randomize.
This commit is contained in:
parent
ee26dddfa1
commit
c6ecd60993
1
Changes
1
Changes
|
|
@ -16,6 +16,7 @@ Verilator 5.003 devel
|
||||||
* Deprecate --no-threads; use --threads 1 for single threaded (#3703). [Kamil Rakoczy, Antmicro Ltd]
|
* Deprecate --no-threads; use --threads 1 for single threaded (#3703). [Kamil Rakoczy, Antmicro Ltd]
|
||||||
* Support named properties (#3667). [Ryszard Rozak, Antmicro Ltd]
|
* Support named properties (#3667). [Ryszard Rozak, Antmicro Ltd]
|
||||||
* Support randcase.
|
* Support randcase.
|
||||||
|
* Support pre_randomize and post_randomize.
|
||||||
* Add ENUMVALUE warning when value misused for enum (#726).
|
* Add ENUMVALUE warning when value misused for enum (#726).
|
||||||
* Internal AST improvements, also affect XML format (#3721). [Geza Lore]
|
* Internal AST improvements, also affect XML format (#3721). [Geza Lore]
|
||||||
* Change ENDLABEL from warning into an error.
|
* Change ENDLABEL from warning into an error.
|
||||||
|
|
|
||||||
|
|
@ -1585,7 +1585,7 @@ class AstThisRef final : public AstNodeExpr {
|
||||||
// Reference to 'this'.
|
// Reference to 'this'.
|
||||||
// @astgen op1 := childDTypep : Optional[AstClassRefDType] // dtype of the node
|
// @astgen op1 := childDTypep : Optional[AstClassRefDType] // dtype of the node
|
||||||
public:
|
public:
|
||||||
explicit AstThisRef(FileLine* fl, AstClassRefDType* dtypep)
|
AstThisRef(FileLine* fl, VFlagChildDType, AstClassRefDType* dtypep)
|
||||||
: ASTGEN_SUPER_ThisRef(fl) {
|
: ASTGEN_SUPER_ThisRef(fl) {
|
||||||
childDTypep(dtypep);
|
childDTypep(dtypep);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2342,7 +2342,7 @@ private:
|
||||||
AstClass* const classp = VN_AS(classSymp->nodep(), Class);
|
AstClass* const classp = VN_AS(classSymp->nodep(), Class);
|
||||||
AstClassRefDType* const dtypep
|
AstClassRefDType* const dtypep
|
||||||
= new AstClassRefDType{nodep->fileline(), classp, nullptr};
|
= new AstClassRefDType{nodep->fileline(), classp, nullptr};
|
||||||
AstThisRef* const newp = new AstThisRef{nodep->fileline(), dtypep};
|
AstThisRef* const newp = new AstThisRef{nodep->fileline(), VFlagChildDType{}, dtypep};
|
||||||
nodep->replaceWith(newp);
|
nodep->replaceWith(newp);
|
||||||
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -115,9 +115,7 @@ private:
|
||||||
if (m_underGenerate) nodep->underGenerate(true);
|
if (m_underGenerate) nodep->underGenerate(true);
|
||||||
// Remember the existing symbol table scope
|
// Remember the existing symbol table scope
|
||||||
if (m_classp) {
|
if (m_classp) {
|
||||||
if (nodep->name() == "pre_randomize" || nodep->name() == "post_randomize") {
|
if (nodep->name() == "randomize") {
|
||||||
nodep->v3warn(E_UNSUPPORTED, "Unsupported: " << nodep->prettyNameQ());
|
|
||||||
} else if (nodep->name() == "randomize") {
|
|
||||||
nodep->v3error(nodep->prettyNameQ()
|
nodep->v3error(nodep->prettyNameQ()
|
||||||
<< " is a predefined class method; redefinition not allowed"
|
<< " is a predefined class method; redefinition not allowed"
|
||||||
" (IEEE 1800-2017 18.6.3)");
|
" (IEEE 1800-2017 18.6.3)");
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,14 @@ private:
|
||||||
valp};
|
valp};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void addPrePostCall(AstClass* classp, AstFunc* funcp, const string& name) {
|
||||||
|
if (AstTask* userFuncp = VN_CAST(classp->findMember(name), Task)) {
|
||||||
|
AstTaskRef* const callp
|
||||||
|
= new AstTaskRef{userFuncp->fileline(), userFuncp->name(), nullptr};
|
||||||
|
callp->taskp(userFuncp);
|
||||||
|
funcp->addStmtsp(callp->makeStmt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// VISITORS
|
// VISITORS
|
||||||
void visit(AstNodeModule* nodep) override {
|
void visit(AstNodeModule* nodep) override {
|
||||||
|
|
@ -215,6 +223,7 @@ private:
|
||||||
UINFO(9, "Define randomize() for " << nodep << endl);
|
UINFO(9, "Define randomize() for " << nodep << endl);
|
||||||
AstFunc* const funcp = V3Randomize::newRandomizeFunc(nodep);
|
AstFunc* const funcp = V3Randomize::newRandomizeFunc(nodep);
|
||||||
AstVar* const fvarp = VN_AS(funcp->fvarp(), Var);
|
AstVar* const fvarp = VN_AS(funcp->fvarp(), Var);
|
||||||
|
addPrePostCall(nodep, funcp, "pre_randomize");
|
||||||
funcp->addStmtsp(new AstAssign{
|
funcp->addStmtsp(new AstAssign{
|
||||||
nodep->fileline(), new AstVarRef{nodep->fileline(), fvarp, VAccess::WRITE},
|
nodep->fileline(), new AstVarRef{nodep->fileline(), fvarp, VAccess::WRITE},
|
||||||
new AstConst{nodep->fileline(), AstConst::WidthedValue{}, 32, 1}});
|
new AstConst{nodep->fileline(), AstConst::WidthedValue{}, 32, 1}});
|
||||||
|
|
@ -250,6 +259,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addPrePostCall(nodep, funcp, "post_randomize");
|
||||||
nodep->user1(false);
|
nodep->user1(false);
|
||||||
}
|
}
|
||||||
void visit(AstRandCase* nodep) override {
|
void visit(AstRandCase* nodep) override {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
%Error-UNSUPPORTED: t/t_randomize_method_unsup.v:8:18: Unsupported: 'pre_randomize'
|
|
||||||
8 | function void pre_randomize;
|
|
||||||
| ^~~~~~~~~~~~~
|
|
||||||
... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest
|
|
||||||
%Error-UNSUPPORTED: t/t_randomize_method_unsup.v:11:18: Unsupported: 'post_randomize'
|
|
||||||
11 | function void post_randomize;
|
|
||||||
| ^~~~~~~~~~~~~~
|
|
||||||
%Error: Exiting due to
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// DESCRIPTION: Verilator: Verilog Test module
|
|
||||||
//
|
|
||||||
// This file ONLY is placed under the Creative Commons Public Domain, for
|
|
||||||
// any use, without warranty, 2020 by Wilson Snyder.
|
|
||||||
// SPDX-License-Identifier: CC0-1.0
|
|
||||||
|
|
||||||
class Cls;
|
|
||||||
function void pre_randomize;
|
|
||||||
endfunction;
|
|
||||||
|
|
||||||
function void post_randomize;
|
|
||||||
endfunction;
|
|
||||||
endclass
|
|
||||||
|
|
||||||
module t (/*AUTOARG*/);
|
|
||||||
endmodule
|
|
||||||
|
|
@ -11,8 +11,10 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di
|
||||||
scenarios(simulator => 1);
|
scenarios(simulator => 1);
|
||||||
|
|
||||||
compile(
|
compile(
|
||||||
fails => $Self->{vlt_all},
|
);
|
||||||
expect_filename => $Self->{golden_filename},
|
|
||||||
|
execute(
|
||||||
|
check_finished => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
ok(1);
|
ok(1);
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
// DESCRIPTION: Verilator: Verilog Test module
|
||||||
|
//
|
||||||
|
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||||
|
// any use, without warranty, 2022 by Wilson Snyder.
|
||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
|
typedef enum int {
|
||||||
|
RANDOMIZED = 20
|
||||||
|
} enumed_t;
|
||||||
|
|
||||||
|
class Cls;
|
||||||
|
int pre;
|
||||||
|
rand enumed_t r;
|
||||||
|
int post;
|
||||||
|
|
||||||
|
function void pre_randomize;
|
||||||
|
if (pre != 0) $stop;
|
||||||
|
$display("%d", r);
|
||||||
|
if (r != enumed_t'(0)) $stop;
|
||||||
|
if (post != 0) $stop;
|
||||||
|
pre = 10;
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function void post_randomize;
|
||||||
|
if (pre != 10) $stop;
|
||||||
|
if (r != RANDOMIZED) $stop;
|
||||||
|
if (post != 0) $stop;
|
||||||
|
post = 30;
|
||||||
|
endfunction
|
||||||
|
endclass
|
||||||
|
|
||||||
|
module t (/*AUTOARG*/);
|
||||||
|
|
||||||
|
initial begin
|
||||||
|
Cls c;
|
||||||
|
int rand_result;
|
||||||
|
|
||||||
|
c = new;
|
||||||
|
rand_result = c.randomize();
|
||||||
|
if (rand_result != 1) $stop;
|
||||||
|
if (c.pre != 10) $stop;
|
||||||
|
if (c.r != RANDOMIZED) $stop;
|
||||||
|
if (c.post != 30) $stop;
|
||||||
|
$write("*-* All Finished *-*\n");
|
||||||
|
$finish;
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
Loading…
Reference in New Issue