代码验证
生成的代码、可追溯性和代码生成报告的行为验证
生成代码后,检查源代码并输出结果以供验证。代码生成报告提供了一个交互式界面,用于检查生成的 C/C++ 源文件、生成的数据类型和其他代码细节。通过使用报告信息对象以编程方式访问代码生成报告中的信息子集。您可以对照原始 MATLAB® 代码对生成的 MEX 代码的输出进行测试,也可以基于 MATLAB 单元测试类创建自定义测试。您可以选择生成运行时错误检查,提醒您注意代码执行过程中出现的错误。
函数
codegen | 从 MATLAB 代码生成 C/C++ 代码。 |
coder.config | 创建 MATLAB Coder 代码生成配置对象 |
coder.ignoreConst | Prevent use of constant value of expression for function specializations |
coder.ignoreSize | Prevent code generator from creating function specializations for constant-size expressions |
coder.mfunctionname | Name of calling function or method (自 R2021b 起) |
coder.runTest | Run test replacing calls to MATLAB functions with calls to MEX functions |
getLineColumn | Find locations of beginning and end of MATLAB code involved in code generation |
类
coder.HardwareImplementation | Hardware-specific configuration parameters for C/C++ code generation from MATLAB code |
对象
coder.CodeConfig | Configuration parameters for C/C++ code generation from MATLAB code |
coder.EmbeddedCodeConfig | Configuration parameters for C/C++ code generation from MATLAB code with Embedded Coder |
coder.MexCodeConfig | Configuration parameters for MEX function generation from MATLAB code |
属性
coder.BuildLog Properties | Build logs produced during code generation |
coder.CodeFile Properties | Description of file containing text that is involved in code generation |
coder.File Properties | Description of file without text that is involved in code generation |
coder.Function Properties | Description of MATLAB function used in code generation |
coder.Message Properties | Description of message produced during code generation readiness analysis or during code generation |
coder.Method Properties | Description of method in a MATLAB class used in code generation |
coder.ReportInfo Properties | Code generation report information |
coder.Summary Properties | Summary of code generation from MATLAB code |
主题
代码生成报告
- Code Generation Reports
View code generation results. - Tracing Generated C/C++ Code to MATLAB Source Code
Generate traceability tags. - Access Code Generation Report Information Programmatically
Access information about code generation such as input files, generated files, and error messages by using a report information object.
测试生成的代码
- 测试从 MATLAB 代码生成的代码
验证生成代码的数值行为。 - Verify MEX Functions in the MATLAB Coder App
Compare results of running the original MATLAB function with the results from running the MEX function. - Verify MEX Functions at the Command Line
Test MEX functions withcoder.runTest
or thecodegen
-test
option. - Unit Test Generated Code with MATLAB Coder
Run MATLAB unit tests on generated code. - Unit Test External C Code with MATLAB Coder
Run MATLAB unit tests on generated code that integrates external C code.
运行时错误检测
- Generate Standalone C/C++ Code That Detects and Reports Run-Time Errors
Generate standalone libraries and executables that detect and report run-time errors, such as out-of-bounds array indexing.
故障排除
- Avoid Duplicate Functions in Generated Code
Reduce the occurrence of duplicate functions in the generated code. - Run-time Stack Overflow
Set the value of the maximum stack usage parameter.