Skip to content

Commit 601db02

Browse files
author
Peter Schrammel
committed
merge line terminators
2 parents 1636f42 + 3831765 commit 601db02

22 files changed

+5860
-41
lines changed

regression/cegis/cegis_control_benchmark_02/example-a_SCHEMA2_IMPL1.c

Lines changed: 5255 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
example-a_SCHEMA2_IMPL1.c
3+
--gcc --cegis-control --cegis-statistics --cegis-genetic --cegis-max-size 1
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

src/cegis/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ SRC = danger/meta/meta_variable_names.cpp danger/facade/danger_runner.cpp danger
6060
cegis-util/task_pool.cpp cegis-util/constant_width.cpp cegis-util/irep_pipe.cpp cegis-util/program_helper.cpp \
6161
cegis-util/temporary_output_block.cpp cegis-util/cbmc_runner.cpp cegis-util/module_helper.cpp \
6262
cegis-util/inline_user_program.cpp cegis-util/counterexample_vars.cpp cegis-util/string_helper.cpp \
63+
cegis-util/type_helper.cpp \
64+
learn/insert_counterexample.cpp learn/constraint_helper.cpp \
6365
constant/add_constant.cpp constant/literals_collector.cpp constant/default_cegis_constant_strategy.cpp \
6466
instrument/cegis_library.cpp instrument/instrument_var_ops.cpp instrument/meta_variables.cpp \
6567
instrument/find_cprover_initialize.cpp \

src/cegis/cegis-util/counterexample_vars.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,28 @@ void show_assignments(std::ostream &os,
100100
os << "</assignment>" << std::endl;
101101
}
102102
}
103+
104+
namespace
105+
{
106+
bool is_marker(const irep_idt &label)
107+
{
108+
return std::string::npos != id2string(label).find(DEFAULT_MARKER_LABEL_PREFIX);
109+
}
110+
111+
typedef goto_programt::instructiont::labelst labelst;
112+
}
113+
114+
bool has_counterexample_marker(const goto_programt::const_targett pos)
115+
{
116+
const labelst &l=pos->labels;
117+
return l.end() != std::find_if(l.begin(), l.end(), is_marker);
118+
}
119+
120+
const irep_idt &get_counterexample_marker(
121+
const goto_programt::const_targett pos)
122+
{
123+
const labelst &l=pos->labels;
124+
const labelst::const_iterator it=std::find_if(l.begin(), l.end(), is_marker);
125+
assert(l.end() != it);
126+
return *it;
127+
}

src/cegis/cegis-util/counterexample_vars.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Author: Daniel Kroening, [email protected]
1515

1616
#include <goto-programs/goto_program.h>
1717

18+
#include <cegis/cegis-util/labelled_assignments.h>
19+
1820
#define DEFAULT_MARKER_LABEL_PREFIX CPROVER_PREFIX "_cegis_ce_location_"
1921

2022
/**
@@ -93,8 +95,7 @@ bool default_cegis_meta_criterion(const goto_programt::const_targett pos);
9395
*
9496
* @return
9597
*/
96-
std::map<const irep_idt, exprt::operandst> extract_counterexample(
97-
const class goto_tracet &trace);
98+
labelled_assignmentst extract_counterexample(const class goto_tracet &trace);
9899

99100
/**
100101
* @brief
@@ -104,6 +105,28 @@ std::map<const irep_idt, exprt::operandst> extract_counterexample(
104105
* @param assignments
105106
*/
106107
void show_assignments(std::ostream &os,
107-
const std::map<const irep_idt, exprt::operandst> &assignments);
108+
const labelled_assignmentst &assignments);
109+
110+
/**
111+
* @brief
112+
*
113+
* @details
114+
*
115+
* @param pos
116+
*
117+
* @return
118+
*/
119+
bool has_counterexample_marker(goto_programt::const_targett pos);
120+
121+
/**
122+
* @brief
123+
*
124+
* @details
125+
*
126+
* @param pos
127+
*
128+
* @return
129+
*/
130+
const irep_idt &get_counterexample_marker(goto_programt::const_targett pos);
108131

