Main Content

importhdl

Import Verilog code and generate Simulink model

Description

importhdl imports and parses the specified Verilog® files to generate the corresponding Simulink® model.

example

importhdl(FileNames) imports the specified Verilog files and generates the corresponding Simulink model while removing unconnected components that do not directly contribute to the output.

example

importhdl(FileNames,Name,Value) imports the specified Verilog files and generates the corresponding Simulink model while removing unconnected components that do not directly contribute to the output, with options specified by one or more name-value pair arguments.

Examples

collapse all

This example shows how you can import a file containing Verilog code and generate the corresponding Simulink™ model.

Specify Input Verilog File

Make sure that the input HDL file does not contain any syntax errors, is synthesizable, and uses constructs that are supported by HDL import. This example shows a Verilog code of a comparator.

edit('comparator.v')

Import Verilog File

To import the HDL file and generate the Simulink™ model, pass the file name as a character vector to the importhdl function.

importhdl('comparator.v')
### Parsing <a href="matlab:edit('comparator.v')">comparator.v</a>. 
### Top Module of the source: 'comparator'. 
### Identified ClkName::clk. 
### Identified RstName::rst. 
### Hdl Import parsing done. 
### Creating Target model comparator
### Generating Dot Layout...
### Start Layout...
### Working on hierarchy at ---> 'comparator'.
### Laying out components.
### Working on hierarchy at ---> 'comparator/comparator'.
### Laying out components.
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Setting the model parameters.
### Generated model as C:\Temp\examples\examples\hdlcoder-ex77699673\hdlimport\comparator\comparator.slx.
### HDL Import completed.

HDL import parses the input file and displays messages of the import process in the MATLAB™ Command Window. The import provides a link to the generated Simulink™ model comparator.slx. The generated model uses the same name as the top module in the input Verilog file.

Examine Generated Simulink™ Model

To open the generated Simulink™ model, select the link. The model is saved in the hdlimport/comparator path relative to the current folder. You can simulate the model and observe the simulation results.

addpath('hdlimport/comparator')
open_system('comparator.slx')
sim('comparator.slx')

This example shows how you can import multiple files containing Verilog code and generate the corresponding Simulink™ model.

Specify input Verilog File

Make sure that the input HDL files do not contain any syntax errors, are synthesizable, and use constructs that are supported by HDL import. For example, this code shows three Verilog files that use module instantiation to form a hierarchical design. One module example1.v implements a simple sequential circuit based on an if-else condition. The other module example2.v implements a simple combinational arithmetic expression.

edit('example1.v')
edit('example2.v')

A top module contained in file example.v instantiates the two modules in example1.v and example2.v

edit('example.v')

Import Verilog Files

To import the HDL file and generate the Simulink™ model, pass the file names as a cell array of character vectors to the importhdl function. By default, HDL import identifies the top module and clock bundle when parsing the input file.

importhdl({'example.v','example1.v','example2.v'})
### Parsing <a href="matlab:edit('example.v')">example.v</a>. 
### Parsing <a href="matlab:edit('example1.v')">example1.v</a>. 
### Parsing <a href="matlab:edit('example2.v')">example2.v</a>. 
### Top Module of the source: 'example'. 
### Identified ClkName::clk. 
### Hdl Import parsing done. 
### Creating Target model example
### Generating Dot Layout...
### Start Layout...
### Working on hierarchy at ---> 'example'.
### Laying out components.
### Working on hierarchy at ---> 'example/example'.
### Laying out components.
### Working on hierarchy at ---> 'example/example/example1'.
### Laying out components.
### Applying Dot Layout...
### Drawing block edges...
### Working on hierarchy at ---> 'example/example/example2'.
### Laying out components.
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Setting the model parameters.
### Generated model as C:\Temp\examples\examples\hdlcoder-ex56732899\hdlimport\example\example.slx.
### HDL Import completed.

