-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #656 from diffblue/verilog_equality_lowering
aval/bval lowering for Verilog logical equality
- Loading branch information
Showing
10 changed files
with
150 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
KNOWNBUG | ||
CORE broken-smt-backend | ||
equality1.v | ||
--bound 0 | ||
^EXIT=0$ | ||
^\[.*\] always 10 == 10 === 1: PROVED up to bound 0$ | ||
^\[.*\] always 10 == 20 === 0: PROVED up to bound 0$ | ||
^\[.*\] always 10 != 20 === 1: PROVED up to bound 0$ | ||
^\[.*\] always 10 == 20 === 0: PROVED up to bound 0$ | ||
^\[.*\] always 1'bx == 10 === 1'bx: PROVED up to bound 0$ | ||
^\[.*\] always 1'bz == 20 === 1'bx: PROVED up to bound 0$ | ||
^\[.*\] always 1'bx != 10 === 1'bx: PROVED up to bound 0$ | ||
^\[.*\] always 1'bz != 20 === 1'bx: PROVED up to bound 0$ | ||
^\[.*\] always 2'b11 == 2'b11 === 0: REFUTED$ | ||
^\[.*\] always 2'sb-1 == 2'sb-1 === 1: PROVED up to bound 0$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Missing Verilog case equality implementation. |
This file contains 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 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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
CORE broken-smt-backend | ||
equality2.v | ||
--bound 0 | ||
^EXIT=0$ | ||
^\[.*\] always 10 === 10 == 1: PROVED up to bound 0$ | ||
^\[.*\] always 10 === 20 == 0: PROVED up to bound 0$ | ||
^\[.*\] always 10 !== 10 == 0: PROVED up to bound 0$ | ||
^\[.*\] always 10 !== 20 == 1: PROVED up to bound 0$ | ||
^\[.*\] always 1'bx === 1'bx == 1: PROVED up to bound 0$ | ||
^\[.*\] always 1'bz === 1'bz == 1: PROVED up to bound 0$ | ||
^\[.*\] always 1'bx === 1'bz == 0: PROVED up to bound 0$ | ||
^\[.*\] always 1'bx === 1 == 0: PROVED up to bound 0$ | ||
^\[.*\] always 1'bz === 1 == 0: PROVED up to bound 0$ | ||
^\[.*\] always 1 === 1 == 1: PROVED up to bound 0$ | ||
^\[.*\] always 3'b11 === 3'b111 == 1: REFUTED$ | ||
^\[.*\] always 3'sb-1 === 3'sb-1 == 1: PROVED up to bound 0$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Missing Verilog case equality implementation. |
This file contains 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 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 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 |
---|---|---|
|
@@ -14,6 +14,8 @@ Author: Daniel Kroening, [email protected] | |
#include <util/mathematical_types.h> | ||
#include <util/std_expr.h> | ||
|
||
#include "verilog_types.h" | ||
|
||
bv_typet aval_bval_type(std::size_t width, irep_idt source_type) | ||
{ | ||
PRECONDITION(!source_type.empty()); | ||
|
@@ -34,12 +36,22 @@ bool is_aval_bval(const typet &type) | |
return type.id() == ID_bv && !type.get(ID_C_verilog_aval_bval).empty(); | ||
} | ||
|
||
bool is_aval_bval(const exprt &expr) | ||
{ | ||
return is_aval_bval(expr.type()); | ||
} | ||
|
||
std::size_t aval_bval_width(const typet &type) | ||
{ | ||
PRECONDITION(is_aval_bval(type)); | ||
return to_bv_type(type).get_width() / 2; | ||
} | ||
|
||
std::size_t aval_bval_width(const exprt &expr) | ||
{ | ||
return aval_bval_width(expr.type()); | ||
} | ||
|
||
typet aval_bval_underlying(const typet &src) | ||
{ | ||
auto id = src.get(ID_C_verilog_aval_bval); | ||
|
@@ -198,3 +210,40 @@ exprt aval_bval_concatenation( | |
|
||
return combine_aval_bval(concatenate(new_aval), concatenate(new_bval), type); | ||
} | ||
|
||
/// return true iff 'expr' contains either x or z | ||
exprt has_xz(const exprt &expr) | ||
{ | ||
PRECONDITION(is_aval_bval(expr)); | ||
auto width = aval_bval_width(expr); | ||
return notequal_exprt{bval(expr), bv_typet{width}.all_zeros_expr()}; | ||
} | ||
|
||
/// return 'x', one bit | ||
exprt make_x() | ||
{ | ||
auto type = verilog_unsignedbv_typet{1}; | ||
return lower_to_aval_bval(constant_exprt{ID_x, type}); | ||
} | ||
|
||
exprt aval_bval(const verilog_logical_equality_exprt &expr) | ||
{ | ||
auto &type = expr.type(); | ||
PRECONDITION(type.id() == ID_verilog_unsignedbv); | ||
// returns 'x' if either operand contains x or z | ||
auto has_xz = or_exprt{::has_xz(expr.lhs()), ::has_xz(expr.rhs())}; | ||
auto equality = equal_exprt{expr.lhs(), expr.rhs()}; | ||
return if_exprt{ | ||
has_xz, make_x(), aval_bval_conversion(equality, lower_to_aval_bval(type))}; | ||
} | ||
|
||
exprt aval_bval(const verilog_logical_inequality_exprt &expr) | ||
{ | ||
auto &type = expr.type(); | ||
PRECONDITION(type.id() == ID_verilog_unsignedbv); | ||
// returns 'x' if either operand contains x or z | ||
auto has_xz = or_exprt{::has_xz(expr.lhs()), ::has_xz(expr.rhs())}; | ||
auto equality = notequal_exprt{expr.lhs(), expr.rhs()}; | ||
return if_exprt{ | ||
has_xz, make_x(), aval_bval_conversion(equality, lower_to_aval_bval(type))}; | ||
} |
This file contains 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 |
---|---|---|
|
@@ -10,7 +10,8 @@ Author: Daniel Kroening, [email protected] | |
#define CPROVER_VERILOG_AVAL_BVAL_H | ||
|
||
#include <util/bitvector_types.h> | ||
#include <util/std_expr.h> | ||
|
||
#include "verilog_expr.h" | ||
|
||
// bit-concoding for four-valued types | ||
// | ||
|
@@ -36,4 +37,7 @@ exprt aval_bval_conversion(const exprt &, const typet &); | |
|
||
exprt aval_bval_concatenation(const exprt::operandst &, const typet &); | ||
|
||
exprt aval_bval(const verilog_logical_equality_exprt &); | ||
exprt aval_bval(const verilog_logical_inequality_exprt &); | ||
|
||
#endif |
This file contains 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 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 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