Skip to content

Commit a146411

Browse files
committed
Refactored CEGIS processor body generation.
1 parent 7249da5 commit a146411

13 files changed

+581
-374
lines changed

src/cegis/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ SRC = danger/meta/meta_variable_names.cpp danger/facade/danger_runner.cpp danger
5656
refactor/environment/instrument_state_vars.cpp \
5757
refactor/instructionset/create_cegis_processor.cpp refactor/instructionset/execute_cegis_program.cpp \
5858
refactor/instructionset/processor_types.cpp refactor/instructionset/cegis_processor_body_factory.cpp \
59+
refactor/instructionset/instruction_description.cpp refactor/instructionset/cegis_instruction_factory.cpp \
60+
refactor/instructionset/processor_symbols.cpp \
5961
refactor/preprocessing/refactor_preprocessing.cpp \
6062
refactor/learn/refactor_symex_learn.cpp \
6163
refactor/verify/refactor_symex_verify.cpp \
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include <algorithm>
2+
3+
#include <cegis/instrument/instrument_var_ops.h>
4+
#include <cegis/refactor/instructionset/processor_types.h>
5+
#include <cegis/refactor/instructionset/processor_symbols.h>
6+
#include <cegis/refactor/instructionset/cegis_instruction_factory.h>
7+
8+
namespace
9+
{
10+
class arithmetic_assignt
11+
{
12+
const irep_idt id;
13+
const typet type;
14+
public:
15+
arithmetic_assignt(const irep_idt &id, const typet &type) :
16+
id(id), type(type)
17+
{
18+
}
19+
20+
goto_programt::targett operator()(const symbol_tablet &st,
21+
const std::string &func_name, goto_programt &body,
22+
goto_programt::targett pos) const
23+
{
24+
pos->type=goto_program_instruction_typet::ASSIGN;
25+
pos->source_location=default_cegis_source_location();
26+
const dereference_exprt lhs(cegis_operand(st, func_name, type, 1));
27+
const dereference_exprt rhs(cegis_operand(st, func_name, type, 2));
28+
const binary_exprt result(lhs, id, rhs);
29+
pos->code=code_assignt(cegis_operand(st, func_name, type, 0), result);
30+
return pos;
31+
}
32+
};
33+
34+
class arithmetic_instructionst
35+
{
36+
const typet &type;
37+
const instruction_descriptiont::typest sig;
38+
public:
39+
arithmetic_instructionst(const typet &type) :
40+
type(type), sig( { type, type, type })
41+
{
42+
}
43+
44+
instruction_descriptiont plus() const
45+
{
46+
return instruction_descriptiont(sig, arithmetic_assignt(ID_plus, type));
47+
}
48+
49+
instruction_descriptiont minus() const
50+
{
51+
return instruction_descriptiont(sig, arithmetic_assignt(ID_minus, type));
52+
}
53+
54+
instruction_descriptiont mult() const
55+
{
56+
return instruction_descriptiont(sig, arithmetic_assignt(ID_mult, type));
57+
}
58+
59+
instruction_descriptiont div() const
60+
{
61+
return instruction_descriptiont(sig, arithmetic_assignt(ID_div, type));
62+
}
63+
};
64+
65+
void insert(
66+
std::map<instruction_descriptiont::typest, instruction_descriptionst> &result,
67+
const instruction_descriptiont &instr)
68+
{
69+
result[instr.signature].push_back(instr);
70+
}
71+
}
72+
73+
ordered_instructionst get_instructions_for_types(
74+
const cegis_operand_datat &signature)
75+
{
76+
ordered_instructionst result;
77+
for (const cegis_operand_datat::value_type &typeWithSlots : signature)
78+
{
79+
const typet &type=typeWithSlots.first;
80+
if (!is_cegis_primitive(type))
81+
assert(!"Class type operand generation not supported.");
82+
const arithmetic_instructionst arith(type);
83+
insert(result, arith.plus());
84+
insert(result, arith.minus());
85+
insert(result, arith.mult());
86+
insert(result, arith.div());
87+
}
88+
return result;
89+
}
90+
91+
instruction_descriptionst::size_type num_instrs(
92+
const ordered_instructionst &instrs)
93+
{
94+
return std::accumulate(instrs.begin(), instrs.end(), 0,
95+
[](const size_t count, const ordered_instructionst::value_type &instrs)
96+
{ return count + instrs.second.size();});
97+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************
2+
3+
Module: Counterexample-Guided Inductive Synthesis
4+
5+
Author: Daniel Kroening, kroening@kroening.com
6+
Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk
7+
8+
\*******************************************************************/
9+
10+
#ifndef CEGIS_REFACTOR_INSTRUCTIONSET_CEGIS_INSTRUCTION_FACTORY_H_
11+
#define CEGIS_REFACTOR_INSTRUCTIONSET_CEGIS_INSTRUCTION_FACTORY_H_
12+
13+
#include <cegis/refactor/instructionset/operand_data.h>
14+
#include <cegis/refactor/instructionset/instruction_description.h>
15+
16+
typedef std::map<instruction_descriptiont::typest, instruction_descriptionst> ordered_instructionst;
17+
18+
/**
19+
* @brief
20+
*
21+
* @details
22+
*
23+
* @param signature
24+
*
25+
* @return
26+
*/
27+
ordered_instructionst get_instructions_for_types(
28+
const cegis_operand_datat &signature);
29+
30+
/**
31+
* @brief
32+
*
33+
* @details
34+
*
35+
* @param instrs
36+
*
37+
* @result
38+
*/
39+
instruction_descriptionst::size_type num_instrs(
40+
const ordered_instructionst &instrs);
41+
42+
#endif /* CEGIS_REFACTOR_INSTRUCTIONSET_CEGIS_INSTRUCTION_FACTORY_H_ */

0 commit comments

Comments
 (0)