@@ -1776,3 +1776,77 @@ TEST_CASE(
17761776 CHECK (test.convert (assignment) == expected);
17771777 }
17781778}
1779+
1780+ TEST_CASE (
1781+ " expr to smt conversion for bswap_exprt expressions" ,
1782+ " [core][smt2_incremental]" )
1783+ {
1784+ auto test =
1785+ expr_to_smt_conversion_test_environmentt::make (test_archt::x86_64);
1786+ SECTION (" 16-bit byte swap" )
1787+ {
1788+ const symbol_exprt operand{" my_value" , unsignedbv_typet{16 }};
1789+ const bswap_exprt byte_swap{operand, 8 , unsignedbv_typet{16 }};
1790+ INFO (" Expression being converted: " + byte_swap.pretty (2 , 0 ));
1791+ const smt_identifier_termt operand_smt{
1792+ " my_value" , smt_bit_vector_sortt{16 }};
1793+ // For 16-bit bswap, we extract [7:0] and [15:8], then concat in reverse
1794+ // order
1795+ // concat([7:0], [15:8]) puts [7:0] as most significant
1796+ const smt_termt expected = smt_bit_vector_theoryt::concat (
1797+ smt_bit_vector_theoryt::extract (7 , 0 )(operand_smt),
1798+ smt_bit_vector_theoryt::extract (15 , 8 )(operand_smt));
1799+ CHECK (test.convert (byte_swap) == expected);
1800+ }
1801+ SECTION (" 32-bit byte swap" )
1802+ {
1803+ const symbol_exprt operand{" my_value" , unsignedbv_typet{32 }};
1804+ const bswap_exprt byte_swap{operand, 8 , unsignedbv_typet{32 }};
1805+ INFO (" Expression being converted: " + byte_swap.pretty (2 , 0 ));
1806+ const smt_identifier_termt operand_smt{
1807+ " my_value" , smt_bit_vector_sortt{32 }};
1808+ // For 32-bit bswap, we extract 4 bytes and concat in reverse order
1809+ const smt_termt expected = smt_bit_vector_theoryt::concat (
1810+ smt_bit_vector_theoryt::concat (
1811+ smt_bit_vector_theoryt::concat (
1812+ smt_bit_vector_theoryt::extract (7 , 0 )(operand_smt),
1813+ smt_bit_vector_theoryt::extract (15 , 8 )(operand_smt)),
1814+ smt_bit_vector_theoryt::extract (23 , 16 )(operand_smt)),
1815+ smt_bit_vector_theoryt::extract (31 , 24 )(operand_smt));
1816+ CHECK (test.convert (byte_swap) == expected);
1817+ }
1818+ SECTION (" 64-bit byte swap" )
1819+ {
1820+ const symbol_exprt operand{" my_value" , unsignedbv_typet{64 }};
1821+ const bswap_exprt byte_swap{operand, 8 , unsignedbv_typet{64 }};
1822+ INFO (" Expression being converted: " + byte_swap.pretty (2 , 0 ));
1823+ const smt_identifier_termt operand_smt{
1824+ " my_value" , smt_bit_vector_sortt{64 }};
1825+ // For 64-bit bswap, we extract 8 bytes and concat in reverse order
1826+ const smt_termt expected = smt_bit_vector_theoryt::concat (
1827+ smt_bit_vector_theoryt::concat (
1828+ smt_bit_vector_theoryt::concat (
1829+ smt_bit_vector_theoryt::concat (
1830+ smt_bit_vector_theoryt::concat (
1831+ smt_bit_vector_theoryt::concat (
1832+ smt_bit_vector_theoryt::concat (
1833+ smt_bit_vector_theoryt::extract (7 , 0 )(operand_smt),
1834+ smt_bit_vector_theoryt::extract (15 , 8 )(operand_smt)),
1835+ smt_bit_vector_theoryt::extract (23 , 16 )(operand_smt)),
1836+ smt_bit_vector_theoryt::extract (31 , 24 )(operand_smt)),
1837+ smt_bit_vector_theoryt::extract (39 , 32 )(operand_smt)),
1838+ smt_bit_vector_theoryt::extract (47 , 40 )(operand_smt)),
1839+ smt_bit_vector_theoryt::extract (55 , 48 )(operand_smt)),
1840+ smt_bit_vector_theoryt::extract (63 , 56 )(operand_smt));
1841+ CHECK (test.convert (byte_swap) == expected);
1842+ }
1843+ SECTION (" Single byte (no swap needed)" )
1844+ {
1845+ const symbol_exprt operand{" my_value" , unsignedbv_typet{8 }};
1846+ const bswap_exprt byte_swap{operand, 8 , unsignedbv_typet{8 }};
1847+ INFO (" Expression being converted: " + byte_swap.pretty (2 , 0 ));
1848+ const smt_identifier_termt operand_smt{" my_value" , smt_bit_vector_sortt{8 }};
1849+ // Single byte should return operand unchanged
1850+ CHECK (test.convert (byte_swap) == operand_smt);
1851+ }
1852+ }
0 commit comments