HDL import parses the input file and displays messages of the import process in the MATLAB™ Command Window. The import provides a link to the generated Simulink™ model example.slx. The generated model uses the same name as the top module that is contained in the input Verilog file example1.v.

Examine Generated Simulink™ Model

To open the generated Simulink™ model, select the link. The model is saved in the hdlimport/example path relative to the current folder. You can simulate the model and observe the simulation results.

addpath('hdlimport/example')
open_system('example.slx')

To avoid a division by zero, you can suppress the warning diagnostic before simulation.

Simulink.suppressDiagnostic({'example/example/example2/Div'}, ...
                                'SimulinkFixedPoint:util:fxpDivisionByZero')
sim('example')

You can see the hierarchy of Subsystems that implement the Verilog code that uses module instantiation.

open_system('example/example/example1')

open_system('example/example/example2')

This example shows how you can import multiple files containing Verilog code and generate the corresponding Simulink™ model. When you import multiple files, if you want to obfuscate the HDL code or if your files contain HDL code for vendor-specific IPs, you can import the HDL code as a BlackBox module using the importhdl function.

Specify input Verilog Files

Make sure that the input HDL files do not contain any syntax errors, are synthesizable, and use constructs that are supported by HDL import. For example, this code shows three Verilog files that use module instantiation to form a hierarchical design. One module sequentialexp.v implements a simple sequential circuit based on an if-else condition. The other module comditionalcomb.v implements a simple combinational arithmetic expression.

edit('conditionalcomb.v')
edit('sequentialexp.v')
edit('intelip.v')

See that the sequentialexp.v module instantiates an Intel® IP that implements a single-precision floating-point adder.

A top module top contained in file blackboxtop.v instantiates the two modules in conditionalcomb.v and sequentialexp.v

edit('blackboxtop.v')

Import Verilog Files

To import the HDL file and generate the Simulink™ model, pass the file names as a cell array of character vectors to the importhdl function. By default, HDL import identifies the top module and clock bundle when parsing the input file.

importhdl({'blackboxtop.v','conditionalcomb.v','sequentialexp.v','intelip.v'}, ...
                            'topModule','top','blackBoxModule','intelip')
### Parsing <a href="matlab:edit('blackboxtop.v')">blackboxtop.v</a>. 
### Parsing <a href="matlab:edit('conditionalcomb.v')">conditionalcomb.v</a>. 
### Parsing <a href="matlab:edit('sequentialexp.v')">sequentialexp.v</a>. 
### Parsing <a href="matlab:edit('intelip.v')">intelip.v</a>. 
### Top Module of the source: 'top'. 
### Identified ClkName::clk. 
### Hdl Import parsing done. 
### Creating Target model top
### Generating Dot Layout...
### Start Layout...
### Working on hierarchy at ---> 'top'.
### Laying out components.
### Working on hierarchy at ---> 'top/top'.
### Laying out components.
### Working on hierarchy at ---> 'top/top/u_comb'.
### Laying out components.
### Applying Dot Layout...
### Drawing block edges...
### Working on hierarchy at ---> 'top/top/u_seq'.
### Laying out components.
### Working on hierarchy at ---> 'top/top/u_seq/u_intelip'.
### Laying out components.
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Setting the model parameters.
### Generated model as C:\Temp\examples\examples\hdlcoder-ex63017378\hdlimport\top\top.slx.
### HDL Import completed.

HDL import parses the input file and displays messages of the import process in the MATLAB™ Command Window. The import provides a link to the generated Simulink™ model top.slx. The generated model uses the same name as the top module that is contained in the input Verilog file conditionalcomb.v.

Examine Generated Simulink™ Model

To open the generated Simulink™ model, select the link. The model is saved in the hdlimport/top path relative to the current folder. You can simulate the model and observe the simulation results.

addpath('hdlimport/top')
open_system('top.slx')
set_param('top','SimulationCommand','update')

To avoid a division by zero, you can suppress the warning diagnostic before simulation.

