|
12 | 12 | #include <algorithm>
|
13 | 13 |
|
14 | 14 | #include <util/arith_tools.h>
|
| 15 | +#include <util/exception_utils.h> |
15 | 16 | #include <util/std_expr.h>
|
16 | 17 | #include <util/std_types.h>
|
17 | 18 |
|
18 | 19 | literalt boolbvt::convert_extractbit(const extractbit_exprt &expr)
|
19 | 20 | {
|
20 |
| - const exprt::operandst &operands=expr.operands(); |
21 |
| - |
22 |
| - if(operands.size()!=2) |
23 |
| - throw "extractbit takes two operands"; |
24 |
| - |
25 |
| - const bvt &bv0=convert_bv(operands[0]); |
| 21 | + const bvt &src_bv = convert_bv(expr.src()); |
26 | 22 |
|
27 | 23 | // constant?
|
28 |
| - if(operands[1].is_constant()) |
| 24 | + if(expr.index().is_constant()) |
29 | 25 | {
|
30 |
| - mp_integer o; |
31 |
| - |
32 |
| - if(to_integer(operands[1], o)) |
33 |
| - throw "extractbit failed to convert constant index"; |
| 26 | + mp_integer index_as_integer = numeric_cast_v<mp_integer>(expr.index()); |
34 | 27 |
|
35 |
| - if(o<0 || o>=bv0.size()) |
| 28 | + if(index_as_integer < 0 || index_as_integer >= src_bv.size()) |
36 | 29 | return prop.new_variable(); // out of range!
|
37 | 30 | else
|
38 |
| - return bv0[integer2size_t(o)]; |
| 31 | + return src_bv[integer2size_t(index_as_integer)]; |
39 | 32 | }
|
40 | 33 |
|
41 |
| - if(operands[0].type().id()==ID_verilog_signedbv || |
42 |
| - operands[0].type().id()==ID_verilog_unsignedbv) |
| 34 | + if( |
| 35 | + expr.src().type().id() == ID_verilog_signedbv || |
| 36 | + expr.src().type().id() == ID_verilog_unsignedbv) |
43 | 37 | {
|
44 |
| - // TODO |
45 |
| - assert(false); |
| 38 | + throw unsupported_operation_exceptiont( |
| 39 | + "extractbit expression not implemented for verilog integers in " |
| 40 | + "flattening solver"); |
46 | 41 | }
|
47 | 42 | else
|
48 | 43 | {
|
49 |
| - std::size_t width_op0=boolbv_width(operands[0].type()); |
50 |
| - std::size_t width_op1=boolbv_width(operands[1].type()); |
| 44 | + std::size_t src_bv_width = boolbv_width(expr.src().type()); |
| 45 | + std::size_t index_bv_width = boolbv_width(expr.index().type()); |
51 | 46 |
|
52 |
| - if(width_op0==0 || width_op1==0) |
| 47 | + if(src_bv_width == 0 || index_bv_width == 0) |
53 | 48 | return SUB::convert_rest(expr);
|
54 | 49 |
|
55 |
| - std::size_t index_width = std::max(address_bits(width_op0), width_op1); |
| 50 | + std::size_t index_width = |
| 51 | + std::max(address_bits(src_bv_width), index_bv_width); |
56 | 52 | unsignedbv_typet index_type(index_width);
|
57 | 53 |
|
58 | 54 | equal_exprt equality;
|
59 |
| - equality.lhs()=operands[1]; // index operand |
| 55 | + equality.lhs() = expr.index(); |
60 | 56 |
|
61 | 57 | if(index_type!=equality.lhs().type())
|
62 | 58 | equality.lhs().make_typecast(index_type);
|
63 | 59 |
|
64 | 60 | if(prop.has_set_to())
|
65 | 61 | {
|
66 | 62 | // free variable
|
67 |
| - literalt l=prop.new_variable(); |
| 63 | + literalt literal = prop.new_variable(); |
68 | 64 |
|
69 | 65 | // add implications
|
70 |
| - for(std::size_t i=0; i<bv0.size(); i++) |
| 66 | + for(std::size_t i = 0; i < src_bv.size(); i++) |
71 | 67 | {
|
72 | 68 | equality.rhs()=from_integer(i, index_type);
|
73 |
| - literalt equal=prop.lequal(l, bv0[i]); |
| 69 | + literalt equal = prop.lequal(literal, src_bv[i]); |
74 | 70 | prop.l_set_to_true(prop.limplies(convert(equality), equal));
|
75 | 71 | }
|
76 | 72 |
|
77 |
| - return l; |
| 73 | + return literal; |
78 | 74 | }
|
79 | 75 | else
|
80 | 76 | {
|
81 |
| - literalt l=prop.new_variable(); |
| 77 | + literalt literal = prop.new_variable(); |
82 | 78 |
|
83 |
| - for(std::size_t i=0; i<bv0.size(); i++) |
| 79 | + for(std::size_t i = 0; i < src_bv.size(); i++) |
84 | 80 | {
|
85 | 81 | equality.rhs()=from_integer(i, index_type);
|
86 |
| - l=prop.lselect(convert(equality), bv0[i], l); |
| 82 | + literal = prop.lselect(convert(equality), src_bv[i], literal); |
87 | 83 | }
|
88 | 84 |
|
89 |
| - return l; |
| 85 | + return literal; |
90 | 86 | }
|
91 | 87 | }
|
92 | 88 |
|
|
0 commit comments