@@ -531,6 +531,93 @@ inline extractbits_exprt &to_extractbits_expr(exprt &expr)
531531 return ret;
532532}
533533
534+ // / \brief Replaces a sub-range of a bit-vector operand
535+ class update_bit_exprt : public expr_protectedt
536+ {
537+ public:
538+ // / Replaces the bit [\p _index] from \p _src to produce a result of
539+ // / the same type as \p _src. The index counts from the
540+ // / least-significant bit. Updates outside of the range of \p _src
541+ // / yield an expression equal to \p _src.
542+ update_bit_exprt (exprt _src, exprt _index, exprt _new_value)
543+ : expr_protectedt(
544+ ID_update_bit,
545+ _src.type(),
546+ {_src, std::move (_index), std::move (_new_value)})
547+ {
548+ PRECONDITION (new_value ().type ().id () == ID_bool);
549+ }
550+
551+ update_bit_exprt (exprt _src, const std::size_t _index, exprt _new_value);
552+
553+ exprt &src ()
554+ {
555+ return op0 ();
556+ }
557+
558+ exprt &index ()
559+ {
560+ return op1 ();
561+ }
562+
563+ exprt &new_value ()
564+ {
565+ return op2 ();
566+ }
567+
568+ const exprt &src () const
569+ {
570+ return op0 ();
571+ }
572+
573+ const exprt &index () const
574+ {
575+ return op1 ();
576+ }
577+
578+ const exprt &new_value () const
579+ {
580+ return op2 ();
581+ }
582+
583+ static void check (
584+ const exprt &expr,
585+ const validation_modet vm = validation_modet::INVARIANT)
586+ {
587+ validate_operands (expr, 3 , " update_bit must have three operands" );
588+ }
589+
590+ // / A lowering to masking, shifting, or.
591+ exprt lower () const ;
592+ };
593+
594+ template <>
595+ inline bool can_cast_expr<update_bit_exprt>(const exprt &base)
596+ {
597+ return base.id () == ID_update_bit;
598+ }
599+
600+ // / \brief Cast an exprt to an \ref update_bit_exprt
601+ // /
602+ // / \a expr must be known to be \ref update_bit_exprt.
603+ // /
604+ // / \param expr: Source expression
605+ // / \return Object of type \ref update_bit_exprt
606+ inline const update_bit_exprt &to_update_bit_expr (const exprt &expr)
607+ {
608+ PRECONDITION (expr.id () == ID_update_bit);
609+ update_bit_exprt::check (expr);
610+ return static_cast <const update_bit_exprt &>(expr);
611+ }
612+
613+ // / \copydoc to_update_bit_expr(const exprt &)
614+ inline update_bit_exprt &to_update_bit_expr (exprt &expr)
615+ {
616+ PRECONDITION (expr.id () == ID_update_bit);
617+ update_bit_exprt::check (expr);
618+ return static_cast <update_bit_exprt &>(expr);
619+ }
620+
534621// / \brief Replaces a sub-range of a bit-vector operand
535622class update_bits_exprt : public expr_protectedt
536623{
0 commit comments