Simulink.suppressDiagnostic({'top/top/u_seq/Div'}, ...
                                'SimulinkFixedPoint:util:fxpDivisionByZero')
sim('top')

You can see the hierarchy of Subsystems that implement the Verilog code that uses module instantiation.

open_system('top/top/u_comb')

If you open the Subsystem that implements the sequential circuit, you can open the u_intelip Subsystem to see the blackbox implementation.

open_system('top/top/u_seq')

open_system('top/top/u_seq/u_intelip')

This example shows how you can import Verilog code that contains these operators and generate the corresponding Simulink™ model:

  • Arithmetic

  • Logical

  • XOR

  • Bitwise

  • Conditional

  • Relational

  • Concatenation

Specify Input Verilog File

Make sure that the input HDL file does not contain any syntax errors, is synthesizable, and uses constructs for the various operators. For example, this Verilog code shows various operators.

edit('VerilogOperators.v')

Import Verilog File

To import the HDL file and generate the Simulink™ model, pass the file name as a character vector to the importhdl function.

importhdl('VerilogOperators.v')
### Parsing <a href="matlab:edit('VerilogOperators.v')">VerilogOperators.v</a>. 
### Top Module of the source: 'VerilogOperators'. 
### Hdl Import parsing done. 
### Creating Target model VerilogOperators
### Generating Dot Layout...
### Start Layout...
### Working on hierarchy at ---> 'VerilogOperators'.
### Laying out components.
### Working on hierarchy at ---> 'VerilogOperators/VerilogOperators'.
### Laying out components.
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Generated model as C:\Temp\examples\examples\hdlcoder-ex29847655\hdlimport\VerilogOperators\VerilogOperators.slx.
### HDL Import completed.

HDL import parses the input file and displays messages of the import process in the MATLAB™ Command Window. The import provides a link to the generated Simulink™ model VerilogOperators.slx. The generated model uses the same name as the top module in the input Verilog file.

Examine Generated Simulink™ Model

To open the generated Simulink™ model, select the link. The model is saved in the hdlimport/VerilogOperators path relative to the current folder. You can simulate the model and observe the simulation results.

addpath('hdlimport/VerilogOperators')
open_system('VerilogOperators.slx')
sim('VerilogOperators.slx')

This example shows how you can import multiple files containing Verilog code that perform implicit data type conversions and generate the corresponding Simulink™ model. HDL import can perform implicit data type conversion such as in arithmetic operations, data type conversion, bit selection, and bit concatenation.

Specify input Verilog File

Make sure that input HDL files do not contain any syntax errors, are synthesizable, and use constructs that are supported by HDL import. For example, this code shows three Verilog files that use module instantiation to form a hierarchical design. The modules NG1_implicit.v and round_const.v perform implicit data type conversion.

edit('NG1_implicit.v')
edit('round_constant.v')

A top module contained in file example.v instantiates the two modules in NG1_implicit.v and round_constant.v.

edit('implicit_top.v')

Import Verilog Files

To import the HDL file and generate the Simulink™ model, pass the file names as a cell array of character vectors to the importhdl function. By default, HDL import identifies the top module when parsing the input file.

importhdl({'implicit_top.v','NG1_implicit.v','round_constant.v'})
### Parsing <a href="matlab:edit('implicit_top.v')">implicit_top.v</a>. 
### Parsing <a href="matlab:edit('NG1_implicit.v')">NG1_implicit.v</a>. 
### Parsing <a href="matlab:edit('round_constant.v')">round_constant.v</a>. 
### Top Module name: 'top'. 
Warning: Unused input port 'i' in 'rconst' module. 
### Hdl Import parsing done. 
### Creating Target model top
### Generating Dot Layout...
### Start Layout...
### Working on hierarchy at ---> 'top'.
### Laying out components.
### Working on hierarchy at ---> 'top/top'.
### Laying out components.
### Working on hierarchy at ---> 'top/top/NG1'.
### Laying out components.
Configurable Subsystem block 'simulink/Ports & Subsystems/Configurable Subsystem' must be converted to a Variant Subsystem block. Variant subsystems offers enhanced capabilities while maintaining equivalant functionality. Support of Configurable Subsystem will be removed in a future release.
 
