Skip to content

Commit f22a2c1

Browse files
authored
Merge pull request #994 from diffblue/smv-word-type
SMV: word types
2 parents 9b88d5d + 494e214 commit f22a2c1

29 files changed

+621
-51
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SystemVerilog: typedefs from package scopes
44
* SystemVerilog: assignment patterns with keys for structs
55
* SMV: LTL V operator, xnor operator
6+
* SMV: word types and operators
67

78
# EBMC 5.5
89

regression/smv/word/basic1.desc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
basic1.smv
3+
--bound 0 --trace
4+
^ s1 = 0sd8_123 \(01111011\)$
5+
^ u1 = 0ud8_123 \(01111011\)$
6+
^EXIT=10$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring

regression/smv/word/basic1.smv

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
MODULE main
2+
3+
VAR u1 : word[8];
4+
5+
ASSIGN u1 := uwconst(123, 8);
6+
7+
VAR s1 : signed word[8];
8+
9+
ASSIGN s1 := swconst(123, 8);
10+
11+
SPEC FALSE

regression/smv/word/basic2.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
basic2.smv
3+
--bdd
4+
^\[live\] G F counter = 0ud8_10: PROVED$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

regression/smv/word/basic2.smv

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MODULE main
2+
3+
VAR counter : word[8];
4+
5+
ASSIGN init(counter) := uwconst(0, 8);
6+
ASSIGN next(counter) := counter + uwconst(1, 8);
7+
8+
LTLSPEC NAME live := G F counter = uwconst(10, 8)

regression/smv/word/bitwise1.desc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
bitwise1.smv
3+
4+
^\[.*\] !0ud8_123 = 0ud8_132: PROVED$
5+
^\[.*\] !0sd8_123 = -0sd8_124: PROVED$
6+
^\[.*\] \(0ud8_123 \& 0ud8_7\) = 0ud8_3: PROVED$
7+
^\[.*\] \(0ud8_123 \| 0ud8_7\) = 0ud8_127: PROVED$
8+
^\[.*\] \(0ud8_123 xor 0ud8_7\) = 0ud8_124: PROVED$
9+
^\[.*\] \(0ud8_123 xnor 0ud8_7\) = 0ud8_131: PROVED$
10+
^\[.*\] \(0ud8_123 <-> 0ud8_7\) = 0ud8_131: PROVED$
11+
^EXIT=0$
12+
^SIGNAL=0$
13+
--
14+
^warning: ignoring

regression/smv/word/bitwise1.smv

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
MODULE main
2+
3+
-- negation
4+
SPEC !uwconst(123, 8) = uwconst(132, 8)
5+
SPEC !swconst(123, 8) = swconst(-124, 8)
6+
7+
-- and
8+
SPEC (uwconst(123, 8) & uwconst(7, 8)) = uwconst(3, 8)
9+
10+
-- or
11+
SPEC (uwconst(123, 8) | uwconst(7, 8)) = uwconst(127, 8)
12+
13+
-- xor
14+
SPEC (uwconst(123, 8) xor uwconst(7, 8)) = uwconst(124, 8)
15+
16+
-- xnor
17+
SPEC (uwconst(123, 8) xnor uwconst(7, 8)) = uwconst(131, 8)
18+
19+
-- implication
20+
--SPEC (uwconst(123, 8) -> uwconst(7, 8)) = uwconst(135, 8)
21+
22+
-- iff
23+
SPEC (uwconst(123, 8) <-> uwconst(7, 8)) = uwconst(131, 8)

regression/smv/word/concat1.desc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
concat1.smv
3+
4+
^\[.*\] 0ud8_123 :: 0ud8_1 = 0ud16_31489: PROVED$
5+
^\[.*\] 0sd8_123 :: 0sd8_1 = 0ud16_31489: PROVED$
6+
^\[.*\] 0sd8_123 :: 0ud8_1 = 0ud16_31489: PROVED$
7+
^EXIT=0$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring

