|
| 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 | +// 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. |
| 20 | + |
| 21 | +irept instrument(const irept irep, const instrumenter_fnt &instrumenter) |
| 22 | +{ |
| 23 | + bool modified=false; |
| 24 | + |
| 25 | + irept::subt new_sub; |
| 26 | + for(const irept &sub : irep.get_sub()) |
| 27 | + { |
| 28 | + new_sub.push_back(instrument(sub, instrumenter)); |
| 29 | + if(new_sub.back()!=sub) |
| 30 | + modified=true; |
| 31 | + } |
| 32 | + |
| 33 | + irept::named_subt new_named_sub; |
| 34 | + for(const irept::named_subt::value_type &name_sub : irep.get_named_sub()) |
| 35 | + { |
| 36 | + const auto it_bool= |
| 37 | + new_named_sub.insert( |
| 38 | + { |
| 39 | + name_sub.first, |
| 40 | + instrument(name_sub.second, instrumenter) |
| 41 | + }); |
| 42 | + assert(it_bool.second); |
| 43 | + if(it_bool.first->second!=name_sub.second) |
| 44 | + modified=true; |
| 45 | + } |
| 46 | + |
| 47 | + irept::named_subt new_comments; |
| 48 | + for(const irept::named_subt::value_type &name_sub : irep.get_comments()) |
| 49 | + { |
| 50 | + const auto it_bool= |
| 51 | + new_comments.insert( |
| 52 | + { |
| 53 | + name_sub.first, |
| 54 | + instrument(name_sub.second, instrumenter) |
| 55 | + }); |
| 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_guide( |
| 73 | + const irept pivot, |
| 74 | + const irept irep, |
| 75 | + const guide_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_guide(*pit, *iit, instrumenter)); |
| 84 | + if(new_sub.back()!=*iit) |
| 85 | + modified=true; |
| 86 | + } |
| 87 | + |
| 88 | + irept::named_subt new_named_sub; |
| 89 | + for(auto iit=irep.get_named_sub().cbegin(); |
| 90 | + iit!=irep.get_named_sub().cend(); |
| 91 | + ++iit) |
| 92 | + { |
| 93 | + const auto pit=pivot.get_named_sub().find(iit->first); |
| 94 | + const auto it_bool= |
| 95 | + new_named_sub.insert( |
| 96 | + { |
| 97 | + iit->first, |
| 98 | + pit!=pivot.get_named_sub().cend() ? |
| 99 | + instrument_using_guide(pit->second, iit->second, instrumenter): |
| 100 | + iit->second |
| 101 | + }); |
| 102 | + assert(it_bool.second); |
| 103 | + if(it_bool.first->second!=iit->second) |
| 104 | + modified=true; |
| 105 | + } |
| 106 | + |
| 107 | + irept::named_subt new_comments; |
| 108 | + for(auto iit=irep.get_comments().cbegin(); |
| 109 | + iit!=irep.get_comments().cend(); |
| 110 | + ++iit) |
| 111 | + { |
| 112 | + auto pit=pivot.get_comments().find(iit->first); |
| 113 | + const auto it_bool= |
| 114 | + new_comments.insert( |
| 115 | + { |
| 116 | + iit->first, |
| 117 | + pit!=pivot.get_comments().cend() ? |
| 118 | + instrument_using_guide(pit->second, iit->second, instrumenter): |
| 119 | + iit->second |
| 120 | + }); |
| 121 | + assert(it_bool.second); |
| 122 | + if(it_bool.first->second!=iit->second) |
| 123 | + modified=true; |
| 124 | + } |
| 125 | + |
| 126 | + if(modified) |
| 127 | + { |
| 128 | + irept result(irep.id()); |
| 129 | + result.get_sub()=new_sub; |
| 130 | + result.get_named_sub()=new_named_sub; |
| 131 | + result.get_comments()=new_comments; |
| 132 | + return instrumenter(pivot, result); |
| 133 | + } |
| 134 | + return instrumenter(pivot, irep); |
| 135 | +} |
0 commit comments