Skip to content

Commit fcbf249

Browse files
author
Pascal Kesseli
committed
Added null object range extraction.
1 parent 9db4612 commit fcbf249

File tree

14 files changed

+171
-6
lines changed

14 files changed

+171
-6
lines changed
Binary file not shown.

regression/cegis/cegis_refactor_benchmark_01/Runner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ void print(ITaxCalculator calc, double price) {
2828
System.out.print(percentage);
2929
System.out.println('%');
3030
}
31+
static void main() {
32+
}
3133
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
Runner.class
3+
--gcc --cegis-refactor --cegis-refactor-null-object --cegis-statistics --cegis-genetic
4+
^VERIFICATION FAILED$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

src/cegis/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ SRC = danger/meta/meta_variable_names.cpp danger/facade/danger_runner.cpp danger
5959
refactor/verify/refactor_symex_verify.cpp \
6060
refactor/facade/refactor_runner.cpp \
6161
refactor/options/refactor_program.cpp refactor/value/refactor_solution.cpp \
62+
refactor/nullobject/range_collector.cpp \
6263
wordsize/restrict_bv_size.cpp value/program_individual_serialisation.cpp value/assignments_printer.cpp \
6364
seed/literals_seed.cpp \
6465
genetic/instruction_set_info_factory.cpp genetic/random_mutate.cpp genetic/random_cross.cpp \
@@ -68,7 +69,7 @@ SRC = danger/meta/meta_variable_names.cpp danger/facade/danger_runner.cpp danger
6869
cegis-util/task_pool.cpp cegis-util/constant_width.cpp cegis-util/irep_pipe.cpp cegis-util/program_helper.cpp \
6970
cegis-util/temporary_output_block.cpp cegis-util/cbmc_runner.cpp cegis-util/module_helper.cpp \
7071
cegis-util/inline_user_program.cpp cegis-util/counterexample_vars.cpp cegis-util/string_helper.cpp \
71-
cegis-util/type_helper.cpp \
72+
cegis-util/instruction_iterator.cpp cegis-util/type_helper.cpp \
7273
learn/insert_counterexample.cpp learn/constraint_helper.cpp \
7374
constant/add_constant.cpp constant/literals_collector.cpp constant/default_cegis_constant_strategy.cpp \
7475
instrument/cegis_library.cpp instrument/instrument_var_ops.cpp instrument/meta_variables.cpp \

src/cegis/cegis-util/goto_range.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*******************************************************************
2+
3+
Module: Counterexample-Guided Inductive Synthesis
4+
5+
Author: Daniel Kroening, [email protected]
6+
Pascal Kesseli, [email protected]
7+
8+
\*******************************************************************/
9+
10+
#include <goto-programs/goto_program.h>
11+
12+
/**
13+
* @brief
14+
*
15+
* @details
16+
*/
17+
typedef std::pair<goto_programt::targett, goto_programt::targett> goto_ranget;

src/cegis/cegis-util/inline_user_program.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <goto-programs/goto_inline.h>
55

66
#include <cegis/cegis-util/program_helper.h>
7-
#include <cegis/cegis-util/inline_user_program.h>
87