regression/smv/word/concat1.smv

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
MODULE main
2+
3+
SPEC uwconst(123, 8) :: uwconst(1, 8) = uwconst(31489, 16)
4+
5+
-- concatenation is unsigned
6+
SPEC swconst(123, 8) :: swconst(1, 8) = uwconst(31489, 16)
7+
SPEC swconst(123, 8) :: uwconst(1, 8) = uwconst(31489, 16)

regression/smv/word/extend1.desc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
KNOWNBUG
2+
extend1.smv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/smv/word/extend1.smv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MODULE main
2+
3+
SPEC extend(uwconst(1, 1), 7) = uwconst(1, 8)
4+
SPEC extend(swconst(-1, 1), 7) = swconst(-1, 8)

regression/smv/word/extractbits1.desc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
shift1.smv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/smv/word/extractbits1.smv

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MODULE main
2+
3+
SPEC uwconst(123, 8)[0:0] = uwconst(1, 1)
4+
SPEC uwconst(123, 8)[7:7] = uwconst(0, 1)
5+
6+
-- always unsigned
7+
SPEC swconst(123, 8)[0:0] = uwconst(1, 1)
8+
SPEC swconst(123, 8)[7:7] = uwconst(0, 1)

regression/smv/word/resize1.desc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
KNOWNBUG
2+
resize1.smv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/smv/word/resize1.smv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MODULE main
2+
3+
SPEC resize(uwconst(1, 1), 8) = uwconst(1, 8)
4+
SPEC resize(swconst(123, 1), 1) = swconst(-1, 1)

regression/smv/word/shift1.desc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CORE
2+
shift1.smv
3+
4+
^\[.*\] 0ud8_123 >> 0 = 0ud8_123: PROVED$
5+
^\[.*\] 0ud8_123 >> 1 = 0ud8_61: PROVED$
6+
^\[.*\] 0ud8_123 >> 8 = 0ud8_0: PROVED$
7+
^\[.*\] 0ud8_123 << 0 = 0ud8_123: PROVED$
8+
^\[.*\] 0ud8_123 << 1 = 0ud8_246: PROVED$
9+
^\[.*\] 0ud8_123 << 2 = 0ud8_236: PROVED$
10+
^\[.*\] 0sd8_123 >> 0 = 0sd8_123: PROVED$
11+
^\[.*\] 0sd8_123 >> 1 = 0sd8_61: PROVED$
12+
^\[.*\] 0sd8_123 >> 8 = 0sd8_0: PROVED$
13+
^\[.*\] 0sd8_123 << 0 = 0sd8_123: PROVED$
14+
^\[.*\] 0sd8_123 << 1 = -0sd8_10: PROVED$
15+
^\[.*\] 0sd8_123 << 2 = -0sd8_20: PROVED$
16+
^EXIT=0$
17+
^SIGNAL=0$
18+
--
19+
^warning: ignoring

regression/smv/word/shift1.smv

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
MODULE main
2+
3+
SPEC uwconst(123, 8) >> 0 = uwconst(123, 8)
4+
SPEC uwconst(123, 8) >> 1 = uwconst(61, 8)
5+
SPEC uwconst(123, 8) >> 8 = uwconst(0, 8)
6+
SPEC uwconst(123, 8) << 0 = uwconst(123, 8)
7+
SPEC uwconst(123, 8) << 1 = uwconst(246, 8)
8+
SPEC uwconst(123, 8) << 2 = uwconst(236, 8)
9+
10+
SPEC swconst(123, 8) >> 0 = swconst(123, 8)
11+
SPEC swconst(123, 8) >> 1 = swconst(61, 8)
12+
SPEC swconst(123, 8) >> 8 = swconst(0, 8)
13+
SPEC swconst(123, 8) << 0 = swconst(123, 8)
14+
SPEC swconst(123, 8) << 1 = swconst(-10, 8)
15+
SPEC swconst(123, 8) << 2 = swconst(-20, 8)

