Skip to content

Commit d6b956b

Browse files
committed
Introducing irept_instrumenter.
1 parent a853b6a commit d6b956b

File tree

3 files changed

+197
-0
lines changed

3 files changed

+197
-0
lines changed

src/taint-slicer/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SRC = slicer.cpp \
44
instrumentation_props.cpp \
55
instrumenter.cpp \
66
slicing_tasks_builder.cpp \
7+
irept_instrument.cpp \
78
# end of SRC
89

910
INCLUDES= -I .. -I ../../cbmc/src -I ../../boost

src/taint-slicer/irept_instrument.cpp

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*******************************************************************\
2+
3+
Module: irept_instrument
4+
5+
Author: Marek Trtik
6+
7+
Date: May 2017
8+
9+
10+
@ Copyright Diffblue, Ltd.
11+
12+
\*******************************************************************/
13+
14+
#include <taint-slicer/irept_instrument.h>
15+
16+
irept make_shallow_copy(const irept irep)
17+
{
18+
irept result(irep.id());
19+
result.get_sub()=irep.get_sub();
20+
result.get_named_sub()=irep.get_named_sub();
21+
result.get_comments()=irep.get_comments();
22+
return result;
23+
}
24+
25+
irept instrument(const irept irep, const instrumenter_fnt &instrumenter)
26+
{
27+
bool modified=false;
28+
29+
irept::subt new_sub;
30+
for(const irept sub : irep.get_sub())
31+
{
32+
new_sub.push_back(instrument(sub, instrumenter));
33+
if(new_sub.back()!=sub)
34+
modified=true;
35+
}
36+
37+
irept::named_subt new_named_sub;
38+
for(const irept::named_subt::value_type name_sub : irep.get_named_sub())
39+
{
40+
const auto it_bool=
41+
new_named_sub.insert({
42+
name_sub.first,
43+
instrument(name_sub.second, instrumenter)});
44+
assert(it_bool.second);
45+
if(it_bool.first->second!=name_sub.second)
46+
modified=true;
47+
}
48+
49+
irept::named_subt new_comments;
50+
for(const irept::named_subt::value_type name_sub : irep.get_comments())
51+
{
52+
const auto it_bool=
53+
new_comments.insert({
54+
name_sub.first,
55+
instrument(name_sub.second, instrumenter)});
56+
assert(it_bool.second);
57+
if(it_bool.first->second!=name_sub.second)
58+
modified=true;
59+
}
60+
61+
if(modified)
62+
{
63+
irept result(irep.id());
64+
result.get_sub()=new_sub;
65+
result.get_named_sub()=new_named_sub;
66+
result.get_comments()=new_comments;
67+
return instrumenter(result);
68+
}
69+
return instrumenter(irep);
70+
}
71+
72+
irept instrument_using_pivot(
73+
const irept pivot,
74+
const irept irep,
75+
const pivot_instrumenter_fnt &instrumenter)
76+
{
77+
bool modified=false;
78+
79+
irept::subt new_sub;
80+
for(auto pit=pivot.get_sub().cbegin(), iit=irep.get_sub().cbegin();
81+
pit!=pivot.get_sub().cend() && iit!=irep.get_sub().cend(); ++pit, ++iit)
82+
{
83+
new_sub.push_back(instrument_using_pivot(*pit, *iit, instrumenter));
84+
if(new_sub.back()!=*iit)
85+
modified=true;
86+
}
87+
88+
irept::named_subt new_named_sub;
89+
for(auto pit=pivot.get_named_sub().cbegin(),
90+
iit=irep.get_named_sub().cbegin();
91+
pit!=pivot.get_named_sub().cend() &&
92+
iit!=irep.get_named_sub().cend();
93+
++pit, ++iit)
94+
{
95+
const auto it_bool=
96+
new_named_sub.insert({
97+
iit->first,
98+
instrument_using_pivot(pit->second, iit->second, instrumenter)});
99+
assert(it_bool.second);
100+
if(it_bool.first->second!=iit->second)
101+
modified=true;
102+
}
103+
104+
irept::named_subt new_comments;
105+
for(auto pit=pivot.get_comments().cbegin(),
106+
iit=irep.get_comments().cbegin();
107+
pit!=pivot.get_comments().cend() &&
108+
iit!=irep.get_comments().cend();
109+
++pit, ++iit)
110+
{
111+
const auto it_bool=
112+
new_comments.insert({
113+
iit->first,
114+
instrument_using_pivot(pit->second, iit->second, instrumenter)});
115+
assert(it_bool.second);
116+
if(it_bool.first->second!=iit->second)
117+
modified=true;
118+
}
119+
120+
if(modified)
121+
{
122+
irept result(irep.id());
123+
result.get_sub()=new_sub;
124+
result.get_named_sub()=new_named_sub;
125+
result.get_comments()=new_comments;
126+
return instrumenter(pivot, result);
127+
}
128+
return instrumenter(pivot, irep);
129+
}

src/taint-slicer/irept_instrument.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*******************************************************************\
2+
3+
Module: irept_instrument
4+
5+
Author: Marek Trtik
6+
7+
Date: May 2017
8+
9+
The module provides utility functuions simplifying the instrumentation
10+
proces of "irept" hierarchical and shared data structures.
11+
12+
@ Copyright Diffblue, Ltd.
13+
14+
\*******************************************************************/
15+
16+
#ifndef CPROVER_TAINT_IREPT_INSTRUMENT_H
17+
#define CPROVER_TAINT_IREPT_INSTRUMENT_H
18+
19+
#include <util/irep.h>
20+
#include <functional>
21+
22+
typedef std::function<irept(irept)> instrumenter_fnt;
23+
typedef std::function<irept(irept, irept)> pivot_instrumenter_fnt;
24+
25+
/*******************************************************************\
26+
27+
Function:
28+
29+
Inputs:
30+
31+
Outputs:
32+
33+
Purpose:
34+
35+
\*******************************************************************/
36+
irept make_shallow_copy(const irept irep);
37+
38+
/*******************************************************************\
39+
40+
Function:
41+
42+
Inputs:
43+
44+
Outputs:
45+
46+
Purpose:
47+
48+
\*******************************************************************/
49+
irept instrument(const irept irep, const instrumenter_fnt &instrumenter);
50+
51+
/*******************************************************************\
52+
53+
Function:
54+
55+
Inputs:
56+
57+
Outputs:
58+
59+
Purpose:
60+
61+
\*******************************************************************/
62+
irept instrument_using_pivot(
63+
const irept pivot,
64+
const irept irep,
65+
const pivot_instrumenter_fnt &instrumenter);
66+
67+
#endif

0 commit comments

Comments
 (0)