### Applying Dot Layout...
### Drawing block edges...
### Working on hierarchy at ---> 'top/top/rconst'.
### Laying out components.
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Generated model file C:\TEMP\Examples\hdlcoder-ex12503110\hdlimport\top\top.slx.
### Importhdl completed.

HDL import parses the input file and displays messages of the import process in the MATLAB™ Command Window. The import provides a link to the generated Simulink™ model implicit_top.slx. The generated model uses the same name as the top module that is contained in the input Verilog file implicit_top.v.

Examine Generated Simulink™ Model

To open the generated Simulink™ model, select the link. The model is saved in the hdlimport/example path relative to the current folder. You can simulate the model and observe the simulation results.

addpath('hdlimport/top');
open_system('top.slx')

In the rconst Subsystem, one of the input ports is unconnected. It is good practice to avoid unterminated outputs by adding a Terminator block.

addterms('top');
sim('top');

You can see the hierarchy of Subsystems that implement the Verilog code that uses module instantiation.

open_system('top/top/NG1')

open_system('top/top/rconst')

This example shows how you can import a file containing Verilog code and infer RAM blocks in the Simulink™ model that gets generated. You can import Verilog code that infers any of the various RAMs in the HDL RAMs library including the hdl.RAM System-Object based blocks and Block RAMs.

Specify Input Verilog File

Make sure that the input HDL file does not contain any syntax errors, is synthesizable, and uses constructs that are supported by HDL import. This example shows the Verilog code.

edit('simple_dual_port_ram.v')

Import Verilog File

To import the HDL file and generate the Simulink™ model, pass the file name as a character vector to the importhdl function.

importhdl('simple_dual_port_ram.v')
### Parsing <a href="matlab:edit('simple_dual_port_ram.v')">simple_dual_port_ram.v</a>. 
### Top Module name: 'SimpleDualPortRAM'. 
### Identified ClkName::clk. 
### Hdl Import parsing done. 
### Creating Target model SimpleDualPortRAM
### Generating Dot Layout...
### Start Layout...
### Working on hierarchy at ---> 'SimpleDualPortRAM'.
### Laying out components.
### Working on hierarchy at ---> 'SimpleDualPortRAM/SimpleDualPortRAM'.
### Laying out components.
Configurable Subsystem block 'simulink/Ports & Subsystems/Configurable Subsystem' must be converted to a Variant Subsystem block. Variant subsystems offers enhanced capabilities while maintaining equivalant functionality. Support of Configurable Subsystem will be removed in a future release.
 
### Applying Dot Layout...
### Drawing block edges...
### Applying Dot Layout...
### Drawing block edges...
### Setting model parameters.
### Generated model file C:\TEMP\Examples\hdlcoder-ex67646187\hdlimport\SimpleDualPortRAM\SimpleDualPortRAM.slx.
### Importhdl completed.

HDL import parses the input file and displays messages of the import process in the MATLAB™ Command Window. The import provides a link to the generated Simulink™ model SimpleDualPortRAM.slx. The generated model uses the same name as the top module in the input Verilog file.

Examine Generated Simulink™ Model

To open the generated Simulink™ model, select the link. The model is saved in the hdlimport/SimpleDualPortRAM path relative to the current folder. You can simulate the model and observe the simulation results.

addpath('hdlimport/SimpleDualPortRAM');
open_system('SimpleDualPortRAM.slx');
sim('SimpleDualPortRAM.slx');

If you navigate the model, you see the Simple Dual Port RAM block.

open_system('SimpleDualPortRAM/SimpleDualPortRAM')

Input Arguments

collapse all