regression/smv/word/signed1.desc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
KNOWNBUG
2+
signed1.smv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/smv/word/signed1.smv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MODULE main
2+
3+
SPEC signed(uwconst(1, 1)) = swconst(-1, 1)

regression/smv/word/sizeof1.desc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
sizeof1.smv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/smv/word/sizeof1.smv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MODULE main
2+
3+
SPEC sizeof(uwconst(0, 1)) = 1
4+
SPEC sizeof(swconst(123, 8)) = 8

regression/smv/word/unsigned1.desc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
KNOWNBUG
2+
unsigned1.smv
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring

regression/smv/word/unsigned1.smv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MODULE main
2+
3+
SPEC unsigned(swconst(-1, 1)) = uwconst(1, 1)

src/hw_cbmc_irep_ids.h

+8
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ IREP_ID_ONE(F)
1717
IREP_ID_ONE(E)
1818
IREP_ID_ONE(G)
1919
IREP_ID_ONE(X)
20+
IREP_ID_ONE(smv_bitimplies)
21+
IREP_ID_ONE(smv_extend)
2022
IREP_ID_ONE(smv_next)
2123
IREP_ID_ONE(smv_iff)
2224
IREP_ID_TWO(C_smv_iff, "#smv_iff")
25+
IREP_ID_ONE(smv_resize)
2326
IREP_ID_ONE(smv_setin)
2427
IREP_ID_ONE(smv_setnotin)
28+
IREP_ID_ONE(smv_signed_cast)
29+
IREP_ID_ONE(smv_sizeof)
30+
IREP_ID_ONE(smv_swconst)
2531
IREP_ID_ONE(smv_union)
32+
IREP_ID_ONE(smv_unsigned_cast)
33+
IREP_ID_ONE(smv_uwconst)
2634
IREP_ID_ONE(smv_H)
2735
IREP_ID_ONE(smv_bounded_H)
2836
IREP_ID_ONE(smv_O)

src/smvlang/expr2smv.cpp

+58-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Author: Daniel Kroening, [email protected]
88

99
#include "expr2smv.h"
1010

11+
#include <util/arith_tools.h>
12+
#include <util/bitvector_types.h>
1113
#include <util/lispexpr.h>
1214
#include <util/lispirep.h>
1315
#include <util/namespace.h>
@@ -114,7 +116,7 @@ class expr2smvt
114116
precedencet &precedence);
115117

116118
bool convert_constant(
117-
const exprt &src,
119+
const constant_exprt &,
118120
std::string &dest,
119121
precedencet &precedence);
120122

@@ -508,14 +510,13 @@ Function: expr2smvt::convert_constant
508510
\*******************************************************************/
509511

