Skip to content

CONTRACTS: add loop contract mode enum and string conversion functions #7628

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/goto-instrument/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ SRC = accelerate/accelerate.cpp \
contracts/contracts.cpp \
contracts/dynamic-frames/dfcc_utils.cpp \
contracts/dynamic-frames/dfcc_loop_nesting_graph.cpp \
contracts/dynamic-frames/dfcc_contract_mode.cpp \
contracts/dynamic-frames/dfcc_loop_contract_mode.cpp \
contracts/dynamic-frames/dfcc_library.cpp \
contracts/dynamic-frames/dfcc_is_cprover_symbol.cpp \
contracts/dynamic-frames/dfcc_is_fresh.cpp \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************\

Module: Dynamic frame condition checking for function contracts

Author: Remi Delmas, [email protected]

Date: March 2023

\*******************************************************************/

#include "dfcc_contract_mode.h"

#include <util/invariant.h>

std::string dfcc_contract_mode_to_string(const dfcc_contract_modet mode)
{
switch(mode)
{
case dfcc_contract_modet::CHECK:
return "dfcc_contract_modet::CHECK";
case dfcc_contract_modet::REPLACE:
return "dfcc_contract_modet::REPLACE";
}
UNREACHABLE;
}

std::ostream &operator<<(std::ostream &os, const dfcc_contract_modet mode)
{
os << dfcc_contract_mode_to_string(mode);
return os;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ Date: August 2022
#ifndef CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_CONTRACT_MODE_H
#define CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_CONTRACT_MODE_H

#include <string>

/// Enum type representing the contract checking and replacement modes.
enum class dfcc_contract_modet
{
CHECK,
REPLACE
};

std::string dfcc_contract_mode_to_string(const dfcc_contract_modet mode);

std::ostream &operator<<(std::ostream &os, const dfcc_contract_modet mode);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************\

Module: Dynamic frame condition checking for function contracts

Author: Remi Delmas, [email protected]

Date: March 2023

\*******************************************************************/

#include "dfcc_loop_contract_mode.h"

#include <util/invariant.h>

dfcc_loop_contract_modet dfcc_loop_contract_mode_from_bools(
bool apply_loop_contracts,
bool unwind_transformed_loops)
{
if(apply_loop_contracts)
{
if(unwind_transformed_loops)
{
return dfcc_loop_contract_modet::APPLY_UNWIND;
}
else
{
return dfcc_loop_contract_modet::APPLY;
}
}
else
{
return dfcc_loop_contract_modet::NONE;
}
}

std::string
dfcc_loop_contract_mode_to_string(const dfcc_loop_contract_modet mode)
{
switch(mode)
{
case dfcc_loop_contract_modet::NONE:
return "dfcc_loop_contract_modet::NONE";
case dfcc_loop_contract_modet::APPLY:
return "dfcc_loop_contract_modet::APPLY";
case dfcc_loop_contract_modet::APPLY_UNWIND:
return "dfcc_loop_contract_modet::APPLY_UNWIND";
}
UNREACHABLE;
}

std::ostream &operator<<(std::ostream &os, const dfcc_loop_contract_modet mode)
{
os << dfcc_loop_contract_mode_to_string(mode);
return os;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************\

Module: Dynamic frame condition checking for function contracts

Author: Remi Delmas, [email protected]

\*******************************************************************/

/// \file
/// Enumeration representing the instrumentation mode for loop contracts.

#ifndef CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_LOOP_CONTRACT_MODE_H
#define CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_LOOP_CONTRACT_MODE_H

#include <string>

/// Enumeration representing the instrumentation mode for loop contracts.
enum class dfcc_loop_contract_modet
{
/// Do not apply loop contracts
NONE,
/// Apply loop contracts
APPLY,
/// Apply loop contracts and unwind the resulting base + step encoding
APPLY_UNWIND
};

/// Generates an enum value from boolean flags for application and unwinding.
dfcc_loop_contract_modet dfcc_loop_contract_mode_from_bools(
bool apply_loop_contracts,
bool unwind_transformed_loops);

std::string dfcc_loop_contract_mode_to_string(dfcc_loop_contract_modet mode);

std::ostream &operator<<(std::ostream &os, const dfcc_loop_contract_modet mode);

#endif