.. _Connect Instances Across the Design Hierarchy:

Connect Instances Across the Design Hierarchy
=============================================


.. _Connect Instances Using New Ports:

Connect Instances Using New Ports
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to connect two module instances using new ports, you must specify the output instance (the signal source) and the input instance (the signal destination). New ports will be created across the design hierarchy as needed, in order to propagate the signal.

.. |design-hierarchy-top| image:: ../../images/icons/act16/design_hierarchy_top.png
   :class: inline

#.  Press the :guilabel:`Select Top` |design-hierarchy-top| button and pick one of the available design tops. 

    .. figure:: ../../images/common/sv-connect-instances-select-top.png


#. Right click on an instance and select :guilabel:`Connect Output` from the context menu. 

   .. figure:: ../../images/common/sv-connect-instances-connect-output.png

   The output instance is presented in the Refactoring Connect View *Output* textbox: 
 
   .. figure:: ../../images/common/sv-connect-instances-connect-output-toolbar-after.png


#. Select another instance, right click and :guilabel:`Connect Input`. 

   .. figure:: ../../images/common/sv-connect-instances-connect-input.png

   The input instance is presented in the Refactoring Connect View *Input* textbox along the previous set output instance: 
 
   .. figure:: ../../images/common/sv-connect-instances-connect-input-toolbar-after.png


#. Press :guilabel:`Compute Changes` button. 

   .. figure:: ../../images/common/sv-connect-instances-dialog.png


#. You can choose :guilabel:`Diagram Preview` to see the design affected by the refactoring operation or :guilabel:`Code Preview` to see the source code changes. 

   .. figure:: ../../images/common/connect-instance-diagram.png

   .. figure:: ../../images/common/sv-connect-instances-code-preview.png


#. Press the :guilabel:`Connect` button in order to perform the changes.

.. note::
    
    You can undo the whole refactoring operation using the application menu :menuselection:`Edit -> Undo`.

.. note::
    
    You can select the output/input instances from editor right click menu :menuselection:`Refactoring -> Connect Output / Connect Input`.


Connect Instances  Using Existing Ports
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



In order to connect two module instances using existing ports, you must specify the output port (the signal source) and the input port (the signal destination). New ports will be created across the design hierarchy as needed, in order to propagate the signal.

#. Press the  **Select Top** button and pick one of the available design tops. 
    
   .. figure:: ../../images/common/sv-connect-instances-connect-existing-select-top.png


#. Press the  **Show/Hide Ports** button to see the ports of the selected instance, if needed.
#. Select an instance using left click and a port using right click **Connect Output Port**. 
    
   .. figure:: ../../images/common/sv-connect-instances-connect-existing-output.png

   The output instance and port are presented in the Refactoring Connect View *Output* textbox: 
    
   .. figure:: ../../images/common/sv-connect-instances-connect-existing-output-toolbar-after.png


#. Select another instance using left click and a port using right click **Connect Input Port**. 

   .. figure:: ../../images/common/sv-connect-instances-connect-existing-input.png

   The input instance and port are presented in the Refactoring Connect View *Input* textbox along the previous set instance and port: 
    
   .. figure:: ../../images/common/sv-connect-instances-connect-existing-input-toolbar-after.png


#.  The rest of the steps are the same as connecting instances using new ports. More details :ref:`Connect Instances Using New Ports`.

.. note::
    The swap between output instance and input instance doesn't work for directional ports (input or output).

Structural Changes Preview Diagram
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Any change to a module or entity definition, like new ports or new signals being added, affects all its instances. Before proceeding to source code changes, you can preview the design structural changes. 

Terminology:

-  **output instance** is the module instance where the connection starts. It outputs the signal that will be connected. **output module** is the module being instantiated as an **output instance**.
-  **input instance** is the module instance where the connection ends. It inputs the signal that will be connected. **input module** is the module being instantiated as an **input instance**.
-  **closest parent instance** is the parent instance through which a signal is routed to connect the ports leading from the **output instance** to the **input instance** across the design hierarchy. No ports will be added to the **closest parent instance**. The **closest parent module** is the module corresponding to the **closest parent instance**.
-  **relevant modules** are the modules that will change by adding new ports and/or new signals. **relevant instances** are instances of **relevant modules**.

Ports are added only to modules that are instantiated on the paths leading from the **output module instance** and the **input module instance** to the **closest parent instance**. Ports are added to the **output module** or the **input module** only if the connection is not using an existing port.

All **relevant instances** are colored in green in the preview diagram. 
All the instances that will not change are colored in blue.

They are hidden by default but the **Show Side Effects** button from the left side of the diagram can be used for showing them.

.. figure:: ../../images/common/connect-instance-diagram.png



.. figure:: ../../images/common/connect-instance-diagram-full.png




Refactoring Connect View
~~~~~~~~~~~~~~~~~~~~~~~~



.. figure:: ../../images/common/sv-connect-instances-connect-toolbar.png




In the design hierarchy you can select the instances that you want to connect.
 
#. You can **Swap** the ports direction.
#. The **output instance path**. The port segment is presented only if you use an existing port.
#. The **input instance path**. The port segment is presented only if you use an existing port.
#. The **output port** / **input port** / **signal name** used for connect operation. 
#. Press **Compute Changes** to start the refactoring operation.
#. Press **Diagram Preview** / **Code Preview** to visualize the structural/source code changes. 
#. Press **Apply changes** to finish the refactoring operation.
#. Press **Close** to hide the **Refactoring Connect View**.
#. (Optional) Press **Reset** to return to initial state of the view.