510512
bool expr2smvt::convert_constant(
511-
const exprt &src,
513+
const constant_exprt &src,
512514
std::string &dest,
513515
precedencet &precedence)
514516
{
515517
precedence = precedencet::MAX;
516518

517-
const typet &type=src.type();
518-
const std::string &value=src.get_string(ID_value);
519+
const typet &type = src.type();
519520

520521
if(type.id()==ID_bool)
521522
{
@@ -528,7 +529,19 @@ bool expr2smvt::convert_constant(
528529
type.id()==ID_natural ||
529530
type.id()==ID_range ||
530531
type.id()==ID_enumeration)
531-
dest=value;
532+
{
533+
dest = id2string(src.get_value());
534+
}
535+
else if(type.id() == ID_signedbv || type.id() == ID_unsignedbv)
536+
{
537+
auto value_int = numeric_cast_v<mp_integer>(src);
538+
auto value_abs = value_int < 0 ? -value_int : value_int;
539+
auto minus = value_int < 0 ? "-" : "";
540+
auto sign_specifier = type.id() == ID_signedbv ? 's' : 'u';
541+
auto word_width = to_bitvector_type(type).width();
542+
dest = minus + std::string("0") + sign_specifier + 'd' +
543+
std::to_string(word_width) + '_' + integer2string(value_abs);
544+
}
532545
else
533546
return convert_norep(src, dest, precedence);
534547

@@ -611,20 +624,25 @@ bool expr2smvt::convert(
611624
return convert_unary(
612625
to_not_expr(src), dest, "!", precedence = precedencet::NOT);
613626

614-
else if(src.id()==ID_and)
627+
else if(src.id() == ID_and || src.id() == ID_bitand)
615628
return convert_binary(src, dest, "&", precedence = precedencet::AND);
616629

617-
else if(src.id()==ID_or)
630+
else if(src.id() == ID_or || src.id() == ID_bitor)
618631
return convert_binary(src, dest, "|", precedence = precedencet::OR);
619632

620-
else if(src.id()==ID_implies)
633+
else if(src.id() == ID_implies || src.id() == ID_smv_bitimplies)
621634
return convert_binary(src, dest, "->", precedence = precedencet::IMPLIES);
622635

623-
else if(src.id() == ID_xor)
636+
else if(src.id() == ID_xor || src.id() == ID_bitxor)
624637
return convert_binary(src, dest, "xor", precedence = precedencet::OR);
625638

626-
else if(src.id() == ID_xnor)
627-
return convert_binary(src, dest, "xnor", precedence = precedencet::OR);
639+
else if(src.id() == ID_xnor || src.id() == ID_bitxnor)
640+
{
641+
if(src.get_bool(ID_C_smv_iff))
642+
return convert_binary(src, dest, "<->", precedence = precedencet::IFF);
643+
else
644+
return convert_binary(src, dest, "xnor", precedence = precedencet::OR);
645+
}
628646

629647
else if(
630648
src.id() == ID_AG || src.id() == ID_EG || src.id() == ID_AF ||
@@ -716,7 +734,7 @@ bool expr2smvt::convert(
716734
return convert_next_symbol(src, dest, precedence);
717735

718736
else if(src.id()==ID_constant)
719-
return convert_constant(src, dest, precedence);
737+
return convert_constant(to_constant_expr(src), dest, precedence);
720738

721739
else if(src.id()=="smv_nondet_choice")
722740
return convert_nondet_choice(src, dest, precedence);
@@ -736,6 +754,24 @@ bool expr2smvt::convert(
736754
else if(src.id()==ID_cond)
737755
return convert_cond(src, dest);
738756

757+
else if(src.id() == ID_concatenation)
758+
{
759+
return convert_binary(
760+
to_binary_expr(src), dest, "::", precedence = precedencet::CONCAT);
761+
}
762+
763+
else if(src.id() == ID_shl)
764+
{
765+
return convert_binary(
766+
to_binary_expr(src), dest, "<<", precedence = precedencet::SHIFT);
767+
}
768+
769+
else if(src.id() == ID_lshr || src.id() == ID_ashr)
770+
{
771+
return convert_binary(
772+
to_binary_expr(src), dest, ">>", precedence = precedencet::SHIFT);
773+
}
774+
739775
else // no SMV language expression for internal representation
740776
return convert_norep(src, dest, precedence);
741777

@@ -838,6 +874,16 @@ bool type2smv(const typet &type, std::string &code, const namespacet &ns)
838874
code+=')';
839875
}
840876
}
877+
else if(type.id() == ID_signedbv)
878+
{
879+
code =
880+
"signed word[" + std::to_string(to_signedbv_type(type).width()) + ']';
881+
}
882+
else if(type.id() == ID_unsignedbv)
883+
{
884+
code =
885+
"unsigned word[" + std::to_string(to_unsignedbv_type(type).width()) + ']';
886+
}
841887
else
842888
return true;
843889

0 commit comments

Comments
 (0)