Verify Code Replacement Library
Verify your code replacement library by examining its structure, replacement, and performance. Use the Code Replacement Viewer (crviewer) to verify the structure of your library. Use the code replacement report to verify the replacements made with your library in generated code. Use crviewer again to verify the performance of your library during code generation by examining the replacement hit and miss logs.
Verify Library Structure
Use the Code Replacement Viewer (crviewer) to open and view the structure of your code replacement library by examining its tables and table entries.
From the MATLAB command prompt, open your code replacement library using the crviewer with the command:
The viewer opens your code replacement library and shows its code replacement tables in the left pane. Verify that your library lists all required tables in the correct relative order.
Open and view the entries for each code replacement table. In the crtool, click each table listed in the left pane to view its entries in the middle pane.
If you are not using the crviewer, you can open each table directly from the MATLAB command prompt with the command:
For each table in your library, verify that it lists all required entries in the correct relative order. Verify that the conceptual representation and implementation representation are correct for each entry in the table.
Verify Library Replacement
Use the Code Replacements Report to verify that when the code generator uses your code replacement library it creates replacements as expected in the generated code. For each instance of replacement, the Code Replacements Report provides a mapping between the Simulink block that triggered the replacement and its implementation in the generated code. Use this mapping to verify correct code replacement by tracing between the report and the code in either direction (from report to code or code to report).
To generate the Code Replacements Report:
Configure your model to use your code replacement library.
Configure your model to open the Code Generation Report. The Code Replacements Report is a tab within this report. In the Model Configuration Parameters dialog box, in the Code Generation > Report pane, select:
Create code generation report
Open report automatically
Summarize which block triggered code replacements
Configure the generated code to include comments. In the Model Configuration Parameters dialog box, in the Code Generation > Comments pane, select:
Either or both of Simulink block comments and Simulink block descriptions
Build your model to generate code only. The Code Generation Report opens automatically. On the left pane, click to open the Code Replacements Report.
Verify that code replacements occur as expected.
Navigate from report to model: In the Code Replacements Report, click each block link to see the source that triggered replacement.
Navigate from model to report: In the Simulink model window, use model-to-code highlighting to trace code replacements. Right-click blocks where you expected code replacement to occur and select C/C++ Code > Navigate to C/C++ Code. The report appears with the corresponding replacement code highlighted.
Verify Library Performance
Verify the performance of your code replacement library by examining the hits and misses that occurred during code generation using your library. During code generation, when the code generator finds a match for code replacement from your code replacement library, it logs the hit in a hit cache. When it does not find a code replacement match, it logs the failed attempt in the miss cache. Each time that you generate code, the code generator overwrites its previous hit and miss cache logs.
To review trace information from the hit and miss cache data, use the Code Replacement Viewer (crviewer). From the hit cache, you can identify when code replacement successfully occurred, and from the miss cache, you can troubleshoot when code replacement did not take place. The miss cache trace information provides you information about the reason for the miss, a link to the relevant source location for the miss, and the call site object of the miss. For more information, see Troubleshoot Code Replacement Misses.