DVT IDE for VS Code SystemVerilog User Guide
Rev. 24.1.8, 24 April 2024

Chapter 16. 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.

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.


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".


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".


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".


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".


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".


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.

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


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.

Implementation notes:

  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.


Join Extern and Implementation

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


Split to Extern and Implementation

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

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


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.


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.


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.


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.


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 the up and down arrows 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.