Skip to content

Commit 8fe2c5e

Browse files
authored
Merge pull request #668 from diffblue/default_aval_bval_encoding
Verilog: default aval/bval lowering
2 parents 19e246d + 320d532 commit 8fe2c5e

File tree

7 files changed

+58
-16
lines changed

7 files changed

+58
-16
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
minus1.sv
33

44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
The result is wrong.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
mult1.sv
33

44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
The result is wrong.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
plus1.sv
33

44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
The result is wrong.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
unary_minus1.sv
33

44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
The result is wrong.

src/verilog/aval_bval_encoding.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ bv_typet aval_bval_type(std::size_t width, irep_idt source_type)
3636

3737
bv_typet lower_to_aval_bval(const typet &src)
3838
{
39-
PRECONDITION(
40-
src.id() == ID_verilog_unsignedbv || src.id() == ID_verilog_signedbv);
39+
PRECONDITION(is_four_valued(src));
4140
return aval_bval_type(to_bitvector_type(src).get_width(), src.id());
4241
}
4342

@@ -75,9 +74,7 @@ typet aval_bval_underlying(const typet &src)
7574

7675
constant_exprt lower_to_aval_bval(const constant_exprt &src)
7776
{
78-
PRECONDITION(
79-
src.type().id() == ID_verilog_signedbv ||
80-
src.type().id() == ID_verilog_unsignedbv);
77+
PRECONDITION(is_four_valued(src.type()));
8178

8279
auto new_type = lower_to_aval_bval(src.type());
8380
auto width = aval_bval_width(new_type);
@@ -256,7 +253,7 @@ exprt has_xz(const exprt &expr)
256253
return false_exprt{}; // it's two-valued
257254
}
258255

259-
/// return 'x', one bit, in aval_bval encoding
256+
/// return 'x'
260257
exprt make_x(const typet &type)
261258
{
262259
PRECONDITION(is_four_valued(type));
@@ -539,3 +536,33 @@ exprt aval_bval(const shift_exprt &expr)
539536
auto x = make_x(expr.type());
540537
return if_exprt{distance_has_xz, x, combined};
541538
}
539+
540+
exprt default_aval_bval_lowering(const exprt &expr)
541+
{
542+
auto &type = expr.type();
543+
544+
PRECONDITION(is_four_valued(type));
545+
546+
exprt::operandst disjuncts;
547+
for(auto &op : expr.operands())
548+
disjuncts.push_back(has_xz(op));
549+
550+
auto has_xz = disjunction(disjuncts);
551+
552+
exprt two_valued_expr = expr; // copy
553+
554+
for(auto &op : two_valued_expr.operands())
555+
op = aval_underlying(op); // replace by aval
556+
557+
if(type.id() == ID_verilog_unsignedbv)
558+
two_valued_expr.type() = unsignedbv_typet{to_bitvector_type(type).width()};
559+
else if(type.id() == ID_verilog_signedbv)
560+
two_valued_expr.type() = signedbv_typet{to_bitvector_type(type).width()};
561+
else
562+
PRECONDITION(false);
563+
564+
return if_exprt{
565+
has_xz,
566+
make_x(type),
567+
aval_bval_conversion(two_valued_expr, lower_to_aval_bval(type))};
568+
}

src/verilog/aval_bval_encoding.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ exprt aval_bval(const typecast_exprt &);
6868
/// lowering for shifts
6969
exprt aval_bval(const shift_exprt &);
7070

71+
/// If any operand has x/z, then the result is 'x'.
72+
/// Otherwise, the result is the expression applied to the aval
73+
/// of the operands.
74+
exprt default_aval_bval_lowering(const exprt &);
75+
7176
#endif

src/verilog/verilog_lowering.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,23 @@ exprt verilog_lowering(exprt expr)
625625
{
626626
// turn into floatbv
627627
expr.type() = verilog_lowering(expr.type());
628+
return expr;
628629
}
629-
630-
return expr;
630+
else if(is_four_valued(expr))
631+
{
632+
return default_aval_bval_lowering(expr);
633+
}
634+
else
635+
return expr;
636+
}
637+
else if(
638+
expr.id() == ID_plus || expr.id() == ID_minus || expr.id() == ID_mult ||
639+
expr.id() == ID_div || expr.id() == ID_mod)
640+
{
641+
if(is_four_valued(expr))
642+
return default_aval_bval_lowering(expr);
643+
else
644+
return expr;
631645
}
632646
else if(expr.id() == ID_lshr || expr.id() == ID_ashr || expr.id() == ID_shl)
633647
{

0 commit comments

Comments
 (0)