Skip to content

Commit 04a227a

Browse files
committed
SMV: introduce classes for extend, resize, signed, unsigned
This introduces classes for the existing SMV expressions.
1 parent f20c412 commit 04a227a

File tree

2 files changed

+170
-8
lines changed

2 files changed

+170
-8
lines changed

src/smvlang/smv_expr.h

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*******************************************************************\
2+
3+
Module: SMV Expressions
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_SMV_EXPR_H
10+
#define CPROVER_SMV_EXPR_H
11+
12+
class smv_resize_exprt : public binary_exprt
13+
{
14+
public:
15+
smv_resize_exprt(exprt __op, constant_exprt __size, typet __type)
16+
: binary_exprt{
17+
std::move(__op),
18+
ID_smv_resize,
19+
std::move(__size),
20+
std::move(__type)}
21+
{
22+
}
23+
24+
const exprt &op() const
25+
{
26+
return op0();
27+
}
28+
29+
exprt &op()
30+
{
31+
return op0();
32+
}
33+
34+
const constant_exprt &size() const
35+
{
36+
return static_cast<const constant_exprt &>(op1());
37+
}
38+
39+
constant_exprt &size()
40+
{
41+
return static_cast<constant_exprt &>(op1());
42+
}
43+
44+
protected:
45+
using binary_exprt::op0;
46+
using binary_exprt::op1;
47+
};
48+
49+
inline const smv_resize_exprt &to_smv_resize_expr(const exprt &expr)
50+
{
51+
PRECONDITION(expr.id() == ID_smv_resize);
52+
smv_resize_exprt::check(expr);
53+
return static_cast<const smv_resize_exprt &>(expr);
54+
}
55+
56+
inline smv_resize_exprt &to_smv_resize_expr(exprt &expr)
57+
{
58+
PRECONDITION(expr.id() == ID_smv_resize);
59+
smv_resize_exprt::check(expr);
60+
return static_cast<smv_resize_exprt &>(expr);
61+
}
62+
63+
class smv_extend_exprt : public binary_exprt
64+
{
65+
public:
66+
smv_extend_exprt(exprt __op, constant_exprt __size, typet __type)
67+
: binary_exprt{
68+
std::move(__op),
69+
ID_smv_extend,
70+
std::move(__size),
71+
std::move(__type)}
72+
{
73+
}
74+
75+
const exprt &op() const
76+
{
77+
return op0();
78+
}
79+
80+
exprt &op()
81+
{
82+
return op0();
83+
}
84+
85+
const constant_exprt &size() const
86+
{
87+
return static_cast<const constant_exprt &>(op1());
88+
}
89+
90+
constant_exprt &size()
91+
{
92+
return static_cast<constant_exprt &>(op1());
93+
}
94+
95+
protected:
96+
using binary_exprt::op0;
97+
using binary_exprt::op1;
98+
};
99+
100+
inline const smv_extend_exprt &to_smv_extend_expr(const exprt &expr)
101+
{
102+
PRECONDITION(expr.id() == ID_smv_extend);
103+
smv_extend_exprt::check(expr);
104+
return static_cast<const smv_extend_exprt &>(expr);
105+
}
106+
107+
inline smv_extend_exprt &to_smv_extend_expr(exprt &expr)
108+
{
109+
PRECONDITION(expr.id() == ID_smv_extend);
110+
smv_extend_exprt::check(expr);
111+
return static_cast<smv_extend_exprt &>(expr);
112+
}
113+
114+
class smv_unsigned_cast_exprt : public unary_exprt
115+
{
116+
public:
117+
smv_unsigned_cast_exprt(exprt __op, typet __type)
118+
: unary_exprt{ID_smv_unsigned_cast, std::move(__op), std::move(__type)}
119+
{
120+
}
121+
};
122+
123+
inline const smv_unsigned_cast_exprt &
124+
to_smv_unsigned_cast_expr(const exprt &expr)
125+
{
126+
PRECONDITION(expr.id() == ID_smv_unsigned_cast);
127+
smv_unsigned_cast_exprt::check(expr);
128+
return static_cast<const smv_unsigned_cast_exprt &>(expr);
129+
}
130+
131+
inline smv_unsigned_cast_exprt &to_smv_unsigned_cast_expr(exprt &expr)
132+
{
133+
PRECONDITION(expr.id() == ID_smv_unsigned_cast);
134+
smv_unsigned_cast_exprt::check(expr);
135+
return static_cast<smv_unsigned_cast_exprt &>(expr);
136+
}
137+
138+
class smv_signed_cast_exprt : public unary_exprt
139+
{
140+
public:
141+
smv_signed_cast_exprt(exprt __op, typet __type)
142+
: unary_exprt{ID_smv_signed_cast, std::move(__op), std::move(__type)}
143+
{
144+
}
145+
};
146+
147+
inline const smv_signed_cast_exprt &to_smv_signed_cast_expr(const exprt &expr)
148+
{
149+
PRECONDITION(expr.id() == ID_smv_signed_cast);
150+
smv_signed_cast_exprt::check(expr);
151+
return static_cast<const smv_signed_cast_exprt &>(expr);
152+
}
153+
154+
inline smv_signed_cast_exprt &to_smv_signed_cast_expr(exprt &expr)
155+
{
156+
PRECONDITION(expr.id() == ID_smv_signed_cast);
157+
smv_signed_cast_exprt::check(expr);
158+
return static_cast<smv_signed_cast_exprt &>(expr);
159+
}
160+
161+
#endif // CPROVER_SMV_EXPR_H