109132
#endif /* CEGIS_COUNTEREXAMPLE_VARS_H_ */
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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_UTIL_LABELLED_ASSIGNMENTS_H_
11+
#define CEGIS_UTIL_LABELLED_ASSIGNMENTS_H_
12+
13+
#include <deque>
14+
15+
#include <util/expr.h>
16+
17+
/**
18+
* @brief
19+
*
20+
* @details
21+
*/
22+
typedef std::map<const irep_idt, exprt::operandst> labelled_assignmentst;
23+
24+
/**
25+
* @brief
26+
*
27+
* @details
28+
*/
29+
typedef std::deque<labelled_assignmentst> labelled_counterexamplest;
30+
31+
#endif /* CEGIS_UTIL_LABELLED_ASSIGNMENTS_H_ */

src/cegis/cegis-util/program_helper.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,12 @@
1111

1212
goto_programt &get_entry_body(goto_functionst &gf)
1313
{
14-
const irep_idt id(goto_functionst::entry_point());
15-
goto_functionst::function_mapt &function_map=gf.function_map;
16-
const goto_functionst::function_mapt::iterator it=function_map.find(id);
17-
assert(function_map.end() != it && "Danger program function missing.");
18-
goto_function_templatet<goto_programt> &f=it->second;
19-
assert(f.body_available() && "Danger program function body missing.");
20-
return f.body;
14+
return get_body(gf, id2string(goto_functionst::entry_point()));
2115
}
2216

2317
const goto_programt &get_entry_body(const goto_functionst &gf)
2418
{
25-
const irep_idt id(goto_functionst::entry_point());
26-
const goto_functionst::function_mapt &function_map=gf.function_map;
27-
const goto_functionst::function_mapt::const_iterator it=function_map.find(id);
28-
assert(function_map.end() != it && "Danger program function missing.");
29-
const goto_function_templatet<goto_programt> &f=it->second;
30-
assert(f.body_available() && "Danger program function body missing.");
31-
return f.body;
19+
return get_body(gf, id2string(goto_functionst::entry_point()));
3220
}
3321

