Skip to content

Commit 6044130

Browse files
committed
Move byte operator lowering to util
There is nothing solvers-specific taking place in this code. Moving this to util enable future use by expression simplification.
1 parent fce00aa commit 6044130

14 files changed

+46
-78
lines changed

src/solvers/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ SRC = $(BOOLEFORCE_SRC) \
140140
floatbv/float_bv.cpp \
141141
floatbv/float_utils.cpp \
142142
floatbv/float_approximation.cpp \
143-
lowering/byte_operators.cpp \
144143
lowering/functions.cpp \
145144
bdd/miniBDD/miniBDD.cpp \
146145
prop/bdd_expr.cpp \

src/solvers/flattening/boolbv_byte_extract.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ Author: Daniel Kroening, [email protected]
1414
#include <util/pointer_offset_size.h>
1515
#include <util/std_expr.h>
1616

17-
#include <solvers/lowering/expr_lowering.h>
18-
1917
bvt map_bv(const endianness_mapt &map, const bvt &src)
2018
{
2119
PRECONDITION(map.number_of_bits() == src.size());

src/solvers/flattening/boolbv_byte_update.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Author: Daniel Kroening, [email protected]
1212
#include <util/byte_operators.h>
1313
#include <util/invariant.h>
1414

15-
#include <solvers/lowering/expr_lowering.h>
16-
1715
bvt boolbvt::convert_byte_update(const byte_update_exprt &expr)
1816
{
1917
// if we update (from) an unbounded array, lower the expression as the array

src/solvers/flattening/boolbv_equality.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Author: Daniel Kroening, [email protected]
1010
#include <util/invariant.h>
1111
#include <util/std_expr.h>
1212

13-
#include <solvers/lowering/expr_lowering.h>
13+
#include "boolbv.h"
1414

1515
#include "boolbv.h"
1616

src/solvers/flattening/boolbv_index.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ Author: Daniel Kroening, [email protected]
1818
#include <util/simplify_expr.h>
1919
#include <util/std_expr.h>
2020

21-
#include <solvers/lowering/expr_lowering.h>
22-
2321
bvt boolbvt::convert_index(const index_exprt &expr)
2422
{
2523
const exprt &array=expr.array();

src/solvers/lowering/expr_lowering.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/solvers/smt2/smt2_conv.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Author: Daniel Kroening, [email protected]
3838
#include <solvers/flattening/boolbv_width.h>
3939
#include <solvers/flattening/c_bit_field_replacement_type.h>
4040
#include <solvers/floatbv/float_bv.h>
41-
#include <solvers/lowering/expr_lowering.h>
4241
#include <solvers/prop/literal_expr.h>
4342

4443
#include "smt2_tokenizer.h"

src/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "smt2_incremental_decision_procedure.h"
44

55
#include <util/arith_tools.h>
6+
#include <util/byte_operators.h>
67
#include <util/expr.h>
78
#include <util/namespace.h>
89
#include <util/nodiscard.h>
@@ -11,7 +12,6 @@
1112
#include <util/string_utils.h>
1213
#include <util/symbol.h>
1314

14-
#include <solvers/lowering/expr_lowering.h>
1515
#include <solvers/smt2_incremental/ast/smt_commands.h>
1616
#include <solvers/smt2_incremental/ast/smt_responses.h>
1717
#include <solvers/smt2_incremental/ast/smt_terms.h>

src/util/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SRC = arith_tools.cpp \
4646
json_stream.cpp \
4747
lispexpr.cpp \
4848
lispirep.cpp \
49+
lower_byte_operators.cpp \
4950
mathematical_expr.cpp \
5051
mathematical_types.cpp \
5152
memory_info.cpp \

src/util/byte_operators.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,30 @@ make_byte_update(const exprt &_op, const exprt &_offset, const exprt &_value);
166166
/// update expression.
167167
bool has_byte_operator(const exprt &src);
168168

169+
/// Rewrite a byte extract expression to more fundamental operations.
170+
/// \param src: Byte extract expression
171+
/// \param ns: Namespace
172+
/// \return Semantically equivalent expression such that the top-level
173+
/// expression no longer is a \ref byte_extract_exprt or
174+
/// \ref byte_update_exprt. Use \ref lower_byte_operators to also remove all
175+
/// byte operators from any operands of \p src.
176+
exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns);
177+
178+
/// Rewrite a byte update expression to more fundamental operations.
179+
/// \param src: Byte update expression
180+
/// \param ns: Namespace
181+
/// \return Semantically equivalent expression such that the top-level
182+
/// expression no longer is a \ref byte_extract_exprt or
183+
/// \ref byte_update_exprt. Use \ref lower_byte_operators to also remove all
184+
/// byte operators from any operands of \p src.
185+
exprt lower_byte_update(const byte_update_exprt &src, const namespacet &ns);
186+
187+
/// Rewrite an expression possibly containing byte-extract or -update
188+
/// expressions to more fundamental operations.
189+
/// \param src: Input expression
190+
/// \param ns: Namespace
191+
/// \return Semantically equivalent expression that does not contain any \ref
192+
/// byte_extract_exprt or \ref byte_update_exprt.
193+
exprt lower_byte_operators(const exprt &src, const namespacet &ns);
194+
169195
#endif // CPROVER_UTIL_BYTE_OPERATORS_H

src/solvers/lowering/byte_operators.cpp renamed to src/util/lower_byte_operators.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
#include <util/arith_tools.h>
10-
#include <util/bitvector_expr.h>
11-
#include <util/byte_operators.h>
12-
#include <util/c_types.h>
13-
#include <util/endianness_map.h>
14-
#include <util/expr_util.h>
15-
#include <util/namespace.h>
16-
#include <util/narrow.h>
17-
#include <util/pointer_offset_size.h>
18-
#include <util/simplify_expr.h>
19-
#include <util/string_constant.h>
20-
21-
#include "expr_lowering.h"
9+
#include "arith_tools.h"
10+
#include "bitvector_expr.h"
11+
#include "byte_operators.h"
12+
#include "c_types.h"
13+
#include "endianness_map.h"
14+
#include "expr_util.h"
15+
#include "namespace.h"
16+
#include "narrow.h"
17+
#include "pointer_offset_size.h"
18+
#include "simplify_expr.h"
19+
#include "string_constant.h"
2220

2321
#include <algorithm>
2422

unit/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ SRC += analyses/ai/ai.cpp \
9494
pointer-analysis/value_set.cpp \
9595
solvers/bdd/miniBDD/miniBDD.cpp \
9696
solvers/floatbv/float_utils.cpp \
97-
solvers/lowering/byte_operators.cpp \
9897
solvers/prop/bdd_expr.cpp \
9998
solvers/sat/external_sat.cpp \
10099
solvers/sat/satcheck_cadical.cpp \
@@ -159,6 +158,7 @@ SRC += analyses/ai/ai.cpp \
159158
util/json_array.cpp \
160159
util/json_object.cpp \
161160
util/lazy.cpp \
161+
util/lower_byte_operators.cpp \
162162
util/memory_info.cpp \
163163
util/message.cpp \
164164
util/optional.cpp \

unit/solvers/lowering/module_dependencies.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

unit/solvers/lowering/byte_operators.cpp renamed to unit/util/lower_byte_operators.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
77
\*******************************************************************/
88

9-
#include <testing-utils/use_catch.h>
10-
11-
#include <solvers/lowering/expr_lowering.h>
12-
139
#include <util/arith_tools.h>
1410
#include <util/byte_operators.h>
1511
#include <util/c_types.h>
@@ -24,7 +20,9 @@
2420
#include <util/string_constant.h>
2521
#include <util/symbol_table.h>
2622

27-
TEST_CASE("byte extract and bits", "[core][solvers][lowering][byte_extract]")
23+
#include <testing-utils/use_catch.h>
24+
25+
TEST_CASE("byte extract and bits", "[core][util][lowering][byte_extract]")
2826
{
2927
// this test does require a proper architecture to be set so that byte extract
3028
// uses adequate endianness
@@ -94,7 +92,7 @@ TEST_CASE("byte extract and bits", "[core][solvers][lowering][byte_extract]")
9492
}
9593
}
9694

97-
SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
95+
SCENARIO("byte_extract_lowering", "[core][util][lowering][byte_extract]")
9896
{
9997
// this test does require a proper architecture to be set so that byte extract
10098
// uses adequate endianness
@@ -362,7 +360,7 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
362360
}
363361
}
364362

365-
SCENARIO("byte_update_lowering", "[core][solvers][lowering][byte_update]")
363+
SCENARIO("byte_update_lowering", "[core][util][lowering][byte_update]")
366364
{
367365
// this test does require a proper architecture to be set so that byte extract
368366
// uses adequate endianness

0 commit comments

Comments
 (0)