Main Content

What Is Code Replacement Customization?

Customize how and when the code generator replaces C/C++ code that it generates by default for functions, operators, and blocks by developing a custom code replacement library. You can develop libraries interactively with the Code Replacement Tool or programmatically.

  • Develop libraries tailored to specific application requirements

  • Add identifiers to the list of reserved keywords the code generator considers during code replacement

  • Customize the code generator’s match and replacement process for functions

To get started, Quick Start Code Replacement Library Development - Simulink.

For information about replacing code from some Simulink® blocks, see Block Replacement for Code Optimization.

Code Replacement Match and Replacement Process

When the code generator encounters a call site for a function or operator, it:

  1. Creates and partially populates a code replacement entry object with the function or operator name or key and conceptual arguments.

  2. Uses the entry object to query the configured code replacement library for a conceptual representation match. The code generator searches the tables in a code replacement library for a match in the order that the tables appear in the library. When searching for a match, the code generator takes into account:

    • Conceptual name or key

    • Arguments, including quantity, type, type qualifiers, and complexity

    • Algorithm (computation method)

    • Fixed-point saturation and rounding modes

    • Priority

  3. When a match exists, the code generator returns a code replacement object, fully populated with the conceptual representation, implementation representation, and priority. If the code generator finds multiple matches within a table, the entry priority determines the match. The priority can range from 0 to 100. The highest priority is 0. The code generator uses a higher-priority entry over a similar entry with a lower priority.

  4. Uses the C or C++ replacement function prototype in the code replacement object to generate code.

Code Replacement Customization Limitations

Related Topics