@@ -6,20 +6,22 @@ Author: Daniel Kroening, kroening@kroening.com
66
77\*******************************************************************/
88
9- #include < cstdlib>
10- #include < iostream>
9+ #include < verilog/expr2verilog_class.h>
1110
1211#include < util/ebmc_util.h>
12+ #include < util/mathematical_expr.h>
1313#include < util/simplify_expr.h>
1414
15+ #include < verilog/expr2verilog.h>
1516#include < verilog/verilog_language.h>
16- #include < verilog/verilog_typecheck.h>
1717#include < verilog/verilog_synthesis.h>
18- #include < verilog/expr2verilog_class.h>
19- #include < verilog/expr2verilog.h>
18+ #include < verilog/verilog_typecheck.h>
2019
2120#include " output_verilog.h"
2221
22+ #include < cstdlib>
23+ #include < iostream>
24+
2325/* ******************************************************************\
2426
2527Function: output_verilog_baset::width
@@ -41,8 +43,8 @@ std::size_t output_verilog_baset::width(const typet &type)
4143 return to_bitvector_type (type).get_width ();
4244
4345 std::cerr << type.id () << ' \n ' ;
44- assert (false );
45-
46+ PRECONDITION (false );
47+
4648 return 0 ; // not reached
4749}
4850
@@ -165,8 +167,10 @@ void output_verilog_netlistt::assign_symbol(
165167 rhs.id ()==ID_xor ||
166168 rhs.id ()==ID_xnor)
167169 {
168- assert (rhs.type ().id ()==ID_bool);
169- assert (lhs.type ().id ()==ID_bool);
170+ DATA_INVARIANT (
171+ rhs.type ().id () == ID_bool, " boolean equivalence rhs must be boolean" );
172+ DATA_INVARIANT (
173+ lhs.type ().id () == ID_bool, " boolean equivalence lhs must be boolean" );
170174
171175 std::string tmp;
172176
@@ -182,8 +186,10 @@ void output_verilog_netlistt::assign_symbol(
182186 }
183187 else if (rhs.id ()==ID_not)
184188 {
185- assert (rhs.type ().id ()==ID_bool);
186- assert (lhs.type ().id ()==ID_bool);
189+ DATA_INVARIANT (
190+ rhs.type ().id () == ID_bool, " boolean equivalence rhs must be boolean" );
191+ DATA_INVARIANT (
192+ lhs.type ().id () == ID_bool, " boolean equivalence lhs must be boolean" );
187193
188194 std::string tmp = make_symbol_expr (to_not_expr (rhs).op (), " " );
189195
@@ -201,7 +207,8 @@ void output_verilog_netlistt::assign_symbol(
201207 {
202208 std::string tmp;
203209
204- assert (rhs.operands ().size ()!=0 );
210+ DATA_INVARIANT (
211+ rhs.operands ().size () != 0 , " multi-ary operator must have operand" );
205212
206213 if (rhs.operands ().size ()==2 )
207214 tmp = make_symbol_expr (to_multi_ary_expr (rhs).op0 (), " " ) + " , " +
@@ -420,7 +427,7 @@ std::string output_verilog_netlistt::symbol_string(const exprt &expr)
420427
421428 std::size_t offset = atoi (src.type ().get (" #offset" ).c_str ());
422429
423- assert (i>= offset);
430+ DATA_INVARIANT (i >= offset, " extractbit index must be in range " );
424431
425432 return symbol_string (src) + ' [' + integer2string (i - offset) + ' ]' ;
426433 }
@@ -440,10 +447,10 @@ std::string output_verilog_netlistt::symbol_string(const exprt &expr)
440447 auto to = from + width (expr.type ());
441448 std::size_t offset = atoi (src.type ().get (" #offset" ).c_str ());
442449
443- assert (from>= offset);
444- assert (to>= offset);
445-
446- assert (to>= from);
450+ DATA_INVARIANT (from >= offset, " extractbits index must be in range " );
451+ DATA_INVARIANT (to >= offset, " extractbits index must be in range " );
452+
453+ DATA_INVARIANT (to >= from, " extractbits index must be in range " );
447454
448455 return symbol_string (src) + ' [' + integer2string (to - offset) + ' :' +
449456 integer2string (from - offset) + ' ]' ;
@@ -804,7 +811,7 @@ Function: output_verilog_baset::module_instantiation
804811
805812void output_verilog_baset::module_instantiation (const exprt &expr)
806813{
807- assert (expr.type ().id ()== ID_bool);
814+ PRECONDITION (expr.type ().id () == ID_bool);
808815
809816 std::list<std::string> argument_strings;
810817
@@ -852,8 +859,8 @@ Function: output_verilog_baset::invariant
852859
853860void output_verilog_baset::invariant (const exprt &expr)
854861{
855- assert (expr.type ().id ()== ID_bool);
856-
862+ PRECONDITION (expr.type ().id () == ID_bool);
863+
857864 if (expr.id ()==ID_and)
858865 {
859866 forall_operands (it, expr)
@@ -894,10 +901,9 @@ Function: output_verilog_baset::invariants
894901
895902void output_verilog_baset::invariants (const symbolt &symbol)
896903{
897- assert (symbol.value .id ()==ID_trans &&
898- symbol.value .operands ().size ()==3 );
904+ PRECONDITION (symbol.value .id () == ID_trans);
899905
900- invariant (to_ternary_expr (symbol.value ).op0 ());
906+ invariant (to_trans_expr (symbol.value ).invar ());
901907}
902908
903909/* ******************************************************************\
@@ -914,8 +920,8 @@ Function: output_verilog_baset::next_state
914920
915921void output_verilog_baset::next_state (const exprt &expr)
916922{
917- assert (expr.type ().id ()== ID_bool);
918-
923+ PRECONDITION (expr.type ().id () == ID_bool);
924+
919925 if (expr.id ()==ID_and)
920926 {
921927 forall_operands (it, expr)
@@ -925,7 +931,8 @@ void output_verilog_baset::next_state(const exprt &expr)
925931 else if (expr.is_true ())
926932 return ;
927933
928- assert (expr.id ()==ID_equal);
934+ DATA_INVARIANT (
935+ expr.id () == ID_equal, " next-state constraints must be equality" );
929936
930937 auto &equal_expr = to_equal_expr (expr);
931938 assign_symbol (equal_expr.lhs (), equal_expr.rhs ());
@@ -945,10 +952,9 @@ Function: output_verilog_baset::next_state
945952
946953void output_verilog_baset::next_state (const symbolt &symbol)
947954{
948- assert (symbol.value .id ()==ID_trans &&
949- symbol.value .operands ().size ()==3 );
955+ PRECONDITION (symbol.value .id () == ID_trans);
950956
951- next_state (symbol.value . operands ()[ 2 ] );
957+ next_state (to_trans_expr ( symbol.value ). trans () );
952958}
953959
954960/* ******************************************************************\
0 commit comments