src/smvlang/smv_typecheck.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#include <util/typecheck.h>
1818

1919
#include "expr2smv.h"
20+
#include "smv_expr.h"
2021
#include "smv_range.h"
2122

2223
#include <algorithm>
@@ -1202,7 +1203,7 @@ void smv_typecheckt::typecheck_expr_rec(exprt &expr, modet mode)
12021203
else if(expr.id() == ID_smv_unsigned_cast)
12031204
{
12041205
// a reinterpret cast
1205-
auto &op = to_unary_expr(expr).op();
1206+
auto &op = to_smv_unsigned_cast_expr(expr).op();
12061207
typecheck_expr_rec(op, mode);
12071208
if(op.type().id() == ID_signedbv)
12081209
expr.type() = unsignedbv_typet{to_signedbv_type(op.type()).get_width()};
@@ -1215,7 +1216,7 @@ void smv_typecheckt::typecheck_expr_rec(exprt &expr, modet mode)
12151216
else if(expr.id() == ID_smv_signed_cast)
12161217
{
12171218
// a reinterpret cast
1218-
auto &op = to_unary_expr(expr).op();
1219+
auto &op = to_smv_signed_cast_expr(expr).op();
12191220
typecheck_expr_rec(op, mode);
12201221
if(op.type().id() == ID_unsignedbv)
12211222
expr.type() = signedbv_typet{to_unsignedbv_type(op.type()).get_width()};
@@ -1248,21 +1249,21 @@ void smv_typecheckt::lower_node(exprt &expr) const
12481249
{
12491250
if(expr.id() == ID_smv_extend)
12501251
{
1251-
auto &binary = to_binary_expr(expr);
1252-
expr = typecast_exprt{binary.lhs(), expr.type()};
1252+
auto &smv_extend = to_smv_extend_expr(expr);
1253+
expr = typecast_exprt{smv_extend.lhs(), smv_extend.type()};
12531254
}
12541255
else if(expr.id() == ID_smv_resize)
12551256
{
1256-
auto &binary = to_binary_expr(expr);
1257-
expr = typecast_exprt{binary.lhs(), expr.type()};
1257+
auto &smv_resize = to_smv_resize_expr(expr);
1258+
expr = typecast_exprt{smv_resize.lhs(), smv_resize.type()};
12581259
}
12591260
else if(expr.id() == ID_smv_signed_cast)
12601261
{
1261-
expr = typecast_exprt{to_unary_expr(expr).op(), expr.type()};
1262+
expr = typecast_exprt{to_smv_signed_cast_expr(expr).op(), expr.type()};
12621263
}
12631264
else if(expr.id() == ID_smv_unsigned_cast)
12641265
{
1265-
expr = typecast_exprt{to_unary_expr(expr).op(), expr.type()};
1266+
expr = typecast_exprt{to_smv_unsigned_cast_expr(expr).op(), expr.type()};
12661267
}
12671268
}
12681269

0 commit comments

Comments
 (0)