Skip to content

Commit 0b96343

Browse files
committed
Extended CEGIS null object instrumentation.
1 parent afb9f77 commit 0b96343

26 files changed

+696
-156
lines changed
Binary file not shown.

regression/cegis/cegis_refactor_benchmark_01/Runner.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,4 @@ void print(ITaxCalculator calc, double price) {
2828
System.out.print(percentage);
2929
System.out.println('%');
3030
}
31-
static void main() {
32-
}
3331
}

src/cegis/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ SRC = danger/meta/meta_variable_names.cpp danger/facade/danger_runner.cpp danger
5858
refactor/instructionset/processor_types.cpp refactor/instructionset/cegis_processor_body_factory.cpp \
5959
refactor/instructionset/instruction_description.cpp refactor/instructionset/cegis_instruction_factory.cpp \
6060
refactor/instructionset/processor_symbols.cpp \
61+
refactor/constraint/constraint_factory.cpp \
6162
refactor/preprocessing/refactor_preprocessing.cpp \
6263
refactor/learn/refactor_symex_learn.cpp \
6364
refactor/verify/refactor_symex_verify.cpp \
6465
refactor/facade/refactor_runner.cpp \
6566
refactor/options/refactoring_type.cpp refactor/options/refactor_program.cpp refactor/value/refactor_solution.cpp \
66-
refactor/nullobject/range_collector.cpp \
67+
refactor/nullobject/range_collector.cpp refactor/nullobject/nullable_analysis.cpp \
6768
wordsize/restrict_bv_size.cpp value/program_individual_serialisation.cpp value/assignments_printer.cpp \
6869
seed/literals_seed.cpp \
6970
genetic/instruction_set_info_factory.cpp genetic/random_mutate.cpp genetic/random_cross.cpp \

src/cegis/cegis-util/program_helper.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ goto_programt &get_body(goto_functionst &gf, const std::string &func_name)
3030
return f.body;
3131
}
3232

33-
goto_programt &get_body(goto_functionst &gf, const goto_programt::const_targett pos)
33+
goto_programt &get_body(goto_functionst &gf,
34+
const goto_programt::const_targett pos)
3435
{
3536
return get_body(gf, id2string(pos->function));
3637
}
@@ -122,7 +123,8 @@ bool is_nondet(goto_programt::const_targett target,
122123

123124
bool is_return_value_name(const std::string &name)
124125
{
125-
return contains(name, "return_value___") || contains(name, RETURN_VALUE_SUFFIX);
126+
return contains(name, "return_value___")
127+
|| contains(name, RETURN_VALUE_SUFFIX);
126128
}
127129

128130
const typet &get_affected_type(const goto_programt::instructiont &instr)
@@ -177,23 +179,38 @@ bool is_global_const(const irep_idt &name, const typet &type)
177179
return std::string::npos == n.find(NS_SEP);
178180
}
179181

180-
void move_labels(goto_programt &body, const goto_programt::targett &from,
181-
const goto_programt::targett &to)
182+
void move_labels(goto_programt::instructionst &body,
183+
const goto_programt::targett &from, const goto_programt::targett &to)
182184
{
183-
for (goto_programt::instructiont &instr : body.instructions)
185+
for (goto_programt::instructiont &instr : body)
184186
for (goto_programt::targett &target : instr.targets)
185187
if (from == target) target=to;
186188
}
187189

190+
void move_labels(goto_programt &body, const goto_programt::targett &from,
191+
const goto_programt::targett &to)
192+
{
193+
move_labels(body.instructions, from, to);
194+
}
195+
196+
goto_programt::targett insert_before_preserve_labels(goto_programt &body,
197+
const goto_programt::targett &target)
198+
{
199+
const goto_programt::targett result=body.insert_before(target);
200+
move_labels(body, target, result);
201+
return result;
202+
}
203+
188204
bool is_builtin(const source_locationt &loc)
189205
{
190206
if (loc.is_nil()) return true;
191207
const std::string &file=id2string(loc.get_file());
192208
return file.empty() || file.at(0) == '<';
193209
}
194210

195-
symbolt &create_local_cegis_symbol(symbol_tablet &st, const std::string &full_name,
196-
const std::string &base_name, const typet &type)
211+
symbolt &create_local_cegis_symbol(symbol_tablet &st,
212+
const std::string &full_name, const std::string &base_name,
213+
const typet &type)
197214
{
198215
symbolt new_symbol;
199216
new_symbol.name=full_name;
@@ -288,11 +305,8 @@ void remove_return(goto_programt &body, const goto_programt::targett pos)
288305
call.lhs().make_nil();
289306
}
290307

