|
| 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 | +} |
0 commit comments