3422
class goto_programt &get_body(

src/cegis/cegis-util/type_helper.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <util/std_types.h>
2+
#include <util/symbol_table.h>
3+
4+
#define TAG_PREFIX "tag-"
5+
6+
const typet &replace_struct_by_symbol_type(const symbol_tablet &st,
7+
const typet &type)
8+
{
9+
const irep_idt &type_id=type.id();
10+
if (ID_struct != type_id && ID_incomplete_struct != type_id
11+
&& ID_union != type_id && ID_incomplete_union != type_id) return type;
12+
std::string tag(TAG_PREFIX);
13+
tag+=id2string(to_struct_union_type(type).get_tag());
14+
return st.lookup(tag).type;
15+
}

src/cegis/cegis-util/type_helper.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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_UTIL_TYPE_HELPER_H_
11+
#define CEGIS_UTIL_TYPE_HELPER_H_
12+
13+
/**
14+
* @brief
15+
*
16+
* @details
17+
*
18+
* @param st
19+
* @param type
20+
*/
21+
const class typet &replace_struct_by_symbol_type(
22+
const class symbol_tablet &st,
23+
const typet &type);
24+
25+
#endif /* CEGIS_UTIL_TYPE_HELPER_H_ */

src/cegis/control/learn/control_symex_learn.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <cegis/learn/constraint_helper.h>
2+
#include <cegis/learn/insert_counterexample.h>
13
#include <cegis/control/learn/nondet_solution.h>
24
#include <cegis/control/learn/control_symex_learn.h>
35

@@ -11,11 +13,14 @@ void control_symex_learnt::process(const counterexamplest &counterexamples,
1113
const size_t max_solution_size)
1214
{
1315
current_program=original_program;
14-
const symbol_tablet &st=current_program.st;
16+
symbol_tablet &st=current_program.st;
1517
goto_functionst &gf=current_program.gf;
1618
nondet_control_solution(st, gf);
17-
// TODO: Implement
18-
assert(false);
19+
transform_asserts_to_assumes(gf);
20+
const goto_programt::targetst &ce_locs=
21+
current_program.counterexample_locations;
22+
insert_counterexamples(st, gf, counterexamples, ce_locs);
23+
gf.update();
1924
}
2025

2126
const symbol_tablet &control_symex_learnt::get_symbol_table() const
Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,110 @@
1+
#include <deque>
2+
#include <algorithm>
3+
14
#include <cegis/control/value/control_vars.h>
25
#include <cegis/cegis-util/program_helper.h>
6+
#include <cegis/instrument/literals.h>
37
#include <cegis/instrument/find_cprover_initialize.h>
48
#include <cegis/control/learn/nondet_solution.h>
59

10+
namespace
11+
{
12+
bool is_sol_assign(const goto_programt::instructiont &instr)
13+
{
14+
if (goto_program_instruction_typet::ASSIGN != instr.type) return false;
15+
const std::string &var=id2string(get_affected_variable(instr));
16+
return CEGIS_CONTROL_SOLUTION_VAR_NAME == var;
17+
}
18+
19+
void remove_solution_assignment_from_cprover_init(goto_functionst &gf)
20+
{
21+
goto_programt::instructionst &i=get_body(gf, CPROVER_INIT).instructions;
22+
const goto_programt::targett end(i.end());
23+
const goto_programt::targett pos=std::find_if(i.begin(), end, is_sol_assign);
24+
assert(end != pos);
25+
i.erase(pos);
26+
}
27+
28+
const exprt &get_comp(const namespacet &ns, const struct_exprt &value,
29+
const char * const comp)
30+
{
31+
const struct_typet &type=to_struct_type(ns.follow(value.type()));
32+
const struct_typet::componentst &comps=type.components();
33+
for (size_t i=0; i < comps.size(); ++i)
34+
if (id2string(comps[i].get_name()) == comp) return value.operands()[i];
35+
assert(!"Solution component not found.");
36+
}
37+
38+
const exprt &get_a_size(const namespacet &ns, const struct_exprt &value)
39+
{
40+
return get_comp(ns, value, CEGIS_CONTROL_A_SIZE_MEMBER_NAME);
41+
}
42+
43+
const exprt &get_b_size(const namespacet &ns, const struct_exprt &value)
44+
{
45+
return get_comp(ns, value, CEGIS_CONTROL_B_SIZE_MEMBER_NAME);
46+
}
47+
48+
class replace_sizes_visitort: public expr_visitort
49+
{
50+
std::deque<exprt *> a_sizes, b_sizes;
51+
const exprt &a_size;
52+
const exprt &b_size;
53+
public:
54+
replace_sizes_visitort(const exprt &a_size, const exprt &b_size) :
55+
a_size(a_size), b_size(b_size)
56+
{
57+
}
58+
59+
virtual ~replace_sizes_visitort()
60+
{
61+
for (exprt * const expr : a_sizes)
62+
*expr=a_size;
63+
for (exprt * const expr : b_sizes)
64+
*expr=b_size;
65+
}
66+
67+
virtual void operator()(exprt &expr)
68+
{
69+
if (ID_member != expr.id()) return;
70+
const member_exprt &member=to_member_expr(expr);
71+
const exprt &struct_op=member.struct_op();
72+
if (ID_symbol != struct_op.id()) return;
73+
const symbol_exprt &symbol=to_symbol_expr(struct_op);
74+
const std::string &var=id2string(symbol.get_identifier());
75+
if (CEGIS_CONTROL_SOLUTION_VAR_NAME != var) return;
76+
const std::string &comp=id2string(member.get_component_name());
77+
if (CEGIS_CONTROL_A_SIZE_MEMBER_NAME == comp) a_sizes.push_back(&expr);
78+
else if (CEGIS_CONTROL_B_SIZE_MEMBER_NAME == comp) b_sizes.push_back(&expr);
79+
}
80+
};
81+
82+
void replace_controller_sizes(const symbol_tablet &st, goto_functionst &gf)
83+
{
84+
const symbolt &symbol=st.lookup(CEGIS_CONTROL_SOLUTION_VAR_NAME);
85+
const struct_exprt &controller_value=to_struct_expr(symbol.value);
86+
const namespacet ns(st);
87+
const exprt &a_size=get_a_size(ns, controller_value);
88+
const exprt &b_size=get_b_size(ns, controller_value);
89+
replace_sizes_visitort visitor(a_size, b_size);
90+
goto_programt &body=get_entry_body(gf);
91+
for (goto_programt::instructiont &instr : body.instructions)
92+
{
93+
instr.code.visit(visitor);
94+
instr.guard.visit(visitor);
95+
}
96+
}
97+
}
98+
699
void nondet_control_solution(const symbol_tablet &st, goto_functionst &gf)
7100
{
8-
const irep_idt name(CEGIS_CONTROL_SOLUTION_VAR_NAME);
101+
const std::string name(CEGIS_CONTROL_SOLUTION_VAR_NAME);
9102
const symbolt &symbol=st.lookup(name);
103+
replace_controller_sizes(st, gf);
10104
const side_effect_expr_nondett value(symbol.type);
11105
const symbol_exprt solution_var(symbol.symbol_expr());
12106
goto_programt &body=get_entry_body(gf);
13-
const goto_programt::targett pos(find_cprover_initialize(body));
14-
cegis_assign_user_variable(st, gf, pos, name, value);
107+
goto_programt::targett pos(find_cprover_initialize(body));
108+
pos=cegis_assign_user_variable(st, gf, std::prev(pos), name, value);
109+
remove_solution_assignment_from_cprover_init(gf);
15110
}

src/cegis/control/value/control_vars.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
#define CEGIS_CONTROL_SOLUTION_VAR_NAME "controller"
1414
#define CEGIS_CONTROL_A_MEMBER_NAME "a"
1515
#define CEGIS_CONTROL_A_SIZE_MEMBER_NAME "a_size"
16+
#define CEGIS_CONTROL_B_SIZE_MEMBER_NAME "b_size"
1617

1718
#endif /* CEGIS_CONTROL_VARS_H_ */

src/cegis/control/verify/control_symex_verify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ void control_symex_verifyt::process(const candidatet &candidate)
1212
{
1313
current_program=original_program;
1414
insert_solution(current_program, candidate);
15+
current_program.gf.update();
1516
}
1617

1718
const symbol_tablet &control_symex_verifyt::get_symbol_table() const

src/cegis/control/verify/insert_solution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void insert_solution(control_programt &program,
6969
goto_functionst &gf=program.gf;
7070
goto_programt &body=get_entry_body(gf);
7171
const goto_programt::targett pos=find_cprover_initialize(body);
72-
const irep_idt name(CEGIS_CONTROL_SOLUTION_VAR_NAME);
72+
const std::string name(CEGIS_CONTROL_SOLUTION_VAR_NAME);
7373
const symbol_tablet &st=program.st;
7474
const source_locationt &loc=pos->source_location;
7575
const struct_exprt value(to_struct_expr(st, solution, loc));

src/cegis/instrument/find_cprover_initialize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ goto_programt::targett find_cprover_initialize(goto_programt &body)
1919
assert(end != pos);
2020
return pos;
2121
}
22+
23+
goto_programt::targett find_last_instr(goto_programt &body)
24+
{
25+
goto_programt::targett result=body.instructions.end();
26+
assert(goto_program_instruction_typet::END_FUNCTION == (--result)->type);
27+
return --result;
28+
}

src/cegis/instrument/find_cprover_initialize.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@
2323
*/
2424
goto_programt::targett find_cprover_initialize(goto_programt &body);
2525

26+
/**
27+
* @brief
28+
*
29+
* @details
30+
*
31+
* @param body
32+
*
33+
* @return
34+
*/
35+
goto_programt::targett find_last_instr(goto_programt &body);
36+
2637
#endif /* CEGIS_FIND_CPROVER_INITIALIZE_H_ */

0 commit comments

Comments
 (0)