Main Content

coder.screener

Determine if function is suitable for code generation

Description

coder.screener(fcn) analyzes the entry-point MATLAB® function fcn to identify unsupported functions and language features as code generation compliance issues. The code generation compliance issues are displayed in the readiness report.

If fcn calls other functions directly or indirectly that are not MathWorks® functions (MATLAB built-in functions and toolbox functions), coder.screener analyzes these functions. It does not analyze the MathWorks functions.

It is possible that coder.screener does not detect all code generation issues. Under certain circumstances, it is possible that coder.screener reports false errors.

To avoid undetected code generation issues and false errors, before generating code, verify that your MATLAB code is suitable for code generation by performing these additional checks:

  • Before using coder.screener, fix issues that the Code Analyzer identifies.

  • After using coder.screener, and before generating C/C++ code, verify that your MATLAB code is suitable for code generation by generating and verifying a MEX function.

The coder.screener function does not report functions that the code generator treats as extrinsic. Examples of such functions are plot, disp, and figure. See Use MATLAB Engine to Execute a Function Call in Generated Code.

example

coder.screener(fcn,'-gpu') analyzes the entry-point MATLAB function fcn to identify unsupported functions and language features for GPU code generation.

coder.screener(fcn_1,...,fcn_n) analyzes multiple entry-point MATLAB functions.

example

info = coder.screener(___) returns a coder.ScreenerInfo object. The properties of this object contain the code generation readiness analysis results. Use info to access the code generation readiness results programmatically. For a list of properties, see coder.ScreenerInfo Properties.

example

Examples

collapse all

The coder.screener function identifies calls to functions that are not supported for code generation. It checks the entry-point function, foo1, and the function, foo2, that foo1 calls.

Write the function foo2 and save it in the file foo2.m.

function [tf1,tf2] = foo2(source,target)
G = digraph(source,target);
tf1 = hascycles(G);
tf2 = isdag(G);
end

Write the function foo1 that calls foo2. Save foo1 in the file foo1.m.

function [tf1,tf2] = foo1(source,target)
assert(numel(source)==numel(target))
[tf1,tf2] = foo2(source,target);
end

Analyze foo1.

coder.screener('foo1')

The Code Generation Readiness report displays a summary of the unsupported MATLAB function calls. The report Issues tab indicates that foo2.m contains one call to the isdag function and one call to the hascycles, which are not supported for code generation.

Screenshot of the code generation readiness tool with sample code and analysis results.

The function foo2 calls two unsupported MATLAB functions. To generate a MEX function, modify the code to make the calls to hascycles and isdag extrinsic by using the coder.extrinsic directive, and then rerun the code generation readiness tool.

function [tf1,tf2] = foo2(source,target)
coder.extrinsic('hascycles','isdag');
G = digraph(source,target);
tf1 = hascycles(G);
tf2 = isdag(G);
end

Rerun coder.screener on the entry-point function foo1.

coder.screener('foo1')

The report no longer flags that code generation does not support the hascycles and isdag functions. When you generate a MEX function for foo1, the code generator dispatches these two functions to MATLAB for execution.

You can call the coder.screener function with an optional output argument. If you use this syntax, the coder.screener function returns a coder.ScreenerInfo object that contains the results of the code generation readiness analysis for your MATLAB code base. See coder.ScreenerInfo Properties.

This example uses the files foo1.m and foo2.m defined in the previous example. Call the coder.screener function:

info = coder.screener('foo1.m')
info = 

  ScreenerInfo with properties:

               Files: [2×1 coder.CodeFile]
            Messages: [2×1 coder.Message]
    UnsupportedCalls: [2×1 coder.CallSite]

    View Screener Report

To access information about the first unsupported call, index into the UnsupportedCalls property,

firstCall = info.UnsupportedCalls(1)
firstCall = 

  CallSite with properties:

    CalleeName: 'hascycles'
          File: [1×1 coder.CodeFile]
    StartIndex: 78
      EndIndex: 86

View the text of the file that contains this unsupported call to hascycles.

firstCall.File.Text
ans =

    'function [tf1,tf2] = foo2(source,target)
     G = digraph(source,target);
     tf1 = hascycles(G);
     tf2 = isdag(G);
     end
     '

To export the entire code generation readiness report to a MATLAB string, use the textReport function.

reportString = textReport(info)
reportString =

    'Code Generation Readiness (Text Report)
     =======================================
     
     2 Code generation readiness issues
     2 Unsupported functions
     2 Files analyzed
     
     Configuration
     =============
     
     Language: C/C++ (MATLAB Coder)
     
     Code Generation Issues
     ======================
     
     Unsupported function: digraph (2)
         - foo2.m (Line 3)
         - foo2.m (Line 4)
     
     '

The coder.screener function identifies MATLAB data types that code generation does not support.

Write the function myfun1 that contains a MATLAB calendar duration array data type.

function out = myfun1(A)
out = calyears(A);
end

Analyze myfun1.

coder.screener('myfun1');

The code generation readiness report indicates that the calyears data type is not supported for code generation. Before generating code, fix the reported issue.

Input Arguments

collapse all

Name of entry-point MATLAB function for analysis. Specify as a character vector or a string scalar.

Example: coder.screener('myfun');

Data Types: char | string

Comma-separated list of entry-point MATLAB function names for analysis. Specify as character vectors or string scalars.

Example: coder.screener('myfun1','myfun2');

Data Types: char | string

Version History

Introduced in R2012b