Main Content

Generate Code with Annotations or Comments

The following sections describe how to use the HDL Coder™ software to add text annotations to generated code, in the form of model annotations, text comments or requirements comments.

Simulink Annotations

You can enter text directly on the block diagram as Simulink® annotations. HDL Coder renders text from Simulink annotations as plain text comments in generated code. The comments are generated at the same level in the model hierarchy as the subsystem(s) that contain the annotations, as if they were Simulink blocks.

For Constant blocks, to reflect the annotations as comments in the HDL code, clear the Minimize intermediate signals check box and set Traceability style to Comment Based.

See Describe Models Using Notes and Annotations for general information on annotations.

Signal Descriptions

You can provide a description for the signals in your Simulink model. The generated HDL code displays these descriptions as comments above the signal declaration statements. To specify a description for the signal, right-click the signal, and select Properties to open the Signal Properties dialog box. Then, select the Documentation tab, and in the Description section, enter a description for the signal. For the signal description, use ASCII characters because non-ASCII characters in the generated code can potentially interfere with downstream synthesis and lint tools. In some cases, due to certain optimizations that act on the signals, the generated code may not translate all signal descriptions to HDL comments or may create replicas of HDL comments for certain signal descriptions.

Text Comments

You can enter text comments at any level of the model by placing a DocBlock at the desired level and entering text comments. HDL Coder renders text from the DocBlock in generated code as plain text comments. The comments are generated at the same level in the model hierarchy as the subsystem that contains the DocBlock.

Set the Document type parameter of the DocBlock to Text. HDL Coder does not support the HTML or RTF options.

See DocBlock for general information on the DocBlock.

Requirements Comments and Hyperlinks

You can assign requirement comments to blocks.

If your model includes requirements comments, you can choose to render the comments in one of the following formats:

  • Text comments in generated code: To include requirements as text comments in code, use the defaults for Include requirements in block comments (on) and Generate traceability report (off) in the Configuration Parameters dialog box.

    If you generate code from the command line, set the Traceability and RequirementComments properties. This code shows the text requirements comments generated for a Gain block from the mcombo model:

    open_system('mcombo')
    makehdl(gcb,'Traceability','off','RequirementComments','on');
    
        BEGIN
          In1_signed <= signed(In1);
    
          --
          -- Block requirements for <S10>/Gain
          -- 1. Gain Requirements Sect 1
          -- 2. Gain Requirements Sect 2
          Gain_gainparam <= to_signed(16384, 16);
    
          Gain_out1 <= resize(In1_signed(15 DOWNTO 0) & '0'
    
          Out1 <= std_logic_vector(Gain_out1);
    
        END rtl;
    
  • Hyperlinked comments: To include requirements comments as hyperlinked comments in an HTML code generation report, select both Generate traceability report and Include requirements in block comments in the Configuration Parameters dialog box.

    If you generate code from the command line, set the Traceability and RequirementComments properties:

    makehdl(gcb,'Traceability','on','RequirementComments','on');
    

    The comments include links back to a requirements document associated with the block and to the block within the original model. For example, the following figure shows two requirements links assigned to a Gain block. The links point to sections of a text requirements file.

The following code shows hyperlinked requirements comments generated for the Gain block.

    BEGIN
      In1_signed <= signed(In1);

      -- <S10>/Gain
      --
      --
      -- Block requirements for <S10>/Gain
      -- 1. Gain Requirements Sect 1
      -- 2. Gain Requirements Sect 2
      Gain_gainparam <= to_signed(16384, 16);

      Gain_out1 <= resize(In1_signed(15 DOWNTO 0) & '0'

      Out1 <= std_logic_vector(Gain_out1);

    END rtl;