@@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com
1414#include < util/std_types.h>
1515
1616#include " expr2verilog.h"
17+ #include " verilog_bits.h"
1718#include " verilog_types.h"
1819
1920/* ******************************************************************\
@@ -159,74 +160,6 @@ mp_integer verilog_typecheck_baset::array_offset(const array_typet &type)
159160
160161/* ******************************************************************\
161162
162- Function: verilog_typecheck_baset::get_width_opt
163-
164- Inputs:
165-
166- Outputs:
167-
168- Purpose:
169-
170- \*******************************************************************/
171-
172- std::optional<mp_integer>
173- verilog_typecheck_baset::get_width_opt (const typet &type)
174- {
175- if (type.id ()==ID_bool)
176- return 1 ;
177-
178- if (type.id ()==ID_unsignedbv || type.id ()==ID_signedbv ||
179- type.id ()==ID_verilog_signedbv || type.id ()==ID_verilog_unsignedbv)
180- return type.get_int (ID_width);
181-
182- if (type.id ()==ID_array)
183- {
184- auto element_width = get_width_opt (to_array_type (type).element_type ());
185- if (element_width.has_value ())
186- return array_size (to_array_type (type)) * element_width.value ();
187- else
188- return {};
189- }
190-
191- if (type.id () == ID_struct)
192- {
193- // add them up
194- mp_integer sum = 0 ;
195- for (auto &component : to_struct_type (type).components ())
196- {
197- auto component_width = get_width_opt (component.type ());
198- if (!component_width.has_value ())
199- return {};
200- sum += *component_width;
201- }
202- return sum;
203- }
204-
205- if (type.id () == ID_union)
206- {
207- // find the biggest
208- mp_integer max = 0 ;
209- for (auto &component : to_verilog_union_type (type).components ())
210- max = std::max (max, get_width (component.type ()));
211- return max;
212- }
213-
214- if (type.id () == ID_verilog_shortint)
215- return 16 ;
216- else if (type.id () == ID_verilog_int)
217- return 32 ;
218- else if (type.id () == ID_verilog_longint)
219- return 64 ;
220- else if (type.id () == ID_verilog_integer)
221- return 32 ;
222- else if (type.id () == ID_verilog_time)
223- return 64 ;
224-
225- return {};
226- }
227-
228- /* ******************************************************************\
229-
230163Function: verilog_typecheck_baset::get_width
231164
232165 Inputs:
@@ -239,13 +172,13 @@ Function: verilog_typecheck_baset::get_width
239172
240173mp_integer verilog_typecheck_baset::get_width (const typet &type)
241174{
242- auto width_opt = get_width_opt (type);
175+ auto bits_opt = verilog_bits_opt (type);
243176
244- if (width_opt .has_value ())
245- return std::move (width_opt .value ());
177+ if (bits_opt .has_value ())
178+ return std::move (bits_opt .value ());
246179 else
247180 throw errort ().with_location (type.source_location ())
248- << " type `" << type.id () << " ' has unknown width " ;
181+ << " type `" << type.id () << " ' has unknown number of bits " ;
249182}
250183
251184/* ******************************************************************\
0 commit comments