@@ -1349,14 +1349,13 @@ Function: verilog_synthesist::instantiate_port
13491349\*******************************************************************/
13501350
13511351void verilog_synthesist::instantiate_port (
1352- bool is_output,
1353- const symbol_exprt &port,
1352+ const module_typet::portt &port,
13541353 const exprt &value,
13551354 const replace_mapt &replace_map,
13561355 const source_locationt &source_location,
13571356 transt &trans)
13581357{
1359- irep_idt port_identifier = port.get_identifier ();
1358+ irep_idt port_identifier = port.identifier ();
13601359
13611360 replace_mapt::const_iterator it = replace_map.find (port_identifier);
13621361
@@ -1372,7 +1371,7 @@ void verilog_synthesist::instantiate_port(
13721371 // Note that the types need not match.
13731372 exprt lhs, rhs;
13741373
1375- if (is_output )
1374+ if (port. output () )
13761375 {
13771376 lhs = value;
13781377 rhs = typecast_exprt::conditional_cast (it->second , value.type ());
@@ -1417,31 +1416,29 @@ void verilog_synthesist::instantiate_ports(
14171416 if (inst.connections ().empty ())
14181417 return ;
14191418
1419+ auto &module_type = to_module_type (symbol.type );
1420+
14201421 // named port connection?
14211422
14221423 if (inst.named_port_connections ())
14231424 {
1424- const irept::subt &ports = symbol.type .find (ID_ports).get_sub ();
1425-
1426- std::set<irep_idt> output_identifiers;
1427- for (auto &port : ports)
1428- if (port.get_bool (ID_output))
1429- output_identifiers.insert (
1430- to_symbol_expr ((const exprt &)(port)).get_identifier ());
1425+ const auto &ports = module_type.ports ();
1426+ auto port_map = module_type.port_map ();
14311427
14321428 // no requirement that all ports are connected
14331429 for (const auto &connection : inst.connections ())
14341430 {
14351431 auto &named_connection = to_verilog_named_port_connection (connection);
1436- const auto &port = to_symbol_expr (named_connection.port ());
1432+ auto port_it =
1433+ port_map.find (to_symbol_expr (named_connection.port ()).get_identifier ());
1434+ CHECK_RETURN (port_it != port_map.end ());
1435+ auto &port = port_it->second ;
14371436 const exprt &value = named_connection.value ();
14381437
14391438 if (value.is_not_nil ())
14401439 {
1441- bool is_output = output_identifiers.find (port.get_identifier ()) !=
1442- output_identifiers.end ();
14431440 instantiate_port (
1444- is_output, port, value, replace_map, inst.source_location (), trans);
1441+ port, value, replace_map, inst.source_location (), trans);
14451442 }
14461443 }
14471444
@@ -1456,17 +1453,15 @@ void verilog_synthesist::instantiate_ports(
14561453
14571454 // unconnected inputs may be given a default value
14581455 for (auto &port : ports)
1459- if (port.get_bool (ID_input ))
1456+ if (port.input ( ))
14601457 {
1461- auto &port_symbol_expr = to_symbol_expr ((const exprt &)(port));
1462- auto identifier = port_symbol_expr.get_identifier ();
1458+ auto identifier = port.identifier ();
14631459 if (connected_ports.find (identifier) == connected_ports.end ())
14641460 {
1465- auto &port_symbol = ns.lookup (port_symbol_expr );
1461+ auto &port_symbol = ns.lookup (identifier );
14661462 if (port_symbol.value .is_not_nil ())
14671463 instantiate_port (
1468- false ,
1469- port_symbol_expr,
1464+ port,
14701465 port_symbol.value ,
14711466 replace_map,
14721467 inst.source_location (),
@@ -1476,7 +1471,7 @@ void verilog_synthesist::instantiate_ports(
14761471 }
14771472 else // just a list without names
14781473 {
1479- const irept::subt &ports = symbol. type . find (ID_ports). get_sub ();
1474+ const auto &ports = module_type. ports ();
14801475
14811476 if (inst.connections ().size () != ports.size ())
14821477 {
@@ -1485,24 +1480,15 @@ void verilog_synthesist::instantiate_ports(
14851480 << inst.connections ().size ();
14861481 }
14871482
1488- irept::subt::const_iterator p_it=
1489- ports.begin ();
1483+ auto p_it = ports.begin ();
14901484
14911485 for (const auto &connection : inst.connections ())
14921486 {
14931487 DATA_INVARIANT (connection.is_not_nil (), " all ports must be connected" );
14941488
1495- auto &port = to_symbol_expr ((const exprt &)(*p_it));
1496-
1497- bool is_output = port.get_bool (ID_output);
1498-
14991489 instantiate_port (
1500- is_output,
1501- port,
1502- connection,
1503- replace_map,
1504- inst.source_location (),
1505- trans);
1490+ *p_it, connection, replace_map, inst.source_location (), trans);
1491+
15061492 p_it++;
15071493 }
15081494 }
0 commit comments