Skip to content

Commit 295cdef

Browse files
authored
Merge pull request #1024 from diffblue/arithmetic1
SMV: word-level arithmetic
2 parents 783d93d + b25c8c6 commit 295cdef

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

regression/smv/word/arithmetic1.desc

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

regression/smv/word/arithmetic1.smv

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
MODULE main
2+
3+
SPEC uwconst(123, 8) + uwconst(1, 8) = uwconst(124, 8)
4+
SPEC uwconst(123, 8) + uwconst(200, 8) = uwconst(67, 8)
5+
SPEC uwconst(123, 8) - uwconst(1, 8) = uwconst(122, 8)
6+
SPEC uwconst(123, 8) - uwconst(200, 8) = uwconst(179, 8)
7+
SPEC uwconst(123, 8) * uwconst(2, 8) = uwconst(246, 8)
8+
SPEC uwconst(123, 8) * uwconst(3, 8) = uwconst(113, 8)
9+
SPEC uwconst(123, 8) / uwconst(2, 8) = uwconst(61, 8)
10+
SPEC uwconst(123, 8) / uwconst(3, 8) = uwconst(41, 8)
11+
SPEC uwconst(123, 8) mod uwconst(2, 8) = uwconst(1, 8)
12+
SPEC uwconst(123, 8) mod uwconst(3, 8) = uwconst(0, 8)
13+
SPEC -uwconst(123, 8) = uwconst(133, 8)
14+
15+
SPEC swconst(123, 8) + swconst(1, 8) = swconst(124, 8)
16+
SPEC swconst(123, 8) + swconst(-56, 8) = swconst(67, 8)
17+
SPEC swconst(123, 8) - swconst(1, 8) = swconst(122, 8)
18+
SPEC swconst(123, 8) - swconst(-56, 8) = swconst(-77, 8)
19+
SPEC swconst(123, 8) * swconst(2, 8) = swconst(-10, 8)
20+
SPEC swconst(123, 8) * swconst(3, 8) = swconst(113, 8)
21+
SPEC swconst(123, 8) / swconst(2, 8) = swconst(61, 8)
22+
SPEC swconst(123, 8) / swconst(3, 8) = swconst(41, 8)
23+
SPEC swconst(123, 8) mod swconst(2, 8) = swconst(1, 8)
24+
SPEC swconst(123, 8) mod swconst(3, 8) = swconst(0, 8)
25+
SPEC -swconst(123, 8) = swconst(-123, 8)

src/smvlang/expr2smv.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@ bool expr2smvt::convert(
595595
return convert_binary(
596596
src, dest, src.id_string(), precedence = precedencet::MULT);
597597

598+
else if(src.id() == ID_mod)
599+
return convert_binary(
600+
src, dest, src.id_string(), precedence = precedencet::MULT);
601+
598602
else if(src.id() == ID_smv_setin)
599603
return convert_binary(src, dest, "in", precedence = precedencet::IN);
600604

src/smvlang/scanner.l

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ void newlocation(YYSTYPE &x)
200200
"!" return NOT_Token;
201201
"+" return PLUS_Token;
202202
"-" return MINUS_Token;
203+
"*" return TIMES_Token;
204+
"/" return DIVIDE_Token;
203205
"|" return OR_Token;
204206
"&" return AND_Token;
205207
"->" return IMPLIES_Token;

src/smvlang/smv_typecheck.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,10 +1004,16 @@ void smv_typecheckt::typecheck_expr_rec(exprt &expr, modet mode)
10041004
uminus_expr.type() =
10051005
(-smv_ranget::from_type(to_range_type(op_type))).to_type();
10061006
}
1007+
else if(op_type.id() == ID_signedbv || op_type.id() == ID_unsignedbv)
1008+
{
1009+
uminus_expr.type() = op_type;
1010+
}
10071011
else
1012+
{
10081013
throw errort().with_location(expr.source_location())
1009-
<< "Operand to unary minus must be integer, but got "
1014+
<< "Operand to unary minus must be integer or word type, but got "
10101015
<< to_string(op_type);
1016+
}
10111017

10121018
// constant folding
10131019
if(uminus_expr.op().is_constant())

0 commit comments

Comments
 (0)