Refactoring

Rename Refactoring

To rename an entity (type, method, macro, etc.) in the source code along with all its references, place the cursor on the desired element and use the Rename Symbol command.

Provide the new name of the entity and click Enter to perform the refactoring operation or Shift+Enter to preview and select the changes that should be performed in the source code.

../../_images/rename_refactoring.gif

Tip

Matches hidden inside a macro call (matches found inside a macro call expansion, but not among the macro call parameters) cannot be automatically renamed.

Instead, DVT will insert a // FIXME comment above the macro call to indicate that it should be refactored by hand.

Rename in File

To rename a variable, signal, method, etc. within the current file, select the name of the element and use the Replace command. Write the new name and choose to replace occurrence by occurrence or all of them at once.

This is a lightweight Rename Refactoring which you should use in contexts where the renamed element is local to the file: local parameters, method argument names, local variables, signals of a module, etc.

Extract to Variable

To extract an expression inside a function or task to a local variable, select the expression, run the Refactor... command and select Extract to local variable.

Provide a name for the new variable, which is declared and initialized with the extracted expression in the correct scope.

../../_images/extract_to_variable.gif

Bind Method Call Arguments by Name

To convert the argument bindings of a method call from positional to named, place the cursor on a method call, run the Refactor... command and select Bind Method Call Arguments by Name.

../../_images/bind_method_call_by_name.gif

Bind Method Call Arguments by Position

To convert the argument bindings of a method call from named to positional, place the cursor on a method call, run the Refactor... command and select Bind Method Call Arguments by Position.

../../_images/bind_method_call_by_position.gif

Connect Instance Ports by Name

To convert the port connections of an instance from positional to named, place the cursor on an instance, run the Refactor... command and select Connect instance ports by name.

../../_images/connect_instance_ports_by_name.gif

Connect Instance Ports by Position

To convert the port connections of an instance from named to positional, place the cursor on an instance, run the Refactor... command and select Connect instance ports by position.

../../_images/connect_instance_ports_by_position.gif

Expand .* Port Connections

To easily expand .* wildcard named port connections to explicit named port connections, place the cursor either on a module or interface instance declaration, run the Refactor... command and select Expand .* port connections.

../../_images/expand_dot_star.gif

Extract to Method

To move a code fragment to a separate new method, select a block of actions, run the Refactor... command and select Extract to task or Extract to function.

Provide a name for the new method, which is created containing the selected code fragment and the selection is replaced with a method call.

../../_images/extract_to_method.gif

Note

Any local variables declared prior to the code fragment you extracted become arguments of the newly created method. Each argument direction is computed accordingly:

  1. input for arguments that are only read

  2. output for arguments that are only written

  3. inout for arguments that are both read and written in the selected block of actions

Note

By default, if and loop conditions are evaluated to the logic data type, according to the IEEE 1800-2023 Standard for SystemVerilog. You can enforce the data type to bit using the DVT.systemVerilog.refactoring.enforceConditionDataTypeToBit preference accessible using Preferences: Open Settings (UI) command.

This preference applies only when you select the whole condition.

Extract to Module

To automatically extract and encapsulate a fragment of a module into a new instance, select the region (must be contiguous, containing only instances, always blocks and assignments) in the editor, run the Refactor... command and select Extract to module.

Provide a name for the new module and file where the selected piece of code will be moved. The initial selection is replaced with an instance of the new module and the ports of the new module are automatically computed and connected in the instantiation.

../../_images/extract_to_module.gif

Note

  1. The new file is `included on the line above the declaration of the initial module.

  2. Signals which are not referenced anywhere outside the selection will be marked with a // FIXME after the extraction.

  3. Currently busses are propagated through a single port even if accessed through bit selects; in such a case, a // FIXME comment can help you easily identify the unique bit selects that you might consider propagating through distinct ports.

Move Selection to New File

To move a code fragment to a separate new file, select a block of code, run the Refactor... command and select Move selection to new file....

Provide a name for the new file, an `include to this file replacing the initial selection.

../../_images/move_selection_to_new_file.gif

Join Extern and Implementation

To merge the extern prototype of a method or constraint with its out-of-block implementation, place the cursor either on the prototype or on the implementation, run the Refactor... command and select Join extern … prototype and implementation.

../../_images/join_extern_and_implementation.gif

Split into Extern and Implementation

To move method or constraint implementations outside the body of the class declaration, place the cursor on the declaration, run the Refactor... command and select Split … into extern prototype and implementation.

The declaration is replaced with the extern prototype, and the implementation is inserted after endclass.

../../_images/split_extern_and_implementation.gif

Add Port to Module from Selected Field

To add a selected field as a port easy and fast, place the cursor on a field, run the Refactor... command and select Add port .

You can optionally change the newly generated port name, direction type or width.

Add New Port to Module

To add a new port to a module, place the cursor on the module name, run the Refactor... command and select Add port.

After tuning the name, direction, type, and width of the new port, an empty port connection is added to all the instances of the selected module along with a // FIXME comment.

../../_images/add_port.gif

Add New Parameter to Module

To add a new parameter to a module, place the editor cursor on the module name, run the Refactor... command and select Add parameter.

After tuning the name, type, width, and the value of the new parameter, an empty parameter override is added to all the instances of the selected module along with a // FIXME comment.

../../_images/add_parameter.gif

Add New Argument to Method

To add a new argument to a method, place the editor cursor on the method name, run the Refactor... command and select Add argument.

After tuning the argument type, the argument name and the value that will be used in method calls, a new argument will be inserted.

Note

In case of duplicate arguments a pop up will appear and the operation will not be performed.

../../_images/add_argument.gif

Remove Argument from Method

To remove an argument from a method, place the editor cursor on the argument name, run the Refactor... command and select Remove argument. The argument will be removed from both method declarations and method calls.

../../_images/remove_argument.gif

Change Position of Method Argument

To change the position of a method argument, place the editor cursor on the argument name, then run the Refactor... command and select Change position of argument. In the newly opened quick pick, you can modify the position by using ARROW UP and ARROW DOWN or by selecting the position you want to place the argument at. To confirm the new position, press Enter or the Done button from the quick pick header.

../../_images/reorder_argument.gif

Expand Macro

To easily expand macro calls, place the cursor on the macro name, run the Refactor... command and select Expand macro.

../../_images/expand_macro.gif

Collapse Macro

To easily collapse macro expansions, place the cursor on the start pragma of a macro expansion, run the Refactor... command and select Collapse macro.

../../_images/collapse_macro.gif