Skip to content

Commit dd64951

Browse files
authored
Merge pull request #7241 from diffblue/chc_proof_strategy
CHC solver: extract solver progress reporting
2 parents 05f2905 + 9ec3465 commit dd64951

File tree

6 files changed

+119
-25
lines changed

6 files changed

+119
-25
lines changed

src/cprover/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SRC = address_taken.cpp \
2626
state_encoding.cpp \
2727
state_encoding_targets.cpp \
2828
solver.cpp \
29+
solver_progress.cpp \
2930
variable_encoding.cpp \
3031
wcwidth.c \
3132
# Empty last line

src/cprover/console.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
# include <unistd.h>
2121
#endif
2222

23+
#include <util/invariant.h>
2324
#include <util/run.h>
2425
#include <util/string_utils.h>
2526
#include <util/unicode.h>
@@ -181,6 +182,18 @@ std::ostream &consolet::reset(std::ostream &str)
181182
return str;
182183
}
183184

185+
std::ostream &consolet::cursorup(std::ostream &str)
186+
{
187+
PRECONDITION(is_terminal());
188+
return str << "\x1b[1A";
189+
}
190+
191+
std::ostream &consolet::cleareol(std::ostream &str)
192+
{
193+
PRECONDITION(is_terminal());
194+
return str << "\x1b[0K";
195+
}
196+
184197
std::size_t consolet::width()
185198
{
186199
if(_width_is_set)

src/cprover/console.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class consolet
2020
public:
2121
static void init();
2222

23+
// colors
2324
static std::ostream &blue(std::ostream &);
2425
static std::ostream &cyan(std::ostream &);
2526
static std::ostream &green(std::ostream &);
@@ -33,6 +34,12 @@ class consolet
3334

3435
static std::ostream &reset(std::ostream &);
3536

37+
// cursor movement
38+
static std::ostream &cursorup(std::ostream &);
39+
40+
// deletion
41+
static std::ostream &cleareol(std::ostream &); // erase to end of line
42+
3643
static bool is_terminal()
3744
{
3845
init();

src/cprover/solver.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Author: Daniel Kroening, [email protected]
2626
#include "propagate.h"
2727
#include "report_properties.h"
2828
#include "report_traces.h"
29+
#include "solver_progress.h"
2930
#include "solver_types.h"
3031
#include "state.h"
3132

@@ -393,29 +394,6 @@ void solver(
393394
property.status = propertyt::DROPPED;
394395
}
395396

396-
void solver_progress(size_t i, size_t n, bool verbose)
397-
{
398-
if(verbose)
399-
{
400-
}
401-
else
402-
{
403-
if(i == n)
404-
{
405-
if(consolet::is_terminal())
406-
std::cout << "\x1b[1A\x1b[0K"; // clear the line
407-
}
408-
else
409-
{
410-
if(i != 0 && consolet::is_terminal())
411-
std::cout << "\x1b[1A";
412-
413-
std::cout << consolet::orange << "Doing property " << (i + 1) << '/' << n
414-
<< consolet::reset << '\n';
415-
}
416-
}
417-
}
418-
419397
solver_resultt solver(
420398
const std::vector<exprt> &constraints,
421399
const solver_optionst &solver_options,
@@ -441,14 +419,16 @@ solver_resultt solver(
441419
return solver_resultt::ALL_PASS;
442420
}
443421

422+
solver_progresst solver_progress(properties.size(), solver_options.verbose);
423+
444424
// solve each property separately, in order of occurence
445425
for(std::size_t i = 0; i < properties.size(); i++)
446426
{
447-
solver_progress(i, properties.size(), solver_options.verbose);
427+
solver_progress(i);
448428
solver(frames, address_taken, solver_options, ns, properties, i);
449429
}
450430

451-
solver_progress(properties.size(), properties.size(), solver_options.verbose);
431+
solver_progress.finished();
452432

453433
// reporting
454434
report_properties(properties);

src/cprover/solver_progress.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************\
2+
3+
Module: Solver Progress Reporting
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Solver Progress Reporting
11+
12+
#include "solver_progress.h"
13+
14+
#include "console.h"
15+
16+
#include <iostream>
17+
18+
void solver_progresst::operator()(size_t current)
19+
{
20+
if(verbose)
21+
{
22+
}
23+
else
24+
{
25+
if(first)
26+
{
27+
first = false;
28+
}
29+
else
30+
{
31+
if(consolet::is_terminal())
32+
{
33+
// up one row and clear the line
34+
std::cout << consolet::cursorup << consolet::cleareol;
35+
}
36+
}
37+
38+
std::cout << consolet::orange << "Processing property " << (current + 1)
39+
<< '/' << total << consolet::reset << '\n';
40+
}
41+
}
42+
43+
void solver_progresst::finished()
44+
{
45+
if(verbose)
46+
{
47+
}
48+
else
49+
{
50+
if(consolet::is_terminal())
51+
{
52+
if(!first)
53+
{
54+
// up one row and clear the line
55+
std::cout << consolet::cursorup << consolet::cleareol;
56+
}
57+
}
58+
}
59+
}

src/cprover/solver_progress.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************\
2+
3+
Module: Solver Progress Reporting
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Solver Progress Reporting
11+
12+
#ifndef CPROVER_CPROVER_SOLVER_PROGRESS_H
13+
#define CPROVER_CPROVER_SOLVER_PROGRESS_H
14+
15+
#include "solver_types.h"
16+
17+
class solver_progresst
18+
{
19+
public:
20+
solver_progresst(std::size_t __total, bool __verbose)
21+
: total(__total), verbose(__verbose)
22+
{
23+
}
24+
25+
void operator()(std::size_t current);
26+
void finished();
27+
28+
private:
29+
bool first = true;
30+
std::size_t total = 0;
31+
bool verbose;
32+
};
33+
34+
#endif // CPROVER_CPROVER_SOLVER_PROGRESS_H

0 commit comments

Comments
 (0)