-
Notifications
You must be signed in to change notification settings - Fork 275
CONTRACTS: loop info tagging utility functions #7632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
remi-delmas-3000
merged 1 commit into
diffblue:develop
from
remi-delmas-3000:contracts-loop-tagging
Apr 6, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/goto-instrument/contracts/dynamic-frames/dfcc_loop_tags.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Dynamic frame condition checking | ||
|
||
Author: Qinheping Hu, [email protected] | ||
Author: Remi Delmas, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#include "dfcc_loop_tags.h" | ||
|
||
const irep_idt ID_loop_id = "loop-id"; | ||
const irep_idt ID_loop_head = "loop-head"; | ||
const irep_idt ID_loop_body = "loop-body"; | ||
const irep_idt ID_loop_latch = "loop-latch"; | ||
const irep_idt ID_loop_exiting = "loop-exiting"; | ||
const irep_idt ID_loop_top_level = "loop-top-level"; | ||
|
||
void dfcc_set_loop_id( | ||
goto_programt::instructiont::targett &target, | ||
const std::size_t loop_id) | ||
{ | ||
target->source_location_nonconst().set(ID_loop_id, loop_id); | ||
} | ||
|
||
optionalt<std::size_t> | ||
dfcc_get_loop_id(const goto_programt::instructiont::targett &target) | ||
{ | ||
if(target->source_location_nonconst().get(ID_loop_id).empty()) | ||
return {}; | ||
|
||
return target->source_location_nonconst().get_size_t(ID_loop_id); | ||
} | ||
|
||
bool dfcc_has_loop_id( | ||
const goto_programt::instructiont::targett &target, | ||
std::size_t loop_id) | ||
{ | ||
auto loop_id_opt = dfcc_get_loop_id(target); | ||
return loop_id_opt.has_value() && loop_id_opt.value() == loop_id; | ||
} | ||
|
||
static void dfcc_set_loop_tag( | ||
goto_programt::instructiont::targett &target, | ||
const irep_idt &tag) | ||
{ | ||
target->source_location_nonconst().set(tag, true); | ||
} | ||
|
||
static bool has_loop_tag( | ||
const goto_programt::instructiont::targett &target, | ||
const irep_idt &tag) | ||
{ | ||
return target->source_location().get_bool(tag); | ||
} | ||
|
||
void dfcc_set_loop_head(goto_programt::instructiont::targett &target) | ||
{ | ||
dfcc_set_loop_tag(target, ID_loop_head); | ||
} | ||
|
||
bool dfcc_is_loop_head(const goto_programt::instructiont::targett &target) | ||
{ | ||
return has_loop_tag(target, ID_loop_head); | ||
} | ||
|
||
void dfcc_set_loop_body(goto_programt::instructiont::targett &target) | ||
{ | ||
dfcc_set_loop_tag(target, ID_loop_body); | ||
} | ||
|
||
bool dfcc_is_loop_body(const goto_programt::instructiont::targett &target) | ||
{ | ||
return has_loop_tag(target, ID_loop_body); | ||
} | ||
|
||
void dfcc_set_loop_exiting(goto_programt::instructiont::targett &target) | ||
{ | ||
dfcc_set_loop_tag(target, ID_loop_exiting); | ||
} | ||
|
||
bool dfcc_is_loop_exiting(const goto_programt::instructiont::targett &target) | ||
{ | ||
return has_loop_tag(target, ID_loop_exiting); | ||
} | ||
|
||
void dfcc_set_loop_latch(goto_programt::instructiont::targett &target) | ||
{ | ||
dfcc_set_loop_tag(target, ID_loop_latch); | ||
} | ||
|
||
bool dfcc_is_loop_latch(const goto_programt::instructiont::targett &target) | ||
{ | ||
return has_loop_tag(target, ID_loop_latch); | ||
} | ||
|
||
void dfcc_set_loop_top_level(goto_programt::instructiont::targett &target) | ||
{ | ||
dfcc_set_loop_tag(target, ID_loop_top_level); | ||
} | ||
|
||
bool dfcc_is_loop_top_level(const goto_programt::instructiont::targett &target) | ||
{ | ||
return has_loop_tag(target, ID_loop_top_level); | ||
} | ||
|
||
void dfcc_remove_loop_tags(source_locationt &source_location) | ||
{ | ||
source_location.remove(ID_loop_id); | ||
source_location.remove(ID_loop_head); | ||
source_location.remove(ID_loop_body); | ||
source_location.remove(ID_loop_exiting); | ||
source_location.remove(ID_loop_latch); | ||
source_location.remove(ID_loop_top_level); | ||
} | ||
|
||
void dfcc_remove_loop_tags(goto_programt::targett &target) | ||
remi-delmas-3000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
dfcc_remove_loop_tags(target->source_location_nonconst()); | ||
} | ||
|
||
void dfcc_remove_loop_tags(goto_programt &goto_program) | ||
{ | ||
for(auto target = goto_program.instructions.begin(); | ||
target != goto_program.instructions.end(); | ||
target++) | ||
{ | ||
dfcc_remove_loop_tags(target); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/goto-instrument/contracts/dynamic-frames/dfcc_loop_tags.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Dynamic frame condition checking for loop contracts | ||
|
||
Author: Qinheping Hu, [email protected] | ||
Author: Remi Delmas, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Functions that allow to tag GOTO instructions with loop identifiers and | ||
/// loop instruction type: head, body, exiting, latch. | ||
|
||
#ifndef CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_LOOP_TAGS_H | ||
#define CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_LOOP_TAGS_H | ||
|
||
#include <goto-programs/goto_program.h> | ||
|
||
void dfcc_set_loop_id( | ||
goto_programt::instructiont::targett &target, | ||
std::size_t loop_id); | ||
|
||
bool dfcc_has_loop_id( | ||
const goto_programt::instructiont::targett &target, | ||
std::size_t loop_id); | ||
|
||
optionalt<std::size_t> | ||
dfcc_get_loop_id(const goto_programt::instructiont::targett &target); | ||
|
||
void dfcc_set_loop_head(goto_programt::instructiont::targett &target); | ||
bool dfcc_is_loop_head(const goto_programt::instructiont::targett &target); | ||
|
||
void dfcc_set_loop_body(goto_programt::instructiont::targett &target); | ||
bool dfcc_is_loop_body(const goto_programt::instructiont::targett &target); | ||
|
||
void dfcc_set_loop_exiting(goto_programt::instructiont::targett &target); | ||
bool dfcc_is_loop_exiting(const goto_programt::instructiont::targett &target); | ||
|
||
void dfcc_set_loop_latch(goto_programt::instructiont::targett &target); | ||
bool dfcc_is_loop_latch(const goto_programt::instructiont::targett &target); | ||
|
||
void dfcc_set_loop_top_level(goto_programt::instructiont::targett &target); | ||
bool dfcc_is_loop_top_level(const goto_programt::instructiont::targett &target); | ||
|
||
void dfcc_remove_loop_tags(source_locationt &source_location); | ||
void dfcc_remove_loop_tags(goto_programt &goto_program); | ||
void dfcc_remove_loop_tags(goto_programt::targett &target); | ||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.