@@ -844,13 +844,8 @@ exprt verilog_typecheck_exprt::convert_system_function(
844
844
845
845
if (arguments.size () >= 2 )
846
846
{
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;
854
849
}
855
850
856
851
expr.type () = arguments.front ().type ();
@@ -1454,12 +1449,12 @@ verilog_typecheck_exprt::convert_integer_constant_expression(exprt expr)
1454
1449
// this could be large
1455
1450
propagate_type (expr, integer_typet ());
1456
1451
1457
- exprt tmp = elaborate_constant_expression (expr);
1452
+ exprt tmp = elaborate_constant_expression_check (expr);
1458
1453
1459
- if (! tmp.is_constant () )
1454
+ if (tmp.id () == ID_infinity )
1460
1455
{
1461
1456
throw errort ().with_location (source_location)
1462
- << " expected constant expression , but got ` " << to_string (tmp) << ' \' ' ;
1457
+ << " expected integer constant , but got $ " ;
1463
1458
}
1464
1459
1465
1460
const auto &tmp_constant = to_constant_expr (tmp);
@@ -1515,6 +1510,9 @@ exprt verilog_typecheck_exprt::elaborate_constant_expression(exprt expr)
1515
1510
1516
1511
if (symbol.is_macro )
1517
1512
{
1513
+ // Elaborate recursively
1514
+ elaborate_symbol_rec (symbol.name );
1515
+
1518
1516
// A parameter or local parameter. Replace by its value.
1519
1517
return symbol.value ;
1520
1518
}
@@ -1524,12 +1522,12 @@ exprt verilog_typecheck_exprt::elaborate_constant_expression(exprt expr)
1524
1522
#if 0
1525
1523
status() << "READ " << identifier << " = " << to_string(value) << eom;
1526
1524
#endif
1527
-
1525
+
1528
1526
if (value.is_not_nil ())
1529
1527
{
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;
1533
1531
return tmp;
1534
1532
}
1535
1533
else
@@ -1671,6 +1669,34 @@ exprt verilog_typecheck_exprt::elaborate_constant_expression(exprt expr)
1671
1669
1672
1670
/* ******************************************************************\
1673
1671
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
+
1674
1700
Function: verilog_typecheck_exprt::elaborate_constant_system_function_call
1675
1701
1676
1702
Inputs:
0 commit comments