1717
1818#include " verilog_expr.h"
1919#include " verilog_types.h"
20+ #include " aval_bval_encoding.h"
2021
2122static constant_exprt
2223countones (const constant_exprt &expr, const namespacet &ns)
@@ -33,6 +34,18 @@ countones(const constant_exprt &expr, const namespacet &ns)
3334 return to_constant_expr (simplified);
3435}
3536
37+ // / constant folding for $isunknown
38+ static constant_exprt
39+ isunknown (const constant_exprt &expr, const namespacet &ns)
40+ {
41+ auto bval = ::bval (expr);
42+ CHECK_RETURN (bval.is_constant ());
43+ if (numeric_cast_v<mp_integer>(to_constant_expr (bval)) == 0 )
44+ return false_exprt{};
45+ else
46+ return true_exprt{};
47+ }
48+
3649static exprt verilog_simplifier_rec (exprt expr, const namespacet &ns)
3750{
3851 // Remember the Verilog type.
@@ -129,6 +142,20 @@ static exprt verilog_simplifier_rec(exprt expr, const namespacet &ns)
129142 ops.push_back (replication.op ());
130143 expr = concatenation_exprt{ops, expr.type ()};
131144 }
145+ else if (expr.id () == ID_function_call)
146+ {
147+ auto &call = to_function_call_expr (expr);
148+ if (call.function ().id () == ID_symbol)
149+ {
150+ auto identifier = to_symbol_expr (call.function ()).get_identifier ();
151+ if (identifier == " $isunknown" )
152+ {
153+ DATA_INVARIANT (call.arguments ().size () == 1 , " $isunknown gets one argument" );
154+ if (call.arguments ()[0 ].is_constant ())
155+ expr = isunknown (to_constant_expr (call.arguments ()[0 ]), ns);
156+ }
157+ }
158+ }
132159
133160 // We fall back to the simplifier to approximate
134161 // the standard's definition of 'constant expression'.
0 commit comments