UML and SysML to C - Operation Specification

This section describes the UML and SysML to C operation.

This page discusses:

Glossary

Acronym Definition
SPO Software Production Operation
BL Behavior Layer
ML Middleware Layer
BSM Behavior Specific Middleware
TSM Target Specific Middleware

Referenced Documents

Document Internal reference
Software Producer Model Specification [1]
UML & SysML - Component Model Generator Specification [2]
UML & SysML to C - Interface Code Generation Specifications [3]
UML & SysML to C - Activity Code Generator Specification [4]
UML & SysML to C - Constraint Code Generator Specification [5]
UML & SysML to C - Opaque Behavior Code Generator Specification [6]
UML & SysML to C - Statemachine Code Generator Specification [7]
C Code Architecture Specification [8]
Targeted Application Concepts [9]
UML & SysML To Code Concepts [10]
UML & SysML to C - Class Code Generator Specification [11]
UML & SysML to C - Assembly Code Generator Specification [12]

General Concepts

UML to C code operation is a code generation operation producing C Code from UML entities.

UML entities belong to a design composed of multiple design patterns described as follows: See [10] for more information.

Components Layer Generation

This operation generates the code associated with the Components Layer. Refer to [9] for more information on the Components layer.

Target layers

Note: A Software Producer model is generated with the code. The purpose of this mode is to describe the contract of the generated components and the connection between them. It mainly contains a description of:

  • Interface elements data, types, operations
  • Connections
  • Executable information

See [1] for more information on the Software Producer Model.

See [2] for more information on the model generation.

The generated code for a component can be composed of:

  • a Structure & Implementation of UML classes See [11]
  • a Classifier Behavior and Operations triggered by ExecutionTypes See XXX for more information on Execution Types
    • Statemachine - See [7]
    • Activity - See [4]
    • Opaque behavior - See [6]
  • a list of communication points – See [3]
    • SysML Constraint blocks connected to these communication point. See [5]

The generated code for the Communication & Scheduling Component specifies the communication between the components. It also schedules the behaviors triggered by Execution Types. See [12]

It is generated from a composition of components or from a single component to expose its communication points.

UML to C code generation operation generates automatically all of these elements.

The generated code of behaviors must have a predictable behavior. To respect this constraint, the input behavior must respect design patterns. The user is guided during the design phase thanks to validation constraints. Only a limited list of designed patterns is supported by the generator. See the dedicated documents for more information.

The code generator produces a valid code nevertheless, some specific parts, for example, the implementation of a state in a statemachine. You can implement or customize it, but the parts must respect the constraints described above.

Once the code is generated, you can modify identified parts of the generated code. These sections of code are identified through comments in the generated code as user code sections. User code sections can be used by other applications to perform a round-trip operation and replicate the modified code in the input model. Note: user code sections can be protected from one generation to another to avoid code loss. See [8] for more information on user code sections.

Limitation

Case of ambiguous semantics will be clarified in the next iteration of SysML Statemachine generator function.

A typical example is the order used to read and manage input signals, which impacts the statemachine behavior.

Input Elements

Not applicable

Validation Constraints

Generated code from a UML / SysML Behavior is expected to have predictable behavior. To respect this highly important constraint, the input behavior must respect design patterns. Only a limited list of designed patterns is supported by the generators and is described in specific documents.

Validation constraints are described in the code generators specific to each UML and SysML behavior. See the dedicated specification for more information.

Code Generator Specification

Software Production Operation Identity Card

Characteristics Values
Name UML to C
Nature Component generation
Description This operation generates C++ code for: - UML classes - SysML Blocks - Instance Specifications
Scan description The scan lists SysML blocks, UML classes and UML packages.
Supported files .mdzip and .mdxml
Input objects - SysML Block - UML Class - UML Package - Instance Specification
Return codes -1: generation is unsuccessful, 1: Generation is Successful, 2: Input data are incorrect, Model contains errors. Code generation cannot be executed.
Feature Generation -50 credits per selected class

Parameters

code_deployment_id Parameter

Attributes Values
Name code_deployment_id
Description Mandatory parameter to specify the code deployment identifier to be used in the generated
Type String
Multiplicity 1

report_name Parameter

Attributes Values
Name report_name
Description Optional parameter specifying the name of the validation report. It is possible to use specific options for the name of the report as following: - %time% to be replaced by the UTC date in ISO-8601 format of the validation. Example: 2022-08-31T09:39:45.856814300Z - %input_file_name% to be replaced by the input file name without its extension. Hidden in CATIA Magic.
Type String
Values [Default] %input_file_name%
Multiplicity 0..1

dry_run Parameter

Attributes Values
Name dry_run
Description This parameter is optional. It describes if the generation is executed in dry mode to obtain the log and validation report without producing an ESP assembly model. Hidden in CATIA Magic. Note: This option does not consume any credits.
Type Boolean
Values [Default] Yes / [No]
Multiplicity 0..1

Validate Parameter

Attributes Values
Name Validate
Description Optional parameter to specify if the validation is executed or not. If the validation is not executed, then no check is performed.
Type Boolean
Values [Default] [Yes] / No
Multiplicity 0..1

report_html Parameter

