-
Notifications
You must be signed in to change notification settings - Fork 19
introduce sva_boolean_exprt
#1083
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
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
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
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
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 |
---|---|---|
|
@@ -23,12 +23,26 @@ Author: Daniel Kroening, [email protected] | |
exprt normalize_pre_sva_non_overlapped_implication( | ||
sva_non_overlapped_implication_exprt expr) | ||
{ | ||
// Same as a->always[1:1] b if lhs is not a sequence. | ||
if(!is_SVA_sequence_operator(expr.lhs())) | ||
// a|=>b is the same as a->always[1:1] b if lhs is not a proper sequence. | ||
if(expr.lhs().id() == ID_sva_boolean) | ||
{ | ||
const auto &lhs_cond = to_sva_boolean_expr(expr.lhs()).op(); | ||
auto one = natural_typet{}.one_expr(); | ||
return or_exprt{ | ||
not_exprt{expr.lhs()}, sva_ranged_always_exprt{one, one, expr.rhs()}}; | ||
not_exprt{lhs_cond}, sva_ranged_always_exprt{one, one, expr.rhs()}}; | ||
} | ||
else | ||
return std::move(expr); | ||
} | ||
|
||
exprt normalize_pre_sva_overlapped_implication( | ||
sva_overlapped_implication_exprt expr) | ||
{ | ||
// a|->b is the same as a->b if lhs is not a proper sequence. | ||
if(expr.lhs().id() == ID_sva_boolean) | ||
{ | ||
const auto &lhs_cond = to_sva_boolean_expr(expr.lhs()).op(); | ||
return implies_exprt{lhs_cond, expr.rhs()}; | ||
} | ||
else | ||
return std::move(expr); | ||
|
@@ -42,6 +56,11 @@ exprt normalize_property_rec(exprt expr) | |
expr = normalize_pre_sva_non_overlapped_implication( | ||
to_sva_non_overlapped_implication_expr(expr)); | ||
} | ||
else if(expr.id() == ID_sva_overlapped_implication) | ||
{ | ||
expr = normalize_pre_sva_overlapped_implication( | ||
to_sva_overlapped_implication_expr(expr)); | ||
} | ||
else if(expr.id() == ID_sva_nexttime) | ||
{ | ||
auto one = natural_typet{}.one_expr(); | ||
|
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 |
---|---|---|
|
@@ -13,15 +13,14 @@ Author: Daniel Kroening, [email protected] | |
|
||
/// This applies the following rewrites: | ||
/// | ||
/// cover(φ) --> G¬φ | ||
/// | ||
/// -----Propositional----- | ||
/// ¬(a ∨ b) --> ¬a ∧ ¬b | ||
/// ¬(a ∧ b) --> ¬a ∨ ¬b | ||
/// (a -> b) --> ¬a ∨ b | ||
/// | ||
/// -----SVA----- | ||
/// sva_non_overlapped_implication --> ¬a ∨ always[1:1] b if a is not an SVA sequence | ||
/// a|=>b --> ¬a ∨ always[1:1] b if a is not an SVA sequence | ||
/// a|->b --> a⇒b if a is not an SVA sequence | ||
/// sva_nexttime φ --> sva_always[1:1] φ | ||
/// sva_nexttime[i] φ --> sva_always[i:i] φ | ||
/// sva_s_nexttime φ --> sva_always[1:1] φ | ||
|
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
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 |
---|---|---|
|
@@ -12,12 +12,10 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "temporal_logic.h" | ||
|
||
static std::optional<exprt> is_state_formula(const exprt &expr) | ||
static std::optional<exprt> is_state_predicate(const exprt &expr) | ||
{ | ||
if(expr.id() == ID_typecast && expr.type().id() == ID_verilog_sva_sequence) | ||
return to_typecast_expr(expr).op(); | ||
else if(expr.type().id() == ID_bool) | ||
return expr; | ||
if(expr.id() == ID_sva_boolean) | ||
return to_sva_boolean_expr(expr).op(); | ||
else | ||
return {}; | ||
} | ||
|
@@ -30,8 +28,8 @@ exprt trivial_sva(exprt expr) | |
// Same as regular implication if lhs and rhs are not sequences. | ||
auto &sva_implication = to_sva_overlapped_implication_expr(expr); | ||
|
||
auto lhs = is_state_formula(sva_implication.lhs()); | ||
auto rhs = is_state_formula(sva_implication.rhs()); | ||
auto lhs = is_state_predicate(sva_implication.lhs()); | ||
auto rhs = is_state_predicate(sva_implication.rhs()); | ||
|
||
if(lhs.has_value() && rhs.has_value()) | ||
expr = implies_exprt{*lhs, *rhs}; | ||
|
@@ -50,23 +48,39 @@ exprt trivial_sva(exprt expr) | |
{ | ||
auto &sva_and = to_sva_and_expr(expr); | ||
|
||
// Same as a ∧ b if the expression is not a sequence. | ||
auto lhs = is_state_formula(sva_and.lhs()); | ||
auto rhs = is_state_formula(sva_and.rhs()); | ||
|
||
if(lhs.has_value() && rhs.has_value()) | ||
expr = and_exprt{*lhs, *rhs}; | ||
// can be sequence or property | ||
if(expr.type().id() == ID_verilog_sva_sequence) | ||
{ | ||
// Same as a ∧ b if the expression is not a sequence. | ||
auto lhs = is_state_predicate(sva_and.lhs()); | ||
auto rhs = is_state_predicate(sva_and.rhs()); | ||
|
||
if(lhs.has_value() && rhs.has_value()) | ||
expr = sva_boolean_exprt{and_exprt{*lhs, *rhs}, expr.type()}; | ||
} | ||
else | ||
{ | ||
expr = and_exprt{sva_and.lhs(), sva_and.rhs()}; | ||
} | ||
} | ||
else if(expr.id() == ID_sva_or) | ||
{ | ||
auto &sva_or = to_sva_or_expr(expr); | ||
|
||
// Same as a ∨ b if the expression is not a sequence. | ||
auto lhs = is_state_formula(sva_or.lhs()); | ||
auto rhs = is_state_formula(sva_or.rhs()); | ||
|
||
if(lhs.has_value() && rhs.has_value()) | ||
expr = or_exprt{*lhs, *rhs}; | ||
// can be sequence or property | ||
if(expr.type().id() == ID_verilog_sva_sequence) | ||
{ | ||
// Same as a ∨ b if the expression is not a sequence. | ||
auto lhs = is_state_predicate(sva_or.lhs()); | ||
auto rhs = is_state_predicate(sva_or.rhs()); | ||
|
||
if(lhs.has_value() && rhs.has_value()) | ||
expr = sva_boolean_exprt{or_exprt{*lhs, *rhs}, expr.type()}; | ||
} | ||
else | ||
{ | ||
expr = or_exprt{sva_or.lhs(), sva_or.rhs()}; | ||
} | ||
} | ||
else if(expr.id() == ID_sva_not) | ||
{ | ||
|
@@ -113,9 +127,10 @@ exprt trivial_sva(exprt expr) | |
{ | ||
// We simplify sequences to boolean expressions, and hence can drop | ||
// the sva_sequence_property converter | ||
auto &op = to_sva_sequence_property_expr_base(expr).sequence(); | ||
if(op.type().id() == ID_bool) | ||
return op; | ||
auto &sequence = to_sva_sequence_property_expr_base(expr).sequence(); | ||
auto pred_opt = is_state_predicate(sequence); | ||
if(pred_opt.has_value()) | ||
return *pred_opt; | ||
} | ||
|
||
return expr; | ||
|
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
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
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 |
---|---|---|
|
@@ -13,6 +13,29 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "verilog_types.h" | ||
|
||
/// 1800-2017 16.6 Boolean expressions | ||
/// Conversion of a Boolean expression into a sequence or property | ||
class sva_boolean_exprt : public unary_exprt | ||
{ | ||
public: | ||
sva_boolean_exprt(exprt condition, typet __type) | ||
: unary_exprt(ID_sva_boolean, std::move(condition), std::move(__type)) | ||
{ | ||
} | ||
}; | ||
|
||
static inline const sva_boolean_exprt &to_sva_boolean_expr(const exprt &expr) | ||
{ | ||
sva_boolean_exprt::check(expr, validation_modet::INVARIANT); | ||
return static_cast<const sva_boolean_exprt &>(expr); | ||
} | ||
|
||
static inline sva_boolean_exprt &to_sva_boolean_expr(exprt &expr) | ||
{ | ||
sva_boolean_exprt::check(expr, validation_modet::INVARIANT); | ||
return static_cast<sva_boolean_exprt &>(expr); | ||
} | ||
|
||
/// accept_on, reject_on, sync_accept_on, sync_reject_on, disable_iff | ||
class sva_abort_exprt : public binary_predicate_exprt | ||
{ | ||
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between a sequence and a "proper" sequence?