Names of HDL files to import for generation of the Simulink model. By default, importhdl imports Verilog files. To import:

  • One HDL file, specify the file name as a character vector.

  • Multiple HDL files, specify the file names as a cell array of character vectors.

  • All HDL files in a folder, specify the folder name as a character vector.

  • Multiple folders and combinations of files and folders, specified as cell array of character vectors. You can also use subfolders that contain recursive folders.

Example: importhdl('example') imports the specified Verilog file. If example is a subfolder in the current working folder, HDL import parses the subfolder example and module instantiations inside the subfolder, and then generates a Simulink model for all .v files. If importhdl cannot find a subfolder that has the name example, it searches the MATLAB® path for HDL files that have the name example.

Example: importhdl({'top.v','subsystem1.v','subsystem2.v'}) imports the specified Verilog files and generates the corresponding Simulink model.

Example: importhdl(pwd) imports all Verilog files in the current folder and generates the corresponding Simulink model.

Example: importhdl('root/example/hdlsrc') imports all Verilog files on the specified path and generates the corresponding Simulink model. You can specify a relative or absolute path.

Example: importhdl('subfolder') imports all Verilog files under specified subfolder and generates the corresponding Simulink model. By default, importhdl parses subfolders that contain recursive folders.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: importhdl('root/example/hdlsrc') imports all Verilog files in the specified path and generates the corresponding Simulink model. You can specify a relative or absolute path.

Language of input source file that contains the HDL code, specified as a character vector. If you specified a VHDL® file, HDL import generates an error.

Example: importhdl('fifo.v','Language','Verilog') imports the Verilog file fifo.v and generates the corresponding Simulink model fifo.slx.

Top-level module name in the HDL code, specified as a character vector. This name becomes the name of the top-level Subsystem from which HDL import constructs the hierarchy of subsystems in the generated Simulink model. If the input HDL files contain more than one top module, specify the top-level module to use for generating the Simulink model by using the TopModule property.

Example: importhdl('full_adder.v','TopModule','two_half_adders') imports the Verilog file full_adder.v and generates the corresponding Simulink model full_adder.slx with two_half_adders as the top-level Subsystem.

Names of clock, reset, and clock enable signals for sequential circuits, specified as a cell array of character vector. Default names for the clock bundle signals are:

  • Clock signal - clk, clock

  • Reset signal - rst, reset

  • Clock Enable signal - clk_enb, clk_en, clk_enable, enb, enable

If you do not specify the clock bundle information, HDL import uses the default values. When parsing the input file, if HDL import identifies a clock name that is different from the clock name specified by the ClockBundle, the import generates an error.

Example: importhdl('example.v','clockBundle',{'clk','rst','clk_enb'}) imports the Verilog file example.v with the specified clock bundle information.

Name or names of modules in the Verilog input files to be imported as BlackBox subsystems in the generated Simulink model. The Subsystem block that is imported as BlackBox uses the input and output ports that you provide to the module definition. Inside the Subsystem, the input ports are connected to Terminator blocks, Constant blocks with a value of zero are connected to the output ports. Use this capability to import vendor-specific IPs as BlackBox subsystems in your model.

Example: importhdl({'example.v,'example1.v','example2.v','xilinxIP.v},'topModule','top','blackBoxModule','xilinxIP') imports the specified Verilog files with xilinxIP as a BlackBox module. The corresponding Subsystem in the Simulink model has the input ports connected to Terminator blocks and Constant blocks with constant value of zero connected to the output ports.

Automatically arrange blocks in the Simulink model generated by running importhdl. By default, autoPlace is on. importhdl then uses Simulink.BlockDiagram.arrangeSystem to improve the model layout by realigning, resizing, and moving blocks, and straightening signal lines.

Example: importhdl('example.v','autoPlace','on') imports the Verilog file example.v and generates the Simulink model with an enhanced model layout.

Limitations

The importhdl function is not supported on Mac platforms.

Version History

Introduced in R2018b