Skip to content

Commit 0b3fc40

Browse files
author
Pascal Kesseli
committed
Added missing CEGIS helpers.
1 parent fcbf249 commit 0b3fc40

File tree

2 files changed

+204
-0
lines changed

2 files changed

+204
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <cegis/cegis-util/instruction_iterator.h>
2+
3+
namespace
4+
{
5+
bool has_body(const goto_functionst::function_mapt::iterator &it,
6+
const goto_functionst::function_mapt::const_iterator &end)
7+
{
8+
if (end == it) return false;
9+
return it->second.body_available();
10+
}
11+
}
12+
13+
instr_iteratort::instr_iteratort()
14+
{
15+
}
16+
17+
instr_iteratort::instr_iteratort(goto_functionst &gf) :
18+
func_it(gf.function_map.begin()), func_end(gf.function_map.end())
19+
{
20+
while (!has_body(func_it, func_end) && func_end != func_it)
21+
++func_it;
22+
if (has_body(func_it, func_end))
23+
prog_it=func_it->second.body.instructions.begin();
24+
}
25+
26+
instr_iteratort &instr_iteratort::operator++()
27+
{
28+
if (func_it->second.body.instructions.end() == prog_it) do
29+
{
30+
++func_it;
31+
if (func_end == func_it)
32+
{
33+
func_it=goto_functionst::function_mapt::iterator();
34+
prog_it=goto_programt::targett();
35+
break;
36+
} else prog_it=func_it->second.body.instructions.begin();
37+
} while (func_it->second.body.instructions.end() == prog_it);
38+
else ++prog_it;
39+
return *this;
40+
}
41+
42+
instr_iteratort instr_iteratort::operator++(int)
43+
{
44+
const instr_iteratort retval=*this;
45+
operator ++();
46+
return retval;
47+
}
48+
49+
bool instr_iteratort::operator==(const instr_iteratort &other) const
50+
{
51+
return func_it == other.func_it && prog_it == other.prog_it;
52+
}
53+
54+
bool instr_iteratort::operator!=(const instr_iteratort &other) const
55+
{
56+
return func_it != other.func_it && prog_it != other.prog_it;
57+
}
58+
59+
instr_iteratort::reference instr_iteratort::operator*()
60+
{
61+
return *prog_it;
62+
}
63+
64+
instr_iteratort::pointer instr_iteratort::operator->()
65+
{
66+
return &*prog_it;
67+
}
68+
69+
instr_iteratort::operator goto_programt::targett() const
70+
{
71+
return prog_it;
72+
}
73+
74+
goto_programt::targett instr_iteratort::body_end() const
75+
{
76+
return func_it->second.body.instructions.end();
77+
}
78+
79+
const instr_iteratort instr_iteratort::end;
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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_CEGIS_UTIL_INSTRUCTION_ITERATOR_H_
11+
#define CEGIS_CEGIS_UTIL_INSTRUCTION_ITERATOR_H_
12+
13+
#include <iterator>
14+
15+
#include <goto-programs/goto_functions.h>
16+
17+
/**
18+
* @brief
19+
*
20+
* @details
21+
*/
22+
class instr_iteratort: public std::iterator<std::input_iterator_tag,
23+
goto_programt::instructiont>
24+
{
25+
goto_functionst::function_mapt::iterator func_it;
26+
const goto_functionst::function_mapt::const_iterator func_end;
27+
goto_programt::targett prog_it;
28+
29+
/**
30+
* @brief
31+
*
32+
* @details
33+
*/
34+
explicit instr_iteratort();
35+
public:
36+
/**
37+
* @brief
38+
*
39+
* @details
40+
*
41+
* @param gf
42+
*/
43+
explicit instr_iteratort(goto_functionst &gf);
44+
45+
/**
46+
* @brief
47+
*
48+
* @details
49+
*
50+
* @return
51+
*/
52+
instr_iteratort &operator++();
53+
54+
/**
55+
* @brief
56+
*
57+
* @details
58+
*
59+
* @return
60+
*/
61+
instr_iteratort operator++(int);
62+
63+
/**
64+
* @brief
65+
*
66+
* @details
67+
*
68+
* @return
69+
*/
70+
bool operator==(const instr_iteratort &other) const;
71+
72+
/**
73+
* @brief
74+
*
75+
* @details
76+
*
77+
* @return
78+
*/
79+
bool operator!=(const instr_iteratort &other) const;
80+
81+
/**
82+
* @brief
83+
*
84+
* @details
85+
*
86+
* @return
87+
*/
88+
reference operator*();
89+
90+
/**
91+
* @brief
92+
*
93+
* @details
94+
*
95+
* @return
96+
*/
97+
pointer operator->();
98+
99+
/**
100+
* @brief
101+
*
102+
* @details
103+
*
104+
* @return
105+
*/
106+
operator goto_programt::targett() const;
107+
108+
/**
109+
* @brief
110+
*
111+
* @details
112+
*
113+
* @return
114+
*/
115+
goto_programt::targett body_end() const;
116+
117+
/**
118+
* @brief
119+
*
120+
* @details
121+
*/
122+
static const instr_iteratort end;
123+
};
124+
125+
#endif /* CEGIS_CEGIS_UTIL_INSTRUCTION_ITERATOR_H_ */

0 commit comments

Comments
 (0)