291-
goto_programt::targett add_return_assignment(
292-
goto_programt &body,
293-
goto_programt::targett pos,
294-
const irep_idt &func_id,
295-
const exprt &value)
308+
goto_programt::targett add_return_assignment(goto_programt &body,
309+
goto_programt::targett pos, const irep_idt &func_id, const exprt &value)
296310
{
297311
const source_locationt &loc=pos->source_location;
298312
pos=body.insert_after(pos);

src/cegis/cegis-util/program_helper.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ const irep_idt &get_affected_variable(const goto_programt::instructiont &instr);
145145
*/
146146
bool is_global_const(const irep_idt &name, const typet &type);
147147

148+
/**
149+
* @brief
150+
*
151+
* @details
152+
*
153+
* @param body
154+
* @param from
155+
* @param to
156+
*/
157+
void move_labels(
158+
goto_programt::instructionst &body,
159+
const goto_programt::targett &from,
160+
const goto_programt::targett &to);
148161

149162
/**
150163
* @brief
@@ -155,9 +168,25 @@ bool is_global_const(const irep_idt &name, const typet &type);
155168
* @param from
156169
* @param to
157170
*/
158-
void move_labels(goto_programt &body, const goto_programt::targett &from,
171+
void move_labels(
172+
goto_programt &body,
173+
const goto_programt::targett &from,
159174
const goto_programt::targett &to);
160175

176+
/**
177+
* @brief
178+
*
179+
* @details
180+
*
181+
* @param body
182+
* @param target
183+
*
184+
* @return
185+
*/
186+
goto_programt::targett insert_before_preserve_labels(
187+
goto_programt &body,
188+
const goto_programt::targett &target);
189+
161190
/**
162191
* @brief
163192
*

src/cegis/cegis-util/string_helper.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,16 @@ bool contains(const std::string &haystack, const std::string &needle)
44
{
55
return std::string::npos != haystack.find(needle);
66
}
7+
8+
bool starts_with(const std::string &haystack, const std::string &prefix)
9+
{
10+
return haystack.substr(0, prefix.size()) == prefix;
11+
}
12+
13+
bool ends_with(const std::string &haystack, const std::string &suffix)
14+
{
15+
const std::string::size_type haystack_sz=haystack.size();
16+
const std::string::size_type suffix_sz=suffix.size();
17+
if (haystack_sz < suffix_sz) return false;
18+
return haystack.substr(haystack_sz - suffix_sz) == suffix;
19+
}

src/cegis/cegis-util/string_helper.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,28 @@ Author: Daniel Kroening, [email protected]
2424
*/
2525
bool contains(const std::string &haystack, const std::string &needle);
2626

27+
/**
28+
* @brief
29+
*
30+
* @details
31+
*
32+
* @param haystack
33+
* @param prefix
34+
*
35+
* @return
36+
*/
37+
bool starts_with(const std::string &haystack, const std::string &prefix);
38+
39+
/**
40+
* @brief
41+
*
42+
* @details
43+
*
44+
* @param haystack
45+
* @param suffix
46+
*
47+
* @return
48+
*/
49+
bool ends_with(const std::string &haystack, const std::string &suffix);
50+
2751
#endif /* CEGIS_STRING_HELPER_H_ */

src/cegis/invariant/util/invariant_program_helper.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ void erase_target(goto_programt::instructionst &body,
1919
body.erase(target);
2020
}
2121

22-
goto_programt::targett insert_before_preserve_labels(goto_programt &body,
23-
const goto_programt::targett &target)
24-
{
25-
const goto_programt::targett result=body.insert_before(target);
26-
move_labels(body, target, result);
27-
return result;
28-
}
29-
3022
void restrict_bv_size(invariant_programt &prog, const size_t width_in_bits)
3123
{
3224
restrict_bv_size(prog.st, prog.gf, width_in_bits);

src/cegis/invariant/util/invariant_program_helper.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@
2323
void erase_target(goto_programt::instructionst &body,
2424
const goto_programt::targett &target);
2525

26-
/**
27-
* @brief
28-
*
29-
* @details
30-
*
31-
* @param body
32-
* @param target
33-
*/
34-
goto_programt::targett insert_before_preserve_labels(goto_programt &body,
35-
const goto_programt::targett &target);
36-
3726
/**
3827
* @brief
3928
*
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <cegis/refactor/options/refactor_program.h>
2+
3+
void create_constraint_function_caller(refactor_programt &prog)
4+
{
5+
// * Create function calling all refactored methods
6+
}
7+
8+
void link_refactoring_ranges(refactor_programt &prog)
9+
{
10+
// * Goto input/spec range
11+
// * Repeat possibly skipped local declarations
12+
}
13+
14+
void create_refactoring_constraint(refactor_programt &prog)
15+
{
16+
// * Nondet state vars at beginning of ranges
17+
// * Clone state vars
18+
// * Replace used variables in input range by clones
19+
// * Generate assertion based on used variables
20+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_CONSTRAINT_CONSTRAINT_FACTORY_H_
11+
#define CEGIS_REFACTOR_CONSTRAINT_CONSTRAINT_FACTORY_H_
12+
13+
/**
14+
* @brief
15+
*
16+
* @details
17+
*
18+
* @param prog
19+
*/
20+
void create_constraint_function_caller(class refactor_programt &prog);
21+
22+
/**
23+
* @brief
24+
*
25+
* @details
26+
*
27+
* @param prog
28+
*/
29+
void link_refactoring_ranges(refactor_programt &prog);
30+
31+
/**
32+
* @brief
33+
*
34+
* @details
35+
*
36+
* @param prog
37+
*/
38+
void create_refactoring_constraint(refactor_programt &prog);
39+
40+
#endif /* CEGIS_REFACTOR_CONSTRAINT_CONSTRAINT_FACTORY_H_ */

src/cegis/refactor/environment/instrument_state_vars.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,34 @@ namespace
44
{
55
class var_findert: public const_expr_visitort
66
{
7+
std::set<irep_idt> &vars;
78
public:
8-
std::set<irep_idt> vars;
9+
var_findert(std::set<irep_idt> &vars) :
10+
vars(vars)
11+
{
12+
}
913

1014
virtual ~var_findert()=default;
1115

1216
virtual void operator()(const exprt &expr)
1317
{
1418
if (ID_symbol != expr.id()) return;
19+
if (ID_code == expr.type().id()) return;
20+
// TODO: Follow function calls
1521
vars.insert(to_symbol_expr(expr).get_identifier());
1622
}
1723
};
1824
}
1925

20-
std::set<irep_idt> collect_state_vars(goto_programt::const_targett first,
21-
const goto_programt::const_targett last)
26+
void collect_state_vars(std::set<irep_idt> &result,
27+
goto_programt::const_targett first, const goto_programt::const_targett last)
2228
{
23-
var_findert visitor;
29+
var_findert visitor(result);
2430
for (; first != last; ++first)
2531
{
2632
first->code.visit(visitor);
2733
first->guard.visit(visitor);
2834
}
29-
return visitor.vars;
3035
}
3136

3237
void instrument_program_ops(goto_programt &body, goto_programt::targett pos,

src/cegis/refactor/environment/instrument_state_vars.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
*
2020
* @details
2121
*
22+
* @param result
2223
* @param first
2324
* @param last
24-
*
25-
* @return
2625
*/
27-
std::set<irep_idt> collect_state_vars(
26+
void collect_state_vars(
27+
std::set<irep_idt> &result,
2828
goto_programt::const_targett first,
2929
goto_programt::const_targett last);
3030

src/cegis/refactor/instructionset/cegis_instruction_factory.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ ordered_instructionst get_instructions_for_types(
7777
for (const cegis_operand_datat::value_type &typeWithSlots : signature)
7878
{
7979
const typet &type=typeWithSlots.first;
80-
if (!is_cegis_primitive(type))
81-
assert(!"Class type operand generation not supported.");
80+
if (!is_cegis_primitive(type)) continue; // TODO: Add support for class types
8281
const arithmetic_instructionst arith(type);
8382
insert(result, arith.plus());
8483
insert(result, arith.minus());

src/cegis/refactor/instructionset/cegis_processor_body_factory.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@
1111
#include <cegis/refactor/instructionset/cegis_instruction_factory.h>
1212
#include <cegis/refactor/instructionset/cegis_processor_body_factory.h>
1313

14-
// XXX: Debug
15-
#include <iostream>
16-
// XXX: Debug
17-
1814
#define NUM_PRIMITIVE_OPERANDS 3u
1915

2016
namespace
2117
{
2218
size_t cegis_max_operands(const typet &type)
2319
{
24-
if (!is_cegis_primitive(type))
25-
assert(!"Class type operand generation not supported.");
20+
if (!is_cegis_primitive(type)) return 0; // TODO: Add support for class types
2621
return NUM_PRIMITIVE_OPERANDS;
2722
}
2823
}
@@ -251,9 +246,7 @@ void remove_skips(goto_programt::instructionst &instrs)
251246
{
252247
if (!pos->is_skip()) continue;
253248
const goto_programt::targett successor(std::next(pos));
254-
for (goto_programt::instructiont &instr : instrs)
255-
for (goto_programt::targett &target : instr.targets)
256-
if (target == pos) target=successor;
249+
move_labels(instrs, pos, successor);
257250
pos=instrs.erase(pos);
258251
}
259252
}
@@ -273,8 +266,8 @@ void generate_processor_body(symbol_tablet &st, goto_programt &body,
273266
}
274267
body.add_instruction(goto_program_instruction_typet::END_FUNCTION);
275268
//remove_singleton_switch_cases(body);
276-
remove_goto_next(body);
277-
remove_skips(body.instructions);
269+
//remove_goto_next(body);
270+
//remove_skips(body.instructions);
278271
body.compute_loop_numbers();
279272
body.update();
280273
}

0 commit comments

Comments
 (0)