@@ -223,28 +223,15 @@ Function: verilog_typecheckt::typecheck_builtin_port_connections
223223void verilog_typecheckt::typecheck_builtin_port_connections (
224224 verilog_inst_baset::instancet &inst)
225225{
226- exprt &range_expr = static_cast <exprt &>(inst.add (ID_range));
227-
228- ranget range;
229-
230- if (range_expr.is_nil () || range_expr.id () == irep_idt{})
231- range = ranget{0 , 0 };
232- else
233- range = convert_range (range_expr);
234-
235- if (range.lsb > range.msb )
236- std::swap (range.lsb , range.msb );
237- mp_integer width = range.length ();
238-
239- inst.remove (ID_range);
240-
241- typet &type=inst.type ();
242- if (width==1 )
243- type.id (ID_bool);
226+ if (!inst.has_instance_array ())
227+ inst.type () = bool_typet{};
244228 else
245229 {
246- type.id (ID_unsignedbv);
247- type.set (ID_width, integer2string (width));
230+ // We'll turn a one-dimensional array into a bit-vector
231+ auto &array_type = to_array_type (inst.instance_array ());
232+ auto width =
233+ numeric_cast_v<mp_integer>(to_constant_expr (array_type.size ()));
234+ inst.type () = unsignedbv_typet{width};
248235 }
249236
250237 for (auto &connection : inst.connections ())
@@ -264,7 +251,7 @@ void verilog_typecheckt::typecheck_builtin_port_connections(
264251 }
265252
266253 // like an assignment
267- assignment_conversion (connection, type);
254+ assignment_conversion (connection, inst. type () );
268255 }
269256}
270257
@@ -560,10 +547,16 @@ Function: verilog_typecheckt::convert_inst_builtin
560547void verilog_typecheckt::convert_inst_builtin (
561548 verilog_inst_builtint &inst)
562549{
563- const irep_idt &inst_module=inst.get_module ();
564-
550+ const irep_idt &inst_module = inst.get_module ();
565551 for (auto &instance : inst.instances ())
566552 {
553+ // typecheck the instance array type, if any
554+ if (instance.has_instance_array ())
555+ {
556+ auto &instance_array = instance.instance_array ();
557+ instance_array = elaborate_type (instance_array);
558+ }
559+
567560 typecheck_builtin_port_connections (instance);
568561
569562 // check built-in ones
0 commit comments