Currently the code assumes that $TBUF output (Y) is connected to just one point: a top-level port.
The problem is that when we use inout pins Y is connected to the top-level port AND internal logic using the top-level port as input.
In this case the number of connections for the net that connects the $TBUF to the outside world is more than 2 and connection_other_port returns NULL. In this case arachne aborts saying the $TBUF must be connected to an output or inout port.
This patch allows more than 2 connections and selects the proper connection to use.
I verified it in a design with 17 $TBUF used in 2 different ways.
The patch passed the regression tests.
It look bigger than what it really is because I added some comments about what the code is doing.
Currently the code assumes that $TBUF output (Y) is connected to just one point: a top-level port. The problem is that when we use inout pins Y is connected to the top-level port AND internal logic using the top-level port as input. In this case the number of connections for the net that connects the $TBUF to the outside world is more than 2 and connection_other_port returns NULL. In this case arachne aborts saying the $TBUF must be connected to an output or inout port. This patch allows more than 2 connections and selects the proper connection to use. I verified it in a design with 17 $TBUF used in 2 different ways. The patch passed the regression tests. It look bigger than what it really is because I added some comments about what the code is doing.