|
17 | 17 |
|
18 | 18 | /*******************************************************************\
|
19 | 19 |
|
| 20 | +Function: map_bv |
| 21 | +
|
| 22 | + Inputs: |
| 23 | +
|
| 24 | + Outputs: |
| 25 | +
|
| 26 | + Purpose: |
| 27 | +
|
| 28 | +\*******************************************************************/ |
| 29 | + |
| 30 | +bvt map_bv(const endianness_mapt &map, const bvt &src) |
| 31 | +{ |
| 32 | + assert(map.size()*8==src.size()); |
| 33 | + |
| 34 | + bvt result; |
| 35 | + result.resize(src.size(), const_literal(false)); |
| 36 | + |
| 37 | + for(unsigned i=0; i<src.size(); i++) |
| 38 | + result[i]=src[map.map_bit(i)]; |
| 39 | + |
| 40 | + return result; |
| 41 | +} |
| 42 | + |
| 43 | +/*******************************************************************\ |
| 44 | +
|
20 | 45 | Function: boolbvt::convert_byte_extract
|
21 | 46 |
|
22 | 47 | Inputs:
|
@@ -59,104 +84,99 @@ void boolbvt::convert_byte_extract(const exprt &expr, bvt &bv)
|
59 | 84 |
|
60 | 85 | // first do op0
|
61 | 86 |
|
62 |
| - const bvt &op0_bv=convert_bv(op0); |
63 |
| - |
| 87 | + endianness_mapt op0_map(op0.type(), little_endian, ns); |
| 88 | + const bvt op0_bv=map_bv(op0_map, convert_bv(op0)); |
| 89 | + |
| 90 | + // do result |
| 91 | + endianness_mapt result_map(expr.type(), little_endian, ns); |
| 92 | + bv.resize(width); |
| 93 | + |
64 | 94 | // see if the byte number is constant
|
| 95 | + unsigned byte_width=8; |
65 | 96 |
|
66 | 97 | mp_integer index;
|
67 | 98 | if(!to_integer(op1, index))
|
68 | 99 | {
|
69 |
| - bv.resize(width); |
70 |
| - |
71 |
| - unsigned byte_width=8; |
72 | 100 | mp_integer offset=index*byte_width;
|
73 | 101 |
|
74 |
| - endianness_mapt op0_map(op0.type(), little_endian, ns); |
75 |
| - endianness_mapt bv_map(expr.type(), little_endian, ns); |
76 |
| - |
77 |
| - assert(width==byte_width*bv_map.size()); |
78 |
| - |
79 | 102 | unsigned offset_i=integer2unsigned(offset);
|
80 | 103 |
|
81 | 104 | for(unsigned i=0; i<width; i++)
|
82 |
| - // out of bounds |
| 105 | + // out of bounds? |
83 | 106 | if(offset<0 || offset_i+i>=op0_bv.size())
|
84 | 107 | bv[i]=prop.new_variable();
|
85 | 108 | else
|
86 |
| - bv[bv_map.map_bit(i)]= |
87 |
| - op0_bv[op0_map.map_bit(offset_i+i)]; |
88 |
| - |
89 |
| - return; |
| 109 | + bv[i]=op0_bv[offset_i+i]; |
90 | 110 | }
|
91 |
| - |
92 |
| - unsigned byte_width=8; |
93 |
| - unsigned bytes=op0_bv.size()/byte_width; |
94 |
| - |
95 |
| - if(prop.has_set_to()) |
| 111 | + else |
96 | 112 | {
|
97 |
| - // free variables |
98 |
| - |
99 |
| - bv.resize(width); |
100 |
| - for(unsigned i=0; i<width; i++) |
101 |
| - bv[i]=prop.new_variable(); |
| 113 | + unsigned bytes=op0_bv.size()/byte_width; |
| 114 | + |
| 115 | + if(prop.has_set_to()) |
| 116 | + { |
| 117 | + // free variables |
| 118 | + for(unsigned i=0; i<width; i++) |
| 119 | + bv[i]=prop.new_variable(); |
102 | 120 |
|
103 |
| - // add implications |
| 121 | + // add implications |
104 | 122 |
|
105 |
| - equal_exprt equality; |
106 |
| - equality.lhs()=op1; // index operand |
| 123 | + equal_exprt equality; |
| 124 | + equality.lhs()=op1; // index operand |
107 | 125 |
|
108 |
| - typet constant_type=op1.type(); // type of index operand |
| 126 | + typet constant_type=op1.type(); // type of index operand |
109 | 127 |
|
110 |
| - bvt equal_bv; |
111 |
| - equal_bv.resize(width); |
| 128 | + bvt equal_bv; |
| 129 | + equal_bv.resize(width); |
112 | 130 |
|
113 |
| - for(unsigned i=0; i<bytes; i++) |
114 |
| - { |
115 |
| - equality.rhs()=from_integer(i, constant_type); |
| 131 | + for(unsigned i=0; i<bytes; i++) |
| 132 | + { |
| 133 | + equality.rhs()=from_integer(i, constant_type); |
116 | 134 |
|
117 |
| - unsigned offset=i*byte_width; |
| 135 | + unsigned offset=i*byte_width; |
118 | 136 |
|
119 |
| - for(unsigned j=0; j<width; j++) |
120 |
| - if(offset+j<op0_bv.size()) |
121 |
| - equal_bv[j]=prop.lequal(bv[j], op0_bv[offset+j]); |
122 |
| - else |
123 |
| - equal_bv[j]=const_literal(true); |
| 137 | + for(unsigned j=0; j<width; j++) |
| 138 | + if(offset+j<op0_bv.size()) |
| 139 | + equal_bv[j]=prop.lequal(bv[j], op0_bv[offset+j]); |
| 140 | + else |
| 141 | + equal_bv[j]=const_literal(true); |
124 | 142 |
|
125 |
| - prop.l_set_to_true( |
126 |
| - prop.limplies(convert(equality), prop.land(equal_bv))); |
| 143 | + prop.l_set_to_true( |
| 144 | + prop.limplies(convert(equality), prop.land(equal_bv))); |
| 145 | + } |
127 | 146 | }
|
128 |
| - } |
129 |
| - else |
130 |
| - { |
131 |
| - bv.resize(width); |
132 |
| - |
133 |
| - equal_exprt equality; |
134 |
| - equality.lhs()=op1; // index operand |
135 |
| - |
136 |
| - typet constant_type(op1.type()); // type of index operand |
137 |
| - |
138 |
| - for(unsigned i=0; i<bytes; i++) |
| 147 | + else |
139 | 148 | {
|
140 |
| - equality.rhs()=from_integer(i, constant_type); |
141 |
| - |
142 |
| - literalt e=convert(equality); |
143 |
| - |
144 |
| - unsigned offset=i*byte_width; |
| 149 | + equal_exprt equality; |
| 150 | + equality.lhs()=op1; // index operand |
145 | 151 |
|
146 |
| - for(unsigned j=0; j<width; j++) |
| 152 | + typet constant_type(op1.type()); // type of index operand |
| 153 | + |
| 154 | + for(unsigned i=0; i<bytes; i++) |
147 | 155 | {
|
148 |
| - literalt l; |
149 |
| - |
150 |
| - if(offset+j<op0_bv.size()) |
151 |
| - l=op0_bv[offset+j]; |
152 |
| - else |
153 |
| - l=const_literal(false); |
154 |
| - |
155 |
| - if(i==0) |
156 |
| - bv[j]=l; |
157 |
| - else |
158 |
| - bv[j]=prop.lselect(e, l, bv[j]); |
159 |
| - } |
160 |
| - } |
| 156 | + equality.rhs()=from_integer(i, constant_type); |
| 157 | + |
| 158 | + literalt e=convert(equality); |
| 159 | + |
| 160 | + unsigned offset=i*byte_width; |
| 161 | + |
| 162 | + for(unsigned j=0; j<width; j++) |
| 163 | + { |
| 164 | + literalt l; |
| 165 | + |
| 166 | + if(offset+j<op0_bv.size()) |
| 167 | + l=op0_bv[offset+j]; |
| 168 | + else |
| 169 | + l=const_literal(false); |
| 170 | + |
| 171 | + if(i==0) |
| 172 | + bv[j]=l; |
| 173 | + else |
| 174 | + bv[j]=prop.lselect(e, l, bv[j]); |
| 175 | + } |
| 176 | + } |
| 177 | + } |
161 | 178 | }
|
| 179 | + |
| 180 | + // shuffle the result |
| 181 | + bv=map_bv(result_map, bv); |
162 | 182 | }
|
0 commit comments