@@ -282,6 +282,7 @@ exprt smt2_convt::get(const exprt &expr) const
282
282
283
283
if (it!=identifier_map.end ())
284
284
return it->second .value ;
285
+ return expr;
285
286
}
286
287
else if (expr.id ()==ID_nondet_symbol)
287
288
{
@@ -472,31 +473,50 @@ constant_exprt smt2_convt::parse_literal(
472
473
exprt smt2_convt::parse_array (
473
474
const irept &src,
474
475
const array_typet &type)
476
+ {
477
+ std::unordered_map<size_t , exprt> operands_map;
478
+ walk_array_tree (&operands_map, src, type);
479
+ exprt::operandst operands;
480
+ size_t i = 0 ;
481
+ auto found_op = operands_map.find (i);
482
+ while (found_op != operands_map.end ())
483
+ {
484
+ operands.emplace_back (found_op->second );
485
+ i++;
486
+ found_op = operands_map.find (i);
487
+ }
488
+ return array_exprt (operands, type);
489
+ }
490
+
491
+ void smt2_convt::walk_array_tree (
492
+ std::unordered_map<size_t , exprt> *operands_map,
493
+ const irept &src,
494
+ const array_typet &type)
475
495
{
476
496
if (src.get_sub ().size ()==4 && src.get_sub ()[0 ].id ()==" store" )
477
497
{
498
+ // This is the SMT syntax being parsed here
478
499
// (store array index value)
479
- if (src.get_sub ().size ()!=4 )
480
- return nil_exprt ();
481
-
482
- exprt array=parse_array (src.get_sub ()[1 ], type);
483
- exprt index=parse_rec (src.get_sub ()[2 ], type.size ().type ());
484
- exprt value=parse_rec (src.get_sub ()[3 ], type.subtype ());
485
-
486
- return with_exprt (array, index, value);
500
+ // Recurse
501
+ walk_array_tree (operands_map, src.get_sub ()[1 ], type);
502
+ const auto index_expr = parse_rec (src.get_sub ()[2 ], type.size ().type ());
503
+ const constant_exprt index_constant = to_constant_expr (index_expr);
504
+ mp_integer tempint;
505
+ bool failure = to_integer (index_constant, tempint);
506
+ if (failure)
507
+ return ;
508
+ size_t index = tempint.to_ulong ();
509
+ exprt value = parse_rec (src.get_sub ()[3 ], type.subtype ());
510
+ operands_map->emplace (index, value);
487
511
}
488
- else if (src.get_sub ().size ()==2 &&
489
- src.get_sub ()[0 ].get_sub ().size ()==3 &&
490
- src.get_sub ()[0 ].get_sub ()[0 ].id ()==" as" &&
491
- src.get_sub ()[0 ].get_sub ()[1 ].id ()==" const" )
512
+ else if (src.get_sub ().size () == 3 && src.get_sub ()[0 ].id () == " let" )
492
513
{
493
- // This is produced by Z3.
494
- // ((as const (Array (_ BitVec 64) (_ BitVec 8))) #x00)))
495
- exprt value=parse_rec (src.get_sub ()[1 ], type.subtype ());
496
- return array_of_exprt (value, type);
514
+ // This is produced by Z3
515
+ // (let (....) (....))
516
+ walk_array_tree (
517
+ operands_map, src.get_sub ()[1 ].get_sub ()[0 ].get_sub ()[1 ], type);
518
+ walk_array_tree (operands_map, src.get_sub ()[2 ], type);
497
519
}
498
- else
499
- return nil_exprt ();
500
520
}
501
521
502
522
exprt smt2_convt::parse_union (
0 commit comments