Fix constant enum methods (#3621)

This commit is contained in:
Todd Strader 2023-02-08 18:50:27 -05:00 committed by GitHub
parent d3cbb1e53f
commit 9121a81a74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 1 deletions

View File

@ -442,7 +442,8 @@ private:
clearOptimizable(nodep, "Var write & read");
}
vscp->user1(vscp->user1() | VU_RV);
const bool isConst = nodep->varp()->isParam() && nodep->varp()->valuep();
const bool isConst = (nodep->varp()->isConst() || nodep->varp()->isParam())
&& nodep->varp()->valuep();
AstNodeExpr* const valuep
= isConst ? fetchValueNull(nodep->varp()->valuep()) : nullptr;
// Propagate PARAM constants for constant function analysis

View File

@ -0,0 +1,21 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
scenarios(simulator => 1);
compile(
);
execute(
check_finished => 1,
);
ok(1);
1;

View File

@ -0,0 +1,47 @@
// DESCRIPTION: Verilator: constant enum methods
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2022 by Todd Strader
// SPDX-License-Identifier: CC0-1.0
module t ();
typedef enum [1:0] {E0, E1, E2} enm_t;
function automatic enm_t get_first();
enm_t enm;
return enm.first;
endfunction
localparam enm_t enum_first = get_first();
function automatic enm_t get_last();
enm_t enm;
return enm.last;
endfunction
localparam enm_t enum_last = get_last();
function automatic enm_t get_second();
enm_t enm;
enm = enm.first;
return enm.next;
endfunction
localparam enm_t enum_second = get_second();
function automatic string get_name(enm_t enm);
return enm.name;
endfunction
localparam string e0_name = get_name(E0);
initial begin
if (enum_first != E0) $stop;
if (enum_last != E2) $stop;
if (enum_second != E1) $stop;
if (e0_name != "E0") $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule