Skip to content

Commit c7035a4

Browse files
committed
Updates requested in the review.
1 parent 954dd0a commit c7035a4

File tree

2 files changed

+42
-45
lines changed

2 files changed

+42
-45
lines changed

src/taint-slicer/irept_instrument.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ Date: May 2017
1313

1414
#include <taint-slicer/irept_instrument.h>
1515

16-
static bool are_equal(const irept l, const irept r)
17-
{
18-
return &l.read()==&r.read();
19-
}
16+
// WARNING: 'irept' does not support equality check and its explicit use
17+
// in functions below was not appreciated (see PR #132). Equivalence
18+
// checks are thus used. And so, in case of performance issues in the
19+
// instrumenter focus your attention also to profiling of these checks.
2020

2121
irept instrument(const irept irep, const instrumenter_fnt &instrumenter)
2222
{
2323
bool modified=false;
2424

2525
irept::subt new_sub;
26-
for(const irept sub : irep.get_sub())
26+
for(const irept &sub : irep.get_sub())
2727
{
2828
new_sub.push_back(instrument(sub, instrumenter));
29-
if(!are_equal(new_sub.back(), sub))
29+
if(new_sub.back()!=sub)
3030
modified=true;
3131
}
3232

3333
irept::named_subt new_named_sub;
34-
for(const irept::named_subt::value_type name_sub : irep.get_named_sub())
34+
for(const irept::named_subt::value_type &name_sub : irep.get_named_sub())
3535
{
3636
const auto it_bool=
3737
new_named_sub.insert(
@@ -40,12 +40,12 @@ irept instrument(const irept irep, const instrumenter_fnt &instrumenter)
4040
instrument(name_sub.second, instrumenter)
4141
});
4242
assert(it_bool.second);
43-
if(!are_equal(it_bool.first->second, name_sub.second))
43+
if(it_bool.first->second!=name_sub.second)
4444
modified=true;
4545
}
4646

4747
irept::named_subt new_comments;
48-
for(const irept::named_subt::value_type name_sub : irep.get_comments())
48+
for(const irept::named_subt::value_type &name_sub : irep.get_comments())
4949
{
5050
const auto it_bool=
5151
new_comments.insert(
@@ -54,7 +54,7 @@ irept instrument(const irept irep, const instrumenter_fnt &instrumenter)
5454
instrument(name_sub.second, instrumenter)
5555
});
5656
assert(it_bool.second);
57-
if(!are_equal(it_bool.first->second, name_sub.second))
57+
if(it_bool.first->second!=name_sub.second)
5858
modified=true;
5959
}
6060

@@ -69,55 +69,57 @@ irept instrument(const irept irep, const instrumenter_fnt &instrumenter)
6969
return instrumenter(irep);
7070
}
7171

72-
irept instrument_using_pivot(
72+
irept instrument_using_guide(
7373
const irept pivot,
7474
const irept irep,
75-
const pivot_instrumenter_fnt &instrumenter)
75+
const guide_instrumenter_fnt &instrumenter)
7676
{
7777
bool modified=false;
7878

7979
irept::subt new_sub;
8080
for(auto pit=pivot.get_sub().cbegin(), iit=irep.get_sub().cbegin();
8181
pit!=pivot.get_sub().cend() && iit!=irep.get_sub().cend(); ++pit, ++iit)
8282
{
83-
new_sub.push_back(instrument_using_pivot(*pit, *iit, instrumenter));
84-
if(!are_equal(new_sub.back(), *iit))
83+
new_sub.push_back(instrument_using_guide(*pit, *iit, instrumenter));
84+
if(new_sub.back()!=*iit)
8585
modified=true;
8686
}
8787

8888
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() &&
89+
for(auto iit=irep.get_named_sub().cbegin();
9290
iit!=irep.get_named_sub().cend();
93-
++pit, ++iit)
91+
++iit)
9492
{
93+
const auto pit=pivot.get_named_sub().find(iit->first);
9594
const auto it_bool=
9695
new_named_sub.insert(
9796
{
9897
iit->first,
99-
instrument_using_pivot(pit->second, iit->second, instrumenter)
98+
pit!=pivot.get_named_sub().cend() ?
99+
instrument_using_guide(pit->second, iit->second, instrumenter):
100+
iit->second
100101
});
101102
assert(it_bool.second);
102-
if(!are_equal(it_bool.first->second, iit->second))
103+
if(it_bool.first->second!=iit->second)
103104
modified=true;
104105
}
105106

106107
irept::named_subt new_comments;
107-
for(auto pit=pivot.get_comments().cbegin(),
108-
iit=irep.get_comments().cbegin();
109-
pit!=pivot.get_comments().cend() &&
108+
for(auto iit=irep.get_comments().cbegin();
110109
iit!=irep.get_comments().cend();
111-
++pit, ++iit)
110+
++iit)
112111
{
112+
auto pit=pivot.get_comments().find(iit->first);
113113
const auto it_bool=
114114
new_comments.insert(
115115
{
116116
iit->first,
117-
instrument_using_pivot(pit->second, iit->second, instrumenter)
117+
pit!=pivot.get_comments().cend() ?
118+
instrument_using_guide(pit->second, iit->second, instrumenter):
119+
iit->second
118120
});
119121
assert(it_bool.second);
120-
if(!are_equal(it_bool.first->second, iit->second))
122+
if(it_bool.first->second!=iit->second)
121123
modified=true;
122124
}
123125

src/taint-slicer/irept_instrument.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ proces of "irept" hierarchical and shared data structures.
2727
/// functions looking only into the passed instance (i.e. not into
2828
/// 'irept' hierarchy below the passed instance).
2929
typedef std::function<irept(irept)> instrumenter_fnt;
30-
typedef std::function<irept(irept, irept)> pivot_instrumenter_fnt;
30+
typedef std::function<irept(irept, irept)> guide_instrumenter_fnt;
3131

3232
/*******************************************************************\
3333
@@ -42,13 +42,7 @@ typedef std::function<irept(irept, irept)> pivot_instrumenter_fnt;
4242
the hierarchy it calls the passed instrumenter. The result of the
4343
function is a new 'irept' hierarchy constructed from the original
4444
one by traversing it bottom-up and by applying the instrumenter on
45-
each visited node. It is possible that in the end the new hierarchy
46-
shares some nodes with the original hierarchy. Namely, a node in the
47-
new hierarchy is NOT a node of the original hierarchy only if
48-
(a) The instrumenter returned for that node a new (different) node,
49-
(b) The instrumenter returned for that node the same node, but in the
50-
sub-hierarchy under that node there is a node for which the case (a)
51-
was applied.
45+
each visited node.
5246
5347
\*******************************************************************/
5448
irept instrument(const irept irep, const instrumenter_fnt &instrumenter);
@@ -62,22 +56,23 @@ irept instrument(const irept irep, const instrumenter_fnt &instrumenter);
6256
Outputs:
6357
6458
Purpose:
65-
The function builds an instrumented copy of a passed hierarchy of
59+
Builds an instrumented copy of a passed hierarchy of
6660
'irept's in the same way as the function 'instrument' above. However,
67-
this version allows the user to also specify a 'pivot' hierarchy of
68-
'irept's providing more refined instrumentation. For instance, the
69-
instrumenter is called only on that topological part of the hierarchy
70-
matching the topology of the pivot. Also, the instrumenter called for
71-
some node may use the corresponding pivot node to decide how the
61+
this version allows the user to also specify a 'guide' hierarchy of
62+
'irept's providing more refined instrumentation.
63+
The instrumenter is called only on that topological part of the hierarchy
64+
matching the topology of the guide. Positional and named operands not present
65+
in the guide irep are left unaltered. Also, the instrumenter called for
66+
some node may use the corresponding guide node to decide how the
7267
instrumentation will be performed. For example, imagine two nodes of
7368
the exactly the same kind of the instrumenter passed with the different
74-
kinds of pivot nodes. The intrumenter may then return nodes of different
75-
kinds (according to kinds of pivot nodes).
69+
kinds of guide nodes. The intrumenter may then return nodes of different
70+
kinds (according to kinds of guide nodes).
7671
7772
\*******************************************************************/
78-
irept instrument_using_pivot(
79-
const irept pivot,
73+
irept instrument_using_guide(
74+
const irept guide,
8075
const irept irep,
81-
const pivot_instrumenter_fnt &instrumenter);
76+
const guide_instrumenter_fnt &instrumenter);
8277

8378
#endif

0 commit comments

Comments
 (0)