@@ -1809,6 +1809,63 @@ void smt2_convt::convert_expr(const exprt &expr)
1809
1809
" smt2_convt::convert_expr: `" +expr.id_string ()+
1810
1810
" ' is not yet supported" );
1811
1811
}
1812
+ else if (expr.id () == ID_bswap)
1813
+ {
1814
+ if (expr.operands ().size () != 1 )
1815
+ INVALIDEXPR (" bswap gets one operand" );
1816
+
1817
+ if (expr.op0 ().type () != expr.type ())
1818
+ INVALIDEXPR (" bswap gets one operand with same type" );
1819
+
1820
+ // first 'let' the operand
1821
+ out << " (let ((bswap_op " ;
1822
+ convert_expr (expr.op0 ());
1823
+ out << " )) " ;
1824
+
1825
+ if (expr.type ().id () == ID_signedbv || expr.type ().id () == ID_unsignedbv)
1826
+ {
1827
+ const std::size_t width = to_bitvector_type (expr.type ()).get_width ();
1828
+
1829
+ // width must be multiple of bytes
1830
+ if (width % 8 != 0 )
1831
+ INVALIDEXPR (" bswap must get bytes" );
1832
+
1833
+ const std::size_t bytes = width / 8 ;
1834
+
1835
+ if (bytes <= 1 )
1836
+ out << " bswap_op" ;
1837
+ else
1838
+ {
1839
+ // do a parallel 'let' for each byte
1840
+ out << " (let (" ;
1841
+
1842
+ for (std::size_t byte = 0 ; byte < bytes; byte++)
1843
+ {
1844
+ if (byte != 0 )
1845
+ out << ' ' ;
1846
+ out << " (bswap_byte_" << byte << ' ' ;
1847
+ out << " ((_ extract " << (byte * 8 + 7 ) << " " << (byte * 8 )
1848
+ << " ) bswap_op)" ;
1849
+ out << ' )' ;
1850
+ }
1851
+
1852
+ out << " ) " ;
1853
+
1854
+ // now stitch back together with 'concat'
1855
+ out << " (concat" ;
1856
+
1857
+ for (std::size_t byte = 0 ; byte < bytes; byte++)
1858
+ out << " bswap_byte_" << byte;
1859
+
1860
+ out << ' )' ; // concat
1861
+ out << ' )' ; // let bswap_byte_*
1862
+ }
1863
+ }
1864
+ else
1865
+ UNEXPECTEDCASE (" bswap must get bitvector operand" );
1866
+
1867
+ out << ' )' ; // let bswap_op
1868
+ }
1812
1869
else
1813
1870
UNEXPECTEDCASE (
1814
1871
" smt2_convt::convert_expr: `" +expr.id_string ()+" ' is unsupported" );
0 commit comments