|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Dynamic frame condition checking |
| 4 | +
|
| 5 | +Author: Qinheping Hu, [email protected] |
| 6 | +Author: Remi Delmas, [email protected] |
| 7 | +
|
| 8 | +\*******************************************************************/ |
| 9 | + |
| 10 | +#include "dfcc_loop_tags.h" |
| 11 | + |
| 12 | +const irep_idt ID_loop_id = "loop-id"; |
| 13 | +const irep_idt ID_loop_head = "loop-head"; |
| 14 | +const irep_idt ID_loop_body = "loop-body"; |
| 15 | +const irep_idt ID_loop_latch = "loop-latch"; |
| 16 | +const irep_idt ID_loop_exiting = "loop-exiting"; |
| 17 | +const irep_idt ID_loop_top_level = "loop-top-level"; |
| 18 | + |
| 19 | +void dfcc_set_loop_id( |
| 20 | + goto_programt::instructiont::targett &target, |
| 21 | + const std::size_t loop_id) |
| 22 | +{ |
| 23 | + target->source_location_nonconst().set(ID_loop_id, loop_id); |
| 24 | +} |
| 25 | + |
| 26 | +optionalt<std::size_t> |
| 27 | +dfcc_get_loop_id(const goto_programt::instructiont::targett &target) |
| 28 | +{ |
| 29 | + if(target->source_location_nonconst().get(ID_loop_id).empty()) |
| 30 | + return {}; |
| 31 | + |
| 32 | + return target->source_location_nonconst().get_size_t(ID_loop_id); |
| 33 | +} |
| 34 | + |
| 35 | +bool dfcc_has_loop_id( |
| 36 | + const goto_programt::instructiont::targett &target, |
| 37 | + std::size_t loop_id) |
| 38 | +{ |
| 39 | + auto loop_id_opt = dfcc_get_loop_id(target); |
| 40 | + return loop_id_opt.has_value() && loop_id_opt.value() == loop_id; |
| 41 | +} |
| 42 | + |
| 43 | +static void dfcc_set_loop_tag( |
| 44 | + goto_programt::instructiont::targett &target, |
| 45 | + const irep_idt &tag) |
| 46 | +{ |
| 47 | + target->source_location_nonconst().set(tag, true); |
| 48 | +} |
| 49 | + |
| 50 | +static bool has_loop_tag( |
| 51 | + const goto_programt::instructiont::targett &target, |
| 52 | + const irep_idt &tag) |
| 53 | +{ |
| 54 | + return target->source_location().get_bool(tag); |
| 55 | +} |
| 56 | + |
| 57 | +void dfcc_set_loop_head(goto_programt::instructiont::targett &target) |
| 58 | +{ |
| 59 | + dfcc_set_loop_tag(target, ID_loop_head); |
| 60 | +} |
| 61 | + |
| 62 | +bool dfcc_is_loop_head(const goto_programt::instructiont::targett &target) |
| 63 | +{ |
| 64 | + return has_loop_tag(target, ID_loop_head); |
| 65 | +} |
| 66 | + |
| 67 | +void dfcc_set_loop_body(goto_programt::instructiont::targett &target) |
| 68 | +{ |
| 69 | + dfcc_set_loop_tag(target, ID_loop_body); |
| 70 | +} |
| 71 | + |
| 72 | +bool dfcc_is_loop_body(const goto_programt::instructiont::targett &target) |
| 73 | +{ |
| 74 | + return has_loop_tag(target, ID_loop_body); |
| 75 | +} |
| 76 | + |
| 77 | +void dfcc_set_loop_exiting(goto_programt::instructiont::targett &target) |
| 78 | +{ |
| 79 | + dfcc_set_loop_tag(target, ID_loop_exiting); |
| 80 | +} |
| 81 | + |
| 82 | +bool dfcc_is_loop_exiting(const goto_programt::instructiont::targett &target) |
| 83 | +{ |
| 84 | + return has_loop_tag(target, ID_loop_exiting); |
| 85 | +} |
| 86 | + |
| 87 | +void dfcc_set_loop_latch(goto_programt::instructiont::targett &target) |
| 88 | +{ |
| 89 | + dfcc_set_loop_tag(target, ID_loop_latch); |
| 90 | +} |
| 91 | + |
| 92 | +bool dfcc_is_loop_latch(const goto_programt::instructiont::targett &target) |
| 93 | +{ |
| 94 | + return has_loop_tag(target, ID_loop_latch); |
| 95 | +} |
| 96 | + |
| 97 | +void dfcc_set_loop_top_level(goto_programt::instructiont::targett &target) |
| 98 | +{ |
| 99 | + dfcc_set_loop_tag(target, ID_loop_top_level); |
| 100 | +} |
| 101 | + |
| 102 | +bool dfcc_is_loop_top_level(const goto_programt::instructiont::targett &target) |
| 103 | +{ |
| 104 | + return has_loop_tag(target, ID_loop_top_level); |
| 105 | +} |
| 106 | + |
| 107 | +void dfcc_remove_loop_tags(source_locationt &source_location) |
| 108 | +{ |
| 109 | + source_location.remove(ID_loop_id); |
| 110 | + source_location.remove(ID_loop_head); |
| 111 | + source_location.remove(ID_loop_body); |
| 112 | + source_location.remove(ID_loop_exiting); |
| 113 | + source_location.remove(ID_loop_latch); |
| 114 | + source_location.remove(ID_loop_top_level); |
| 115 | +} |
| 116 | + |
| 117 | +void dfcc_remove_loop_tags(goto_programt::targett &target) |
| 118 | +{ |
| 119 | + dfcc_remove_loop_tags(target->source_location_nonconst()); |
| 120 | +} |
| 121 | + |
| 122 | +void dfcc_remove_loop_tags(goto_programt &goto_program) |
| 123 | +{ |
| 124 | + for(auto target = goto_program.instructions.begin(); |
| 125 | + target != goto_program.instructions.end(); |
| 126 | + target++) |
| 127 | + { |
| 128 | + dfcc_remove_loop_tags(target); |
| 129 | + } |
| 130 | +} |
0 commit comments