Attributes Values
Name report_html
Description Optional parameter to specify if the validation report is generated in HTML. The validate parameter must be defined as True. Hidden in CATIA Magic.
Type Boolean
Values [Default] Yes / [No]
Multiplicity 0..1

Implementation Generation Parameter

Attributes Values
Name Implementation Generation
Description Optional parameter to specify the type of generation. The Structure and Behavior Generation option includes behaviors described in the design. The Structure Only Generation option generates code with empty functions. The Headers Only Generation option produces only header files.
Type Enum
Values [Default] [full_implementation], empty_implementation, headers_only
Multiplicity 0..1

Instrumented Code Parameter

Attributes Values
Name Instrumented Code
Description Optional parameter to specify if extra instrumented code is generated. Instrumented code consists of additional variables to monitor the behavior of activities and statemachines.
Type Boolean
Values [Default] [false], true
Multiplicity 0..1

output Parameter

Attributes Values
Name output
Description Optional parameter that specifies the output directory in which resources are stored. If null, the generator generates a UML_to_C folder. Hidden in CATIA Magic.
Type String
Values [Default] N/A
Multiplicity 0..1

Objects Allocation Parameter

Attributes Values
Name Objects Allocation
Description Specifies the method to allocate memory for objects. Options are: Static to rely on variables for objects in generated code, Dynamic to rely on tal_allocate() function for memory allocation.
Type Enumeration
Values [Default] [Dynamic], Static
Multiplicity 0..1

Objects Access Parameter

Attributes Values
Name Objects Access
Description Optional parameter to specify the method to access objects. Options are: Pointer to access elements via pointer (pointers are used for objects referencing in classes - standard mode), Index to access elements via an index (indexes are used for objects referencing in classes and save space compared to pointers - reduce RAM usage). Default is Pointer. Note: the Objects Allocation parameter must be set to Static when this parameter is set to Index.
Type Enumeration
Values [Default] [Pointer], Index
Multiplicity 0..1

Memory Optimization Parameter

Attributes Values
Name Memory Optimization
Description Optional parameter to specify the method to optimize memory. Options are: None for no optimization, Prefer ROM to allocate all constant in ROM memory. Default is None. Note: the Objects Allocation parameter must be set to Static when this parameter is set to Prefer ROM.
Type Enumeration
Values [Default] [None], Prefer ROM
Multiplicity 0..1

Central Pool Size parameter

Attributes Values
Name Central Pool Size
Description Optional parameter to specify the central pool size to be applied. Default value is 512.
Type Positive Integer
Values [Default] [512]
Multiplicity 0..1

Default Pool Size Parameter

Attributes Values
Name Default Pool Size
Description Optional parameter specifying the default pool size to apply to all event pools without any specific size is configured. Default value is 128.
Type Positive Integer
Values [Default] [128]
Multiplicity 0..

Tick Frequency Parameter

Attributes Values
Name Tick Frequency
Description Optional parameter to specify the tick frequency used in the generated code. Default value is 1000 corresponding to 1000 Hz.
Type Positive Integer
Values [Default] [1000]
Multiplicity 0..1

Compiler Parameter

Attributes Values
Name Compiler
Description Optional parameter specifying the C compiler to be used to compile the generated code.
Type Enumeration
Values [Default] [none], gcc
Multiplicity 0..1

Misra Violation Comment Parameter

Attributes Values
Name Misra Violation Comment
Description If set to true, adds a comment in the generated code with the violated MISRA rule ID. By default, it is set to false.
Type Boolean
Values [Default] false
Multiplicity 0..1

Misra Ignore Parameter

Attributes Values
Name Misra Ignore
Description This option ignores MISRA violation inherited from the code generator. It avoids raising these known MISRA violations in the tool report. Violations related to user code are still sent. CppCheck premium is currently supported.
Type String
Values [Default] [none], ignore_cppcheck
Multiplicity 0..1

C Version Parameter

Attributes Values
Name C Version
Description Optional parameter specifying which C version the generated is compliant with.
Type Enumeration
Values [Default] [c99], c11, c17, c18, c23
Multiplicity 0..1

Derive Instance Graph Parameter

Attributes Values
Name Derive Instance Graph
Description Optional parameter to specify if an instance graph shall be derived from the design and included in the generation output.
Type boolean
Values [Default] [true] / false
Multiplicity 0..1

Files Specification

The code generator generates C code compliant with standard c99, c11, c17, c18.

Any character of the block name or the class name which is different of a digit, an ASCII letter, a - or a _, is replaced by an _ in the generated folder / file.

The file name of each behavior is composed with the parent names and its name separated by underscore.

MyBlock_ClassifierBehavior_SubBehavior.c/.h

Example 1 of a sub behavior file name called by the classifier behavior.

MyBlock_ClassifierBehavior_SubBehavior_SubSubBehavior.c/.h

Example 2 of a sub sub behavior file name called by a sub behavior called itself by the classifier behavior.

The operation must support the file header customization as defined in [8].

Depending on the behavior type, code generation is described in dedicated specification documents. For each behavior type, the name of the generated files is composed of a variable part and a fixed one. The variable part is identified in the specification documents as follows: <Behavior> and is replaced with the parent names as described above.