@@ -844,13 +844,8 @@ exprt verilog_typecheck_exprt::convert_system_function(
844844
845845 if (arguments.size () >= 2 )
846846 {
847- auto tmp = elaborate_constant_expression (arguments[1 ]);
848- if (!tmp.is_constant ())
849- {
850- throw errort ().with_location (arguments[1 ].source_location ())
851- << " expected elaboration-time constant, but got `" << to_string (tmp)
852- << ' \' ' ;
853- }
847+ auto tmp = elaborate_constant_expression_check (arguments[1 ]);
848+ arguments[1 ] = tmp;
854849 }
855850
856851 expr.type () = arguments.front ().type ();
@@ -1454,12 +1449,12 @@ verilog_typecheck_exprt::convert_integer_constant_expression(exprt expr)
14541449 // this could be large
14551450 propagate_type (expr, integer_typet ());
14561451
1457- exprt tmp = elaborate_constant_expression (expr);
1452+ exprt tmp = elaborate_constant_expression_check (expr);
14581453
1459- if (! tmp.is_constant () )
1454+ if (tmp.id () == ID_infinity )
14601455 {
14611456 throw errort ().with_location (source_location)
1462- << " expected constant expression , but got ` " << to_string (tmp) << ' \' ' ;
1457+ << " expected integer constant , but got $ " ;
14631458 }
14641459
14651460 const auto &tmp_constant = to_constant_expr (tmp);
@@ -1515,6 +1510,9 @@ exprt verilog_typecheck_exprt::elaborate_constant_expression(exprt expr)
15151510
15161511 if (symbol.is_macro )
15171512 {
1513+ // Elaborate recursively
1514+ elaborate_symbol_rec (symbol.name );
1515+
15181516 // A parameter or local parameter. Replace by its value.
15191517 return symbol.value ;
15201518 }
@@ -1524,12 +1522,12 @@ exprt verilog_typecheck_exprt::elaborate_constant_expression(exprt expr)
15241522 #if 0
15251523 status() << "READ " << identifier << " = " << to_string(value) << eom;
15261524 #endif
1527-
1525+
15281526 if (value.is_not_nil ())
15291527 {
1530- source_locationt source_location= expr.source_location ();
1531- exprt tmp= value;
1532- tmp.add_source_location ()= source_location;
1528+ source_locationt source_location = expr.source_location ();
1529+ exprt tmp = value;
1530+ tmp.add_source_location () = source_location;
15331531 return tmp;
15341532 }
15351533 else
@@ -1671,6 +1669,34 @@ exprt verilog_typecheck_exprt::elaborate_constant_expression(exprt expr)
16711669
16721670/* ******************************************************************\
16731671
1672+ Function: verilog_typecheck_exprt::elaborate_constant_expression_check
1673+
1674+ Inputs:
1675+
1676+ Outputs:
1677+
1678+ Purpose:
1679+
1680+ \*******************************************************************/
1681+
1682+ exprt verilog_typecheck_exprt::elaborate_constant_expression_check (exprt expr)
1683+ {
1684+ source_locationt source_location = expr.find_source_location ();
1685+
1686+ exprt tmp = elaborate_constant_expression (std::move (expr));
1687+
1688+ // $ counts as a constant
1689+ if (!tmp.is_constant () && tmp.id () != ID_infinity)
1690+ {
1691+ throw errort ().with_location (source_location)
1692+ << " expected constant expression, but got `" << to_string (tmp) << ' \' ' ;
1693+ }
1694+
1695+ return tmp;
1696+ }
1697+
1698+ /* ******************************************************************\
1699+
16741700Function: verilog_typecheck_exprt::elaborate_constant_system_function_call
16751701
16761702 Inputs:
0 commit comments