@@ -116,7 +116,7 @@ Function: verilog_typecheck_baset::array_size
116
116
117
117
\*******************************************************************/
118
118
119
- mp_integer verilog_typecheck_baset::array_size (const array_typet &type)
119
+ mp_integer verilog_typecheck_baset::array_size (const array_typet &type) const
120
120
{
121
121
auto size_opt = numeric_cast<mp_integer>(type.size ());
122
122
@@ -141,7 +141,7 @@ Function: verilog_typecheck_baset::array_offset
141
141
142
142
\*******************************************************************/
143
143
144
- mp_integer verilog_typecheck_baset::array_offset (const array_typet &type)
144
+ mp_integer verilog_typecheck_baset::array_offset (const array_typet &type) const
145
145
{
146
146
mp_integer offset;
147
147
@@ -157,7 +157,7 @@ mp_integer verilog_typecheck_baset::array_offset(const array_typet &type)
157
157
158
158
/* ******************************************************************\
159
159
160
- Function: verilog_typecheck_baset::get_width
160
+ Function: verilog_typecheck_baset::get_width_opt
161
161
162
162
Inputs:
163
163
@@ -167,7 +167,8 @@ Function: verilog_typecheck_baset::get_width
167
167
168
168
\*******************************************************************/
169
169
170
- mp_integer verilog_typecheck_baset::get_width (const typet &type)
170
+ std::optional<mp_integer>
171
+ verilog_typecheck_baset::get_width_opt (const typet &type) const
171
172
{
172
173
if (type.id ()==ID_bool)
173
174
return 1 ;
@@ -178,16 +179,24 @@ mp_integer verilog_typecheck_baset::get_width(const typet &type)
178
179
179
180
if (type.id ()==ID_array)
180
181
{
181
- mp_integer element_width = get_width (to_array_type (type).element_type ());
182
- return (array_size (to_array_type (type)) * element_width).to_ulong ();
182
+ auto element_width = get_width_opt (to_array_type (type).element_type ());
183
+ if (element_width.has_value ())
184
+ return array_size (to_array_type (type)) * element_width.value ();
185
+ else
186
+ return {};
183
187
}
184
188
185
189
if (type.id () == ID_struct)
186
190
{
187
191
// add them up
188
192
mp_integer sum = 0 ;
189
193
for (auto &component : to_struct_type (type).components ())
190
- sum += get_width (component.type ());
194
+ {
195
+ auto component_width = get_width_opt (component.type ());
196
+ if (!component_width.has_value ())
197
+ return {};
198
+ sum += *component_width;
199
+ }
191
200
return sum;
192
201
}
193
202
@@ -202,8 +211,30 @@ mp_integer verilog_typecheck_baset::get_width(const typet &type)
202
211
else if (type.id () == ID_verilog_time)
203
212
return 64 ;
204
213
205
- throw errort ().with_location (type.source_location ())
206
- << " type `" << type.id () << " ' has unknown width" ;
214
+ return {};
215
+ }
216
+
217
+ /* ******************************************************************\
218
+
219
+ Function: verilog_typecheck_baset::get_width
220
+
221
+ Inputs:
222
+
223
+ Outputs:
224
+
225
+ Purpose:
226
+
227
+ \*******************************************************************/
228
+
229
+ mp_integer verilog_typecheck_baset::get_width (const typet &type) const
230
+ {
231
+ auto width_opt = get_width_opt (type);
232
+
233
+ if (width_opt.has_value ())
234
+ return std::move (width_opt.value ());
235
+ else
236
+ throw errort ().with_location (type.source_location ())
237
+ << " type `" << type.id () << " ' has unknown width" ;
207
238
}
208
239
209
240
/* ******************************************************************\
@@ -218,7 +249,7 @@ Function: verilog_typecheck_baset::index_type
218
249
219
250
\*******************************************************************/
220
251
221
- typet verilog_typecheck_baset::index_type (const array_typet &array_type)
252
+ typet verilog_typecheck_baset::index_type (const array_typet &array_type) const
222
253
{
223
254
return unsignedbv_typet (address_bits (
224
255
(array_size (array_type) + array_offset (array_type)).to_ulong ()));
0 commit comments