98
namespace
109
{

src/cegis/refactor/facade/refactor_runner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
int run_refactor(optionst &options, messaget::mstreamt &result,
1010
const symbol_tablet &st, const goto_functionst &gf)
1111
{
12-
refactor_preprocessingt preproc;
12+
refactor_preprocessingt preproc(options, st, gf);
1313
refactor_symex_learnt learn_cfg;
1414
refactor_symex_verifyt verify_cfg;
1515
cegis_symex_learnt<refactor_preprocessingt, refactor_symex_learnt> learn(
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <cegis/cegis-util/instruction_iterator.h>
2+
3+
#include <cegis/refactor/options/refactor_program.h>
4+
#include <cegis/refactor/nullobject/range_collector.h>
5+
6+
// XXX: Debug
7+
#include <iostream>
8+
// XXX: Debug
9+
10+
namespace
11+
{
12+
bool is_null_comparison(const exprt &guard)
13+
{
14+
const irep_idt &id=guard.id();
15+
if (ID_equal != id && ID_notequal != id) return false;
16+
const binary_relation_exprt &binary=to_binary_relation_expr(guard);
17+
return ID_NULL == binary.lhs().id() || ID_NULL == binary.rhs().id();
18+
}
19+
20+
class null_reference_type_extractort: public const_expr_visitort
21+
{
22+
public:
23+
typet reference_type;
24+
25+
virtual ~null_reference_type_extractort()=default;
26+
27+
virtual void operator()(const exprt &expr)
28+
{
29+
if (ID_symbol == expr.id()) reference_type=expr.type();
30+
}
31+
};
32+
33+
typet get_reference_type(const exprt &guard)
34+
{
35+
null_reference_type_extractort extractor;
36+
guard.visit(extractor);
37+
return extractor.reference_type;
38+
}
39+
40+
goto_ranget get_then_range(const goto_programt::targett &else_range_last)
41+
{
42+
const goto_programt::targett then_range_first(else_range_last);
43+
const goto_programt::targett last_else_instr(std::prev(else_range_last));
44+
if (GOTO != last_else_instr->type)
45+
return goto_ranget(then_range_first, then_range_first);
46+
return goto_ranget(then_range_first, last_else_instr->get_target());
47+
}
48+
}
49+
50+
void collect_nullobject_ranges(refactor_programt &prog)
51+
{
52+
for (instr_iteratort it(prog.gf); it != instr_iteratort::end; ++it)
53+
{
54+
if (goto_program_instruction_typet::GOTO != it->type) continue;
55+
if (!is_null_comparison(it->guard)) continue;
56+
const goto_programt::targett else_range_last(it->get_target());
57+
const goto_ranget else_range(++it, else_range_last);
58+
const goto_ranget then_range(get_then_range(else_range_last));
59+
if (ID_equal == it->guard.id())
60+
{
61+
prog.spec_ranges.push_back(else_range);
62+
prog.input_ranges.push_back(then_range);
63+
} else
64+
{
65+
prog.spec_ranges.push_back(then_range);
66+
prog.input_ranges.push_back(else_range);
67+
}
68+
}
69+
// XXX: Debug
70+
std::cout << "<collect_nullobject_range>" << std::endl;
71+
prog.gf.output(namespacet(prog.st), std::cout);
72+
std::cout << "</collect_nullobject_range>" << std::endl;
73+
// XXX: Debug
74+
// TODO: Implement
75+
assert(false);
76+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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_NULLOBJECT_RANGE_COLLECTOR_H_
11+
#define CEGIS_REFACTOR_NULLOBJECT_RANGE_COLLECTOR_H_
12+
13+
/**
14+
* @brief
15+
*
16+
* @details
17+
*/
18+
void collect_nullobject_ranges(class refactor_programt &prog);
19+
20+
#endif /* CEGIS_REFACTOR_NULLOBJECT_RANGE_COLLECTOR_H_ */

src/cegis/refactor/options/refactor_program.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
#ifndef CEGIS_REFACTOR_OPTIONS_REFACTOR_PROGRAM_H_
1111
#define CEGIS_REFACTOR_OPTIONS_REFACTOR_PROGRAM_H_
1212

13+
#include <deque>
14+
1315
#include <goto-programs/goto_functions.h>
1416

17+
#include <cegis/cegis-util/goto_range.h>
18+
1519
/**
1620
* @brief
1721
*
@@ -30,6 +34,20 @@ class refactor_programt
3034
*/
3135
goto_programt::targetst counterexample_locations;
3236

37+
/**
38+
* @brief
39+
*
40+
* @details
41+
*/
42+
std::deque<goto_ranget> input_ranges;
43+
44+
/**
45+
* @brief
46+
*
47+
* @details
48+
*/
49+
std::deque<goto_ranget> spec_ranges;
50+
3351
/**
3452
* @brief
3553
*

src/cegis/refactor/preprocessing/refactor_preprocessing.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
#include <util/options.h>
2+
3+
#include <cegis/options/parameters.h>
4+
#include <cegis/cegis-util/inline_user_program.h>
5+
#include <cegis/refactor/nullobject/range_collector.h>
16
#include <cegis/refactor/preprocessing/refactor_preprocessing.h>
27

3-
refactor_preprocessingt::refactor_preprocessingt()
8+
refactor_preprocessingt::refactor_preprocessingt(const optionst &options,
9+
const symbol_tablet &st, const goto_functionst &gf) :
10+
options(options), original_program(st, gf)
411
{
512
}
613

714
void refactor_preprocessingt::operator()()
815
{
16+
inline_user_program(original_program.st, original_program.gf);
17+
if (options.get_bool_option(CEGIS_NULL_OBJECT_REFACTOR))
18+
{
19+
collect_nullobject_ranges(original_program);
20+
}
921
// TODO: Implement
1022
assert(false);
1123
}

src/cegis/refactor/preprocessing/refactor_preprocessing.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@
1919
*/
2020
class refactor_preprocessingt
2121
{
22+
const class optionst &options;
23+
refactor_programt original_program;
24+
refactor_programt current_program;
2225
public:
2326
/**
2427
* @brief
2528
*
2629
* @details
30+
*
31+
* @param options
32+
* @param st
33+
* @param gf
2734
*/
28-
explicit refactor_preprocessingt();
35+
explicit refactor_preprocessingt(
36+
const optionst &options,
37+
const symbol_tablet &st,
38+
const goto_functionst &gf);
2939

3040
/**
3141
* @brief

src/cegis/runner/cegis_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void cegis_parse_optionst::get_command_line_options(optionst &options)
8888
options.set_option(CEGIS_SHOW_ITERATIONS, cmdline.isset(CEGIS_SHOW_ITERATIONS));
8989
options.set_option(CEGIS_KEEP_GOTO_PROGRAMS, cmdline.isset(CEGIS_KEEP_GOTO_PROGRAMS));
9090
set_integer_option(options, cmdline, CEGIS_MAX_RUNTIME, 300u);
91+
options.set_option(CEGIS_NULL_OBJECT_REFACTOR, cmdline.isset(CEGIS_NULL_OBJECT_REFACTOR));
9192
}
9293
}
9394

src/cegis/runner/cegis_parse_options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Author: Daniel Kroening, [email protected]
2020
"(cegis-genetic-mutation-rate):(cegis-genetic-replace-rate):" \
2121
"(cegis-limit-wordsize)(cegis-parallel-verify)(cegis-symex-head-start):" \
2222
"(safety)(danger)(jsa)(danger-max-size):(danger-no-ranking)" \
23-
"(cegis-control)"
23+
"(cegis-control)" \
24+
"(cegis-refactor)(cegis-refactor-null-object)"
2425

2526
class cegis_parse_optionst: public cbmc_parse_optionst
2627
{

0 commit comments

Comments
 (0)