Skip to content

Commit ac0aaed

Browse files
committed
Improve creating strategy solvers and invariants
Instead of allocating strategy solvers and abstract values in ssa_analyzer based on CLI options, make domains responsible for allocating adequate solvers. Each abstract domain must implement methods new_value and new_strategy_solver that return a unique_ptr to a new abstract value and new strategy solver for the domain, respectively. These methods are then called from ssa_analyzer, which simplifies the code a lot. This change required some unification of interfaces of strategy solver constructors.
1 parent 6e67bf5 commit ac0aaed

32 files changed

+219
-172
lines changed

src/2ls/dynamic_cfg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Peter Schrammel
1414

1515
#include <util/std_expr.h>
1616
#include <util/graph.h>
17+
#include <util/i2string.h>
1718
#include <goto-programs/goto_program.h>
1819

1920
#include <ssa/ssa_unwinder.h>

src/domains/domain.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ Author: Peter Schrammel
2121
#include <util/replace_expr.h>
2222
#include <util/namespace.h>
2323
#include <solvers/refinement/bv_refinement.h>
24+
#include <memory>
2425
#include "symbolic_path.h"
26+
#include "incremental_solver.h"
2527

2628
// Forward declaration - real is in template_generator_base.h
2729
class template_generator_baset;
30+
class strategy_solver_baset;
2831

2932
class local_SSAt;
3033

@@ -104,6 +107,14 @@ class domaint
104107
basic_valuet basic_value;
105108
};
106109

110+
/// Create a new empty abstract value for the domain
111+
virtual std::unique_ptr<valuet> new_value()=0;
112+
/// Create a new strategy solver for the domain
113+
virtual std::unique_ptr<strategy_solver_baset> new_strategy_solver(
114+
incremental_solvert &,
115+
const local_SSAt &,
116+
message_handlert &)=0;
117+
107118
// General methods for the strategy solver
108119
// Each generic strategy solver should implement at least these.
109120

src/domains/equality_domain.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class equality_domaint:public simple_domaint
6363
equ_valuet *clone() override { return new equ_valuet(*this); }
6464
};
6565

66+
std::unique_ptr<domaint::valuet> new_value() override
67+
{
68+
return std::unique_ptr<domaint::valuet>(new equ_valuet());
69+
}
70+
6671
void initialize() override;
6772

6873
void initialize_value(domaint::valuet &value) override;

src/domains/heap_domain.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class heap_domaint:public simple_domaint
8787
heap_valuet *clone() override { return new heap_valuet(*this); }
8888
};
8989

90+
std::unique_ptr<domaint::valuet> new_value() override
91+
{
92+
return std::unique_ptr<domaint::valuet>(new heap_valuet());
93+
}
94+
9095
// Initialize value and domain
9196
void initialize_value(domaint::valuet &value) override;
9297

src/domains/incremental_solver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Author: Peter Schrammel
1919
#include <solvers/refinement/bv_refinement.h>
2020
#include <solvers/sat/satcheck.h>
2121

22-
#include "domain.h"
2322
#include "util.h"
2423

2524
// #define DISPLAY_FORMULA

src/domains/lexlinrank_domain.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ class lexlinrank_domaint:public simple_domaint
9292
templ_valuet *clone() override { return new templ_valuet(*this); }
9393
};
9494

95+
std::unique_ptr<domaint::valuet> new_value() override
96+
{
97+
return std::unique_ptr<domaint::valuet>(new templ_valuet());
98+
}
99+
95100
lexlinrank_domaint(
96101
unsigned _domain_number,
97102
replace_mapt &_renaming_map,

src/domains/linrank_domain.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class linrank_domaint:public simple_domaint
6969
templ_valuet *clone() override { return new templ_valuet(*this); }
7070
};
7171

72+
std::unique_ptr<domaint::valuet> new_value() override
73+
{
74+
return std::unique_ptr<domaint::valuet>(new templ_valuet());
75+
}
76+
7277
linrank_domaint(
7378
unsigned _domain_number,
7479
replace_mapt &_renaming_map,

src/domains/predabs_domain.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class predabs_domaint:public simple_domaint
5252
templ_valuet *clone() override { return new templ_valuet(*this); }
5353
};
5454

55+
std::unique_ptr<domaint::valuet> new_value() override
56+
{
57+
return std::unique_ptr<domaint::valuet>(new templ_valuet());
58+
}
59+
5560
predabs_domaint(
5661
unsigned _domain_number,
5762
replace_mapt &_renaming_map,

src/domains/product_domain.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Viktor Malik
1313
/// Designed to work with strategy_solver_productt.
1414

1515
#include "product_domain.h"
16+
#include "strategy_solver_product.h"
1617

1718
void product_domaint::initialize_value(domaint::valuet &_value)
1819
{
@@ -81,3 +82,17 @@ void product_domaint::remove_all_sympath_restrictions()
8182
for(auto &domain : domains)
8283
domain->remove_all_sympath_restrictions();
8384
}
85+
86+
std::unique_ptr<strategy_solver_baset> product_domaint::new_strategy_solver(
87+
incremental_solvert &solver,
88+
const local_SSAt &SSA,
89+
message_handlert &message_handler)
90+
{
91+
solver_vect solvers;
92+
for(auto &d : domains)
93+
solvers.push_back(
94+
std::move(d->new_strategy_solver(solver, SSA, message_handler)));
95+
return std::unique_ptr<strategy_solver_baset>(
96+
new strategy_solver_productt(
97+
*this, std::move(solvers), solver, SSA, message_handler));
98+
}

src/domains/product_domain.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class product_domaint:public domaint
4848
}
4949
};
5050

51+
std::unique_ptr<domaint::valuet> new_value() override
52+
{
53+
value_vect values;
54+
for(auto &d : domains)
55+
values.push_back(std::move(d->new_value()));
56+
return std::unique_ptr<valuet>(new valuet(std::move(values)));
57+
}
58+
5159
// Most of the domain methods are implemented in such way that the
5260
// corresponding method is called for each domain.
5361

@@ -78,6 +86,11 @@ class product_domaint:public domaint
7886
return result;
7987
}
8088

89+
std::unique_ptr<strategy_solver_baset> new_strategy_solver(
90+
incremental_solvert &solvert,
91+
const local_SSAt &at,
92+
message_handlert &handlert) override;
93+
8194
// Product domain contains a vector of domains
8295
domain_vect domains;
8396

0 commit comments

Comments
 (0)