@@ -531,6 +531,92 @@ 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_bits_exprt : public expr_protectedt
536+ {
537+ public:
538+ // / Replace the bits [\p _index .. \p _index + size] from \p _src
539+ // / where size is the width of \p _new_value to produce a result of
540+ // / the same type as \p _src. The index counts from the
541+ // / least-significant bit.
542+ update_bits_exprt (exprt _src, exprt _index, exprt _new_value)
543+ : expr_protectedt(
544+ ID_update_bits,
545+ _src.type(),
546+ {_src, std::move (_index), std::move (_new_value)})
547+ {
548+ }
549+
550+ update_bits_exprt (exprt _src, const std::size_t _index, exprt _new_value);
551+
552+ exprt &src ()
553+ {
554+ return op0 ();
555+ }
556+
557+ exprt &index ()
558+ {
559+ return op1 ();
560+ }
561+
562+ exprt &new_value ()
563+ {
564+ return op2 ();
565+ }
566+
567+ const exprt &src () const
568+ {
569+ return op0 ();
570+ }
571+
572+ const exprt &index () const
573+ {
574+ return op1 ();
575+ }
576+
577+ const exprt &new_value () const
578+ {
579+ return op2 ();
580+ }
581+
582+ static void check (
583+ const exprt &expr,
584+ const validation_modet vm = validation_modet::INVARIANT)
585+ {
586+ validate_operands (expr, 3 , " update_bits must have three operands" );
587+ }
588+
589+ // / A lowering to masking, shifting, or.
590+ exprt lower () const ;
591+ };
592+
593+ template <>
594+ inline bool can_cast_expr<update_bits_exprt>(const exprt &base)
595+ {
596+ return base.id () == ID_update_bits;
597+ }
598+
599+ // / \brief Cast an exprt to an \ref update_bits_exprt
600+ // /
601+ // / \a expr must be known to be \ref update_bits_exprt.
602+ // /
603+ // / \param expr: Source expression
604+ // / \return Object of type \ref update_bits_exprt
605+ inline const update_bits_exprt &to_update_bits_expr (const exprt &expr)
606+ {
607+ PRECONDITION (expr.id () == ID_update_bits);
608+ update_bits_exprt::check (expr);
609+ return static_cast <const update_bits_exprt &>(expr);
610+ }
611+
612+ // / \copydoc to_update_bits_expr(const exprt &)
613+ inline update_bits_exprt &to_update_bits_expr (exprt &expr)
614+ {
615+ PRECONDITION (expr.id () == ID_update_bits);
616+ update_bits_exprt::check (expr);
617+ return static_cast <update_bits_exprt &>(expr);
618+ }
619+
534620// / \brief Bit-vector replication
535621class replication_exprt : public binary_exprt
536622{
0 commit comments