Main Content

Code Generation Reports

MATLAB® Coder™ produces a code generation report that helps you to:

  • Debug code generation issues and verify that your MATLAB code is suitable for code generation.

  • View generated C/C++ code.

  • Trace between MATLAB source code and generated C/C++ code.

  • See how the code generator determines and propagates type information for variables and expressions in your MATLAB code.

  • Identify potential issues in the generated code.

  • Access additional reports available with Embedded Coder®.

Report Generation

When you enable report generation or when an error occurs, the code generator produces a code generation report. To control production and opening of a code generation report, use app settings, codegen options, or configuration object properties.

In the MATLAB Coder app:

  • To generate a report, set Always create a report to Yes.

  • If you want the app to open the report for you, set Automatically launch a report if one is generated to Yes.

To view the code generation report, click the View report link. If no build errors occur, this report provides links to your MATLAB code, generated C/C++ files, and compile-time type information for the variables in your MATLAB code. If build errors occur, the report lists errors and warnings.

At the command line, use codegen options:

  • To generate a report, use the -report option.

  • To generate and open a report, use the -launchreport option.

Alternatively, use configuration object properties:

  • To generate a report, set GenerateReport to true.

  • If you want codegen to open the report for you, set LaunchReport to true.

Report Location

The code generation report is named report.mldatx. It is located in the html subfolder of the code generation output folder. If you have MATLAB R2018a or later, you can open the report.mldatx file by double-clicking it.

Errors and Warnings

View code generation error, warning, and information messages on the All Messages tab. To highlight the source code for an error or warning, click the message. It is a best practice to address the first message because subsequent errors and warnings can be related to the first message.

View compilation and linking errors and warnings on the Build Logs tab. The code generator detects compilation warnings only for MEX output or if you use a supported compiler for other types of output. See Supported Compilers.

Files and Functions

The report lists MATLAB source functions and generated files. In the MATLAB Source pane, the Function List view organizes functions according to the containing file. To visualize functions according to the call structure, use the Call Tree view.

To view a function in the code pane of the report, click the function in the list. Clicking a function opens the file that contains the function. To edit the selected file in the MATLAB Editor, click Edit in MATLAB or click a line number in the code pane.

If you have Embedded Coder and generate the report with traceability enabled, to view the source code and generated code next to each other in the code pane, click Trace Code. You can interactively trace between the source code and the generated code. See Interactively Trace Between MATLAB Code and Generated C/C++ Code (Embedded Coder).

If you want to move the generated files for standalone code (library or executable) to another development environment, you can put them into a zip file by clicking Package Code.

Specialized Functions or Classes

When a function is called with different types of inputs or a class uses different types for its properties, the code generator produces specializations. In the MATLAB Source pane, numbered functions (or classes) indicate specializations. For example:

Display of two specializations of the function fcn in the MATLAB Source pane.

Functions List After Fixed-Point Conversion

If you convert floating-point MATLAB code to fixed-point MATLAB code, and then generate fixed-point C/C++ code, the MATLAB Source pane lists the original MATLAB functions and the fixed-point MATLAB functions. For example:

Display of both the original and fixed-point MATLAB functions in the MATLAB source pane.

MATLAB Source

To view a MATLAB function in the code pane, click the name of the function in the MATLAB Source pane. In the code pane, when you pause on a variable or expression, a tooltip displays information about its size, type, and complexity. Additionally, syntax highlighting helps you to identify MATLAB syntax elements and certain code generation attributes, such as whether a function is extrinsic or whether an argument is constant.

Extrinsic Functions

The report identifies an extrinsic function with purple text. The tooltip indicates that the function is extrinsic.

This image shows the report when it identifies the extrinsic function. The extrinsic function is purple.

Constant Arguments

Orange text indicates a compile-time constant argument to an entry-point function or a specialized function. The tooltip includes the constant value.

This image shows the report when it identifies a compile-time costant argument. The constant a is highlighted in orange.

Knowing the value of a constant argument helps you to understand the generated function signatures. It also helps you to see when code generation creates function specializations for different constant argument values.

To export the value to a variable in the workspace, click the Export icon .

MATLAB Variables

The Variables tab provides information about the variables for the selected MATLAB function. To select a function, click the function in the MATLAB Source pane.

The variables table shows:

  • Class, size, and complexity

  • Properties of fixed-point types

  • Whether an array is sparse

  • Array layout

This information helps you to debug errors, such as type mismatch errors, and to understand how the code generator propagates types and represents data in the generated code.

Visual Indicators on the Variables Tab

This table describes the symbols, badges, and other indicators in the variables table.

Column in the Variables TableIndicatorDescription
NameexpanderVariable has elements or properties that you can see by clicking the expander.
Name{:}Homogenous cell array (all elements have the same properties).
Name{n}nth element of a heterogeneous cell array.
Classv > nv is reused with a different class, size, and complexity. The number n identifies a reuse with a unique set of properties. When you pause on a renamed variable, the report highlights only the instances of this variable that share the class, size, and complexity. See Reuse the Same Variable with Different Properties.
Size:nVariable-size array with an upper bound of n.
Size:?Variable-size array with no upper bound.
SizeitalicsVariable-size array whose dimensions do not change size during execution.
Classsparse prefixSparse array.
Classcomplex prefixComplex number.
Class

Fixed-point type.

To see the fixed-point properties, click the badge.

Array Layout Indicators on the Variables Tab

This table describes the badges that indicate array layout in the variables table.

BadgeDescription

Row-major array layout.

Column-major array layout.

A mixture of row-major and column-major layouts.

See Row-Major and Column-Major Array Layouts.

Tracing Code

You can trace between MATLAB source code and generated C/C++ code by using one of these methods:

  • Interactively visualize the mapping between the MATLAB code and the generated code. To access interactive tracing, in the report, click Trace Code.

    The Trace Code button is enabled only if you have Embedded Coder and you enabled code traceability when you generated code. See Interactively Trace Between MATLAB Code and Generated C/C++ Code (Embedded Coder).

  • Include source code as comments in the generated C/C++ code.

    In a comment, the code generator produces a tag that helps you find the corresponding MATLAB source code. If you have Embedded Coder, the tag is a link to the source code. See Tracing Generated C/C++ Code to MATLAB Source Code.

Code Insights

The code generator can detect and report issues that can potentially occur in the generated code. View the messages on the Code Insights tab. The issues include:

Additional Reports

If the generated code includes calls to platform-specific precompiled libraries, the Summary tab contains a link Precompiled Libraries. Click this link to view a list of paths for these libraries.

The Summary tab can also have links to these additional reports:

Report Limitations

  • The entry-point summary shows the individual elements of varargin and varargout, but the variables table does not show them.

  • The report does not show full information for unrolled loops. It displays data types of one arbitrary iteration.

  • The report does not show information about dead code.

Related Topics