Main Content

Configure Model for Code Generation Objectives by Using Code Generation Advisor

Consider how your application objectives, such as efficiency, traceability, and safety, map to code generation parameters in a model configuration set. Parameters that you set in the Configuration Parameters dialog box specify the behavior of a model in simulation and the code generated for the model.

Before generating code, or as part of the code generation process, you can use the Code Generation Advisor to review a model. When you choose to review a model before generating code, you specify which model, subsystem, or referenced model the Code Generation Advisor reviews. When you choose to review a model as part of the code generation process, the Code Generation Advisor reviews the entire system. The Code Generation Advisor uses the information presented in Recommended Settings Summary for Model Configuration Parameters to determine the parameter values that meet your objectives. When there is a conflict between multiple objectives, the higher-priority objective takes precedence.

Setting code generation objectives, and then running the Code Generation Advisor provides information on how to meet code generation objectives for your model. The Code Generation Advisor does not alter the generated code. You can use the Code Generation Advisor to make the suggested changes to your model. The generated code is changed only after you modify your model and regenerate code. When you use the Code Generation Advisor to set code generation objectives and check your model, the generated code includes comments identifying which objectives you specified, the checks that the Code Generation Advisor ran on the model, and the results of running the checks.

If a model uses a configuration reference, you can run the Code Generation Advisor to review your configuration parameter settings. However, the Code Generation Advisor cannot modify the configuration parameter settings.

High-Level Code Generation Objectives

Depending on the type of application that your model represents, you are likely to have specific high-level code generation objectives. For example, safety and traceability are more critical than efficient use of memory. If you have specific objectives, you can quickly configure your model to meet those objectives by selecting and prioritizing from these code generation objectives:

  • Execution efficiency (all targets) — Configure code generation settings to achieve fast execution time.

  • ROM efficiency (ERT-based targets) — Configure code generation settings to reduce ROM usage.

  • RAM efficiency (ERT-based targets) — Configure code generation settings to reduce RAM usage.

  • Traceability (ERT-based targets) — Configure code generation settings to provide mapping between model elements and code.

  • Safety precaution (ERT-based targets) — Configure code generation settings to increase clarity, determinism, robustness, and verifiability of the code.

  • Debugging (all targets) — Configure code generation settings to debug the code generation build process.

  • MISRA C:2012 guidelines (ERT-based targets) — Configure code generation settings to increase compliance with MISRA C:2012 guidelines.

  • Polyspace (ERT-based targets) — Configure code generation settings to prepare the code for Polyspace® analysis.

If you select the MISRA C:2012 guidelines code generation objective, the Code Generation Advisor:

  • Checks the model configuration settings for compliance with the MISRA C:2012 configuration setting recommendations.

  • Checks for blocks that are not supported or recommended for MISRA C:2012 compliant code generation.

Specify Objectives in Referenced Models

When you check a model during the code generation process, you must specify the same objectives in the top model and referenced models. If you specify different objectives for the top model and referenced model, the build process generates an error.

To specify different objectives for the top model and each referenced model, review the models separately without generating code.

Configure Model Using Code Generation Advisor

This example shows how to use the Code Generation Advisor to check and configure your model to meet code generation objectives:

  1. On the C Code tab, click C/C++ Code Advisor.

  2. In the System Selector window, select the model or subsystem that you want to review, and then click OK.

  3. In the Code Generation Advisor, on the Code Generation Objectives pane, select the code generation objectives. As you select objectives, on the left pane, the Code Generation Advisor updates the list of checks it runs on your model. If your model is configured with an ERT-based target, more objectives are available. For this example, the model is configured with an ERT-based target. If your objectives are execution efficiency and traceability, in that priority, do the following:

    1. In Available objectives, double-click Execution efficiency. Execution efficiency is added to Selected objectives - prioritized.

    2. In Available objectives, double-click Traceability. Traceability is added to Selected objectives - prioritized under Execution efficiency.

  4. To run the checks listed in the left pane of the Code Generation Advisor, right-click on the Code Generation Advisor folder and select Run Selected Checks.

  5. In the Code Generation Advisor window, review the results for Check model configuration settings against code generation objectives by selecting it from the left pane. The results for that check are displayed in the right pane.

    Check model configuration settings against code generation objectives triggers a warning for these issues:

    • Parameters are set to values other than the value recommended for the specified code generation objectives.

    • Selected code generation objectives differ from the objectives set in the model.

    Click Modify Parameters to set:

    • Parameters to the value recommended for the specified code generation objectives.

    • Code generation objectives in the model to the objectives specified in the Code Generation Advisor.

  6. In the Code Generation Advisor window, review the results for the remaining checks by selecting them from the left pane. The results for the checks display in the right pane.

  7. After reviewing the check results, you can choose to fix warnings and failures, as described in Fix a Model Advisor Check Warning or Failure.

When you specify an efficiency or Safety precaution objective, the Code Generation Advisor includes additional checks. When you make changes to one of these additional checks, previous check results can potentially become invalid and need to be rerun.

Configure Model for Code Generation Objectives by Using Configuration Parameters Dialog Box

This example shows how to configure and check your model to meet code generation objectives via the Configuration Parameters dialog box:

  1. Open the Configuration Parameters dialog box. Select Code Generation.

  2. Specify a system target file. If you specify an ERT-based target, more objectives are available. For this example, choose an ERT-based target such as ert.tlc.

  3. Click Set Objectives.

  4. In the Set Objectives — Code Generation Advisor Dialog Box, specify your objectives. For example, if your objectives are execution efficiency and traceability, in that priority, do the following:

    1. In Available objectives, double-click Execution efficiency. Execution efficiency is added to Selected objectives - prioritized.

    2. In Available objectives, double-click Traceability. Traceability is added to Selected objectives - prioritized under Execution efficiency.

    3. To accept the objectives, click OK. In the Configuration Parameters dialog box, Code Generation > Prioritized objectives is updated.

  5. On the Code Generation pane, click Check Model.

  6. In the System Selector window, select the model or subsystem that you want to review, and then click OK. The Code Generation Advisor opens and reviews the model or subsystem that you specified.

  7. In the Code Generation Advisor window, review the results by selecting a check from the left pane. The results for that check display in the right pane.

  8. After reviewing the check results, you can choose to fix warnings and failures, as described in Fix a Model Advisor Check Warning or Failure.

When you specify an efficiency or Safety precaution objective, the Code Generation Advisor includes additional checks. When you make changes to one of these additional checks, previous check results can potentially become invalid and need to be rerun.

For more information, see Set Objectives — Code Generation Advisor Dialog Box

Related Topics