@@ -60,11 +60,13 @@ Function: output_verilog_netlistt::is_symbol
60
60
61
61
bool output_verilog_netlistt::is_symbol (const exprt &expr) const
62
62
{
63
- if (expr.id ()==ID_extractbit ||
64
- expr.id ()==ID_extractbits)
63
+ if (expr.id () == ID_extractbit)
65
64
{
66
- assert (expr.operands ().size ()>=1 );
67
- return is_symbol (expr.op0 ());
65
+ return is_symbol (to_extractbit_expr (expr).src ());
66
+ }
67
+ else if (expr.id () == ID_extractbits)
68
+ {
69
+ return is_symbol (to_extractbits_expr (expr).src ());
68
70
}
69
71
else if (expr.id ()==ID_symbol)
70
72
{
@@ -182,10 +184,9 @@ void output_verilog_netlistt::assign_symbol(
182
184
{
183
185
assert (rhs.type ().id ()==ID_bool);
184
186
assert (lhs.type ().id ()==ID_bool);
185
- assert (rhs.operands ().size ()==1 );
186
187
187
- std::string tmp= make_symbol_expr (rhs. op0 (), " " );
188
-
188
+ std::string tmp = make_symbol_expr (to_not_expr ( rhs). op (), " " );
189
+
189
190
out << " " << rhs.id () << " g" << (++count) << " ("
190
191
<< symbol_string (lhs) << tmp
191
192
<< " );" << ' \n ' << ' \n ' ;
@@ -195,23 +196,23 @@ void output_verilog_netlistt::assign_symbol(
195
196
rhs.id ()==ID_mult)
196
197
{
197
198
if (rhs.operands ().size ()==1 )
198
- assign_symbol (lhs, rhs.op0 ());
199
+ assign_symbol (lhs, to_multi_ary_expr ( rhs) .op0 ());
199
200
else
200
201
{
201
202
std::string tmp;
202
203
203
204
assert (rhs.operands ().size ()!=0 );
204
205
205
206
if (rhs.operands ().size ()==2 )
206
- tmp= make_symbol_expr (rhs.op0 (), " " )+ " , " +
207
- make_symbol_expr (rhs.op1 (), " " );
207
+ tmp = make_symbol_expr (to_multi_ary_expr ( rhs) .op0 (), " " ) + " , " +
208
+ make_symbol_expr (to_multi_ary_expr ( rhs) .op1 (), " " );
208
209
else
209
210
{
210
211
exprt tmp_rhs (rhs);
211
212
tmp_rhs.operands ().erase (tmp_rhs.operands ().begin ());
212
-
213
- tmp= make_symbol_expr (rhs.op0 (), " " )+ " , " +
214
- make_symbol_expr (tmp_rhs, " " );
213
+
214
+ tmp = make_symbol_expr (to_multi_ary_expr ( rhs) .op0 (), " " ) + " , " +
215
+ make_symbol_expr (tmp_rhs, " " );
215
216
}
216
217
217
218
out << " RTL_" ;
@@ -275,19 +276,18 @@ void output_verilog_rtlt::assign_symbol(
275
276
{
276
277
if (lhs.id ()==ID_extractbits)
277
278
{
278
- assert (lhs. operands (). size ()== 3 );
279
+ auto &lhs_extractbits = to_extractbits_expr (lhs);
279
280
280
281
// redundant?
281
282
mp_integer from, to;
282
283
283
284
if (
284
- !to_integer_non_constant (lhs. op1 (), to) &&
285
- !to_integer_non_constant (lhs. op2 (), from))
285
+ !to_integer_non_constant (lhs_extractbits. upper (), to) &&
286
+ !to_integer_non_constant (lhs_extractbits. lower (), from))
286
287
{
287
- if (from==0 &&
288
- to==width (lhs.op0 ().type ())-1 )
288
+ if (from == 0 && to == width (lhs_extractbits.src ().type ()) - 1 )
289
289
{
290
- assign_symbol (lhs. op0 (), rhs);
290
+ assign_symbol (lhs_extractbits. src (), rhs);
291
291
return ;
292
292
}
293
293
}
@@ -307,7 +307,7 @@ void output_verilog_rtlt::assign_symbol(
307
307
throw 0 ;
308
308
}
309
309
310
- symbol_expr= lhs. op0 ();
310
+ symbol_expr = to_extractbit_expr ( lhs). src ();
311
311
}
312
312
else if (lhs.id ()==ID_extractbits)
313
313
{
@@ -318,7 +318,7 @@ void output_verilog_rtlt::assign_symbol(
318
318
throw 0 ;
319
319
}
320
320
321
- symbol_expr= lhs. op0 ();
321
+ symbol_expr = to_extractbits_expr ( lhs). src ();
322
322
}
323
323
324
324
if (symbol_expr.id ()!=ID_symbol &&
@@ -342,8 +342,10 @@ void output_verilog_rtlt::assign_symbol(
342
342
343
343
// replace the next_symbol
344
344
exprt tmp (lhs);
345
- if (tmp.id ()==ID_extractbit || tmp.id ()==ID_extractbits)
346
- tmp.op0 ().id (ID_symbol);
345
+ if (tmp.id () == ID_extractbit)
346
+ to_extractbit_expr (tmp).src ().id (ID_symbol);
347
+ else if (tmp.id () == ID_extractbits)
348
+ to_extractbits_expr (tmp).src ().id (ID_symbol);
347
349
else
348
350
tmp.id (ID_symbol);
349
351
@@ -406,62 +408,58 @@ std::string output_verilog_netlistt::symbol_string(const exprt &expr)
406
408
407
409
if (expr.id ()==ID_extractbit)
408
410
{
409
- assert (expr.operands ().size ()==2 );
411
+ auto &src = to_extractbit_expr (expr).src ();
412
+ auto &index = to_extractbit_expr (expr).index ();
410
413
411
414
mp_integer i;
412
- if (to_integer_non_constant (expr. op1 () , i))
415
+ if (to_integer_non_constant (index , i))
413
416
{
414
- error ().source_location =expr.op1 ().find_source_location ();
415
- error () << " failed to convert constant "
416
- << expr.op1 ().pretty () << eom;
417
+ error ().source_location = index.find_source_location ();
418
+ error () << " failed to convert constant " << index.pretty () << eom;
417
419
throw 0 ;
418
420
}
419
421
420
- std::size_t offset= atoi (expr. op0 () .type ().get (" #offset" ).c_str ());
421
-
422
+ std::size_t offset = atoi (src .type ().get (" #offset" ).c_str ());
423
+
422
424
assert (i>=offset);
423
-
424
- return
425
- symbol_string (expr.op0 ())+
426
- ' [' +integer2string (i-offset)+' ]' ;
425
+
426
+ return symbol_string (src) + ' [' + integer2string (i - offset) + ' ]' ;
427
427
}
428
428
else if (expr.id ()==ID_extractbits)
429
429
{
430
- assert (expr.operands ().size ()==3 );
430
+ auto &src = to_extractbits_expr (expr).src ();
431
+ auto &upper = to_extractbits_expr (expr).upper ();
432
+ auto &lower = to_extractbits_expr (expr).lower ();
431
433
432
434
mp_integer from;
433
- if (to_integer_non_constant (expr. op1 () , from))
435
+ if (to_integer_non_constant (upper , from))
434
436
{
435
- error ().source_location =expr.op1 ().find_source_location ();
436
- error () << " failed to convert constant "
437
- << expr.op1 ().pretty () << eom;
437
+ error ().source_location = upper.find_source_location ();
438
+ error () << " failed to convert constant " << upper.pretty () << eom;
438
439
throw 0 ;
439
440
}
440
441
441
442
mp_integer to;
442
- if (to_integer_non_constant (expr. operands ()[ 2 ] , to))
443
+ if (to_integer_non_constant (lower , to))
443
444
{
444
- error ().source_location =expr.operands ()[2 ].find_source_location ();
445
- error () << " failed to convert constant "
446
- << expr.operands ()[2 ].pretty () << eom;
445
+ error ().source_location = lower.find_source_location ();
446
+ error () << " failed to convert constant " << lower.pretty () << eom;
447
447
throw 0 ;
448
448
}
449
449
450
- std::size_t offset= atoi (expr. op0 () .type ().get (" #offset" ).c_str ());
451
-
450
+ std::size_t offset = atoi (src .type ().get (" #offset" ).c_str ());
451
+
452
452
assert (from>=offset);
453
453
assert (to>=offset);
454
454
455
455
assert (to>=from);
456
-
457
- return
458
- symbol_string (expr.op0 ())+
459
- ' [' +integer2string (to-offset)+
460
- ' :' +integer2string (from-offset)+' ]' ;
456
+
457
+ return symbol_string (src) + ' [' + integer2string (to - offset) + ' :' +
458
+ integer2string (from - offset) + ' ]' ;
461
459
}
462
460
else if (expr.id ()==ID_symbol)
463
461
{
464
- const irep_idt &identifier= expr. get (ID_identifier );
462
+ const irep_idt &identifier = to_symbol_expr ( expr). get_identifier ( );
465
463
symbol_tablet::symbolst::const_iterator s_it=
466
464
symbol_table.symbols .find (identifier);
467
465
@@ -885,8 +883,8 @@ void output_verilog_baset::invariant(const exprt &expr)
885
883
}
886
884
else if (expr.id ()==ID_equal)
887
885
{
888
- assert (expr. operands (). size ()== 2 );
889
- assign_symbol (expr. op0 (), expr. op1 ());
886
+ auto &equal_expr = to_equal_expr (expr);
887
+ assign_symbol (equal_expr. lhs (), equal_expr. rhs ());
890
888
}
891
889
else
892
890
{
@@ -941,9 +939,9 @@ void output_verilog_baset::next_state(const exprt &expr)
941
939
return ;
942
940
943
941
assert (expr.id ()==ID_equal);
944
- assert (expr.operands ().size ()==2 );
945
942
946
- assign_symbol (expr.op0 (), expr.op1 ());
943
+ auto &equal_expr = to_equal_expr (expr);
944
+ assign_symbol (equal_expr.lhs (), equal_expr.rhs ());
947
945
}
948
946
949
947
/* ******************************************************************\
0 commit comments