Making M-Code Compliant with the Embedded MATLAB Subset

Debugging Strategies

Before performing code verification, The MathWorks recommends that you choose a debugging strategy for detecting and correcting noncompliant code in your MATLAB applications, especially if they consist of a large number of M-files that call each other's functions. Here are two best practices:

Debugging StrategyWhat to DoProsCons

Bottom-up verification

  1. Verify that your lowest-level (leaf) functions are compliant.

  2. Work your way up the function hierarchy incrementally to compile and verify each function, ending with the top-level function.

  • Efficient

  • Safe

  • Easy to isolate Embedded MATLAB syntax violations

Requires application tests that work from the bottom up

Top-down verification

  1. Declare all functions called by the top-level function to be extrinsic so Embedded MATLAB MEX does not compile them (see Declaring MATLAB Functions as Extrinsic Functions).

  2. Verify that your top-level function is compliant.

  3. Work your way down the function hierarchy incrementally by removing extrinsic declarations one by one to compile and verify each function, ending with the leaf functions.

Lets you retain your top-level tests

Introduces extraneous code that you must remove after code verification, including:

  • Extrinsic declarations

  • Additional assignment statements as necessary to convert opaque values returned by extrinsic functions to nonopaque values (see Working with mxArrays)

Detecting Embedded MATLAB Syntax Violations at Compile Time

Before you can successfully convert an M-file to a C-MEX function, you must verify that your M-code complies with Embedded MATLAB syntax and semantics, as defined in Working with the Embedded MATLAB Subset.

Embedded MATLAB MEX checks for all potential Embedded MATLAB syntax violations at compile time. When Embedded MATLAB MEX detects errors or warnings, it automatically generates a compilation report that describes the issues and provides links to the offending M-code. See Working with Compilation Reports.

If your M-code calls functions on the MATLAB path, Embedded MATLAB MEX attempts to compile these functions unless you declare them to be extrinsic (see How the Embedded MATLAB Subset Resolves Function Calls. To get detailed diagnostics, add the %#eml compiler directive to each external function that you want Embedded MATLAB MEX to compile, as described in Adding the Compilation Directive %#eml.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS