Skip to content

Commit 5fd6f6e

Browse files
author
Pascal Kesseli
committed
Defined CEGIS null object preprocessing tasks.
1 parent 48bfc7e commit 5fd6f6e

File tree

10 files changed

+125
-30
lines changed

10 files changed

+125
-30
lines changed

src/cegis/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ SRC = danger/meta/meta_variable_names.cpp danger/facade/danger_runner.cpp danger
5858
refactor/learn/refactor_symex_learn.cpp \
5959
refactor/verify/refactor_symex_verify.cpp \
6060
refactor/facade/refactor_runner.cpp \
61-
refactor/options/refactor_program.cpp refactor/value/refactor_solution.cpp \
61+
refactor/options/refactoring_type.cpp refactor/options/refactor_program.cpp refactor/value/refactor_solution.cpp \
6262
refactor/nullobject/range_collector.cpp \
6363
wordsize/restrict_bv_size.cpp value/program_individual_serialisation.cpp value/assignments_printer.cpp \
6464
seed/literals_seed.cpp \

src/cegis/cegis-util/type_helper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ instanceof_anyt::instanceof_anyt(const symbol_tablet &st,
5555

5656
bool instanceof_anyt::operator ()(const typet &type) const
5757
{
58+
if (types.empty()) return true;
5859
return types.end()
5960
!= std::find_if(types.begin(), types.end(),
6061
[this, &type](const typet &rhs)

src/cegis/control/preprocessing/control_preprocessing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace
1717
const char * const excluded_functions[]={
1818
"verify_stability_closedloop_using_dslib", "check_stability_closedloop",
1919
"fxp_double_to_fxp", "fxp_to_double", "ft_closedloop_series", "poly_mult",
20-
"poly_sum", "internal_pow" };
20+
"poly_sum", "internal_pow", "fxp_check", "fxp_control_floatt_to_fxp" };
2121

2222
bool is_meta(const goto_programt::const_targett pos)
2323
{
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
11
#include <cegis/refactor/environment/instrument_state_vars.h>
22

3-
void instrument_state_vars(goto_programt &body,
4-
const goto_programt::targett &first, const goto_programt::targett &last,
3+
namespace
4+
{
5+
class var_findert: public const_expr_visitort
6+
{
7+
public:
8+
std::set<irep_idt> vars;
9+
10+
virtual ~var_findert()=default;
11+
12+
virtual void operator()(const exprt &expr)
13+
{
14+
if (ID_symbol != expr.id()) return;
15+
vars.insert(to_symbol_expr(expr).get_identifier());
16+
}
17+
};
18+
}
19+
20+
std::set<irep_idt> collect_state_vars(goto_programt::const_targett first,
21+
const goto_programt::const_targett last)
22+
{
23+
var_findert visitor;
24+
for (; first != last; ++first)
25+
{
26+
first->code.visit(visitor);
27+
first->guard.visit(visitor);
28+
}
29+
return visitor.vars;
30+
}
31+
32+
void instrument_program_ops(goto_programt &body, goto_programt::targett pos,
33+
const std::set<irep_idt> &state_vars,
534
const std::function<bool(const typet &)> predicate)
635
{
736
// TODO: Implement
@@ -10,14 +39,14 @@ void instrument_state_vars(goto_programt &body,
1039

1140
namespace
1241
{
13-
bool yes(const typet &instr)
42+
bool use_all(const typet &instr)
1443
{
1544
return true;
1645
}
1746
}
1847

19-
void instrument_state_vars(goto_programt &body,
20-
const goto_programt::targett &first, const goto_programt::targett &last)
48+
void instrument_program_ops(goto_programt &body, goto_programt::targett pos,
49+
const std::set<irep_idt> &state_vars)
2150
{
22-
instrument_state_vars(body, first, last, yes);
51+
instrument_program_ops(body, pos, state_vars, use_all);
2352
}

src/cegis/refactor/environment/instrument_state_vars.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,29 @@
1919
*
2020
* @details
2121
*
22-
* @param body
2322
* @param first
2423
* @param last
24+
*
25+
* @return
26+
*/
27+
std::set<irep_idt> collect_state_vars(
28+
goto_programt::const_targett first,
29+
goto_programt::const_targett last);
30+
31+
/**
32+
* @brief
33+
*
34+
* @details
35+
*
36+
* @param body
37+
* @param pos
38+
* @param state_vars
2539
* @param predicate
2640
*/
27-
void instrument_state_vars(
41+
void instrument_program_ops(
2842
goto_programt &body,
29-
const goto_programt::targett &first,
30-
const goto_programt::targett &last,
43+
goto_programt::targett pos,
44+
const std::set<irep_idt> &state_vars,
3145
std::function<bool(const typet &)> predicate);
3246

3347
/**
@@ -36,12 +50,12 @@ void instrument_state_vars(
3650
* @details
3751
*
3852
* @param body
39-
* @param first
40-
* @param last
53+
* @param pos
54+
* @param state_vars
4155
*/
42-
void instrument_state_vars(
56+
void instrument_program_ops(
4357
goto_programt &body,
44-
const goto_programt::targett &first,
45-
const goto_programt::targett &last);
58+
goto_programt::targett pos,
59+
const std::set<irep_idt> &state_vars);
4660

4761
#endif /* CEGIS_REFACTOR_ENVIRONMENT_INSTRUMENT_STATE_VARS_H_ */

src/cegis/refactor/nullobject/range_collector.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ void collect_nullobject_ranges(refactor_programt &prog)
3636
if (goto_program_instruction_typet::GOTO != it->type) continue;
3737
const exprt &guard=it->guard;
3838
if (!is_null_comparison(guard)) continue;
39+
prog.sketches.push_back(refactor_programt::sketcht());
40+
refactor_programt::sketcht &sketch=prog.sketches.back();
41+
sketch.init=it;
3942
const goto_programt::targett else_range_last(it->get_target());
4043
const goto_ranget else_range(++it, else_range_last);
4144
const goto_ranget then_range(get_then_range(else_range_last));
42-
prog.sketches.push_back(refactor_programt::sketcht());
43-
refactor_programt::sketcht &sketch=prog.sketches.back();
4445
if (ID_equal == guard.id())
4546
{
4647
sketch.spec_range=then_range;

src/cegis/refactor/options/refactor_program.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ class refactor_programt
4242
class sketcht
4343
{
4444
public:
45+
goto_programt::targett init;
4546
goto_ranget input_range;
4647
goto_ranget spec_range;
48+
std::set<irep_idt> state_vars;
4749
std::set<typet> types;
4850
};
4951

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <cassert>
2+
3+
#include <util/options.h>
4+
5+
#include <cegis/options/parameters.h>
6+
#include <cegis/refactor/options/refactoring_type.h>
7+
8+
refactoring_typet get_refactoring_type(const class optionst &options)
9+
{
10+
if (options.get_bool_option(CEGIS_NULL_OBJECT_REFACTOR))
11+
return refactoring_typet::NULL_OBJECT;
12+
assert(!"Invalid refactoring type selected.");
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*******************************************************************
2+
3+
Module: Counterexample-Guided Inductive Synthesis
4+
5+
Author: Daniel Kroening, [email protected]
6+
Pascal Kesseli, [email protected]
7+
8+
\*******************************************************************/
9+
10+
#ifndef CEGIS_REFACTOR_OPTIONS_REFACTORING_TYPE_H_
11+
#define CEGIS_REFACTOR_OPTIONS_REFACTORING_TYPE_H_
12+
13+
typedef enum
14+
{
15+
NULL_OBJECT
16+
} refactoring_typet;
17+
18+
/**
19+
* @brief
20+
*
21+
* @details
22+
*
23+
* @param options
24+
*
25+
* @return
26+
*/
27+
refactoring_typet get_refactoring_type(const class optionst &options);
28+
29+
#endif /* CEGIS_REFACTOR_OPTIONS_REFACTORING_TYPE_H_ */

src/cegis/refactor/preprocessing/refactor_preprocessing.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#include <util/options.h>
44

5-
#include <cegis/options/parameters.h>
65
#include <cegis/cegis-util/inline_user_program.h>
76
#include <cegis/cegis-util/program_helper.h>
87
#include <cegis/cegis-util/type_helper.h>
8+
#include <cegis/refactor/options/refactoring_type.h>
99
#include <cegis/refactor/environment/instrument_state_vars.h>
1010
#include <cegis/refactor/nullobject/range_collector.h>
1111
#include <cegis/refactor/preprocessing/refactor_preprocessing.h>
@@ -21,19 +21,25 @@ void refactor_preprocessingt::operator()()
2121
const symbol_tablet &st=original_program.st;
2222
goto_functionst &gf=original_program.gf;
2323
inline_user_program(st, gf);
24-
if (options.get_bool_option(CEGIS_NULL_OBJECT_REFACTOR))
24+
const refactoring_typet type(get_refactoring_type(options));
25+
switch (type)
2526
{
27+
case refactoring_typet::NULL_OBJECT:
2628
collect_nullobject_ranges(original_program);
27-
for (refactor_programt::sketcht &sketch : original_program.sketches)
28-
{
29-
goto_ranget &input_range=sketch.input_range;
30-
goto_programt &body=get_body(gf, input_range.first);
31-
const instanceof_anyt pred(st, sketch.types);
32-
instrument_state_vars(body, input_range.first, input_range.second, pred);
33-
}
34-
// TODO: collect_
29+
// TODO: Insert GOTOs between ranges
30+
break;
31+
}
32+
for (refactor_programt::sketcht &s : original_program.sketches)
33+
s.state_vars=collect_state_vars(s.spec_range.first, s.spec_range.second);
34+
// TODO: Insert extern programs.
35+
// TODO: construct_instruction_set(original_program); // Multiple?
36+
switch (type)
37+
{
38+
case refactoring_typet::NULL_OBJECT:
39+
// TODO: Replace method calls by program execution.
40+
// TODO: Instrument ops (globals + params from corresponding replaced method call)
41+
break;
3542
}
36-
// TODO: construct_instruction_set(original_program);
3743
// TODO: Implement
3844
assert(false);
3945
}

0 commit comments

Comments
 (0)