Code Generation Node

This node contains the following options:

Protected against division by zero

Note

This option refers to generated C code, not to model divisions.

If this option is activated, ASCET generates a check to prevent division by zero at runtime. If the denominator is non-zero, the division is evaluated normally. If the denominator is zero, then, by default, the nominator is returned as result (i.e. a/b == a if b == 0).

The default result for a zero denominator can be modified via the Result on Division by Zero option.

This does not apply to integer divisions with arithmetic services, because arithmetic services routines are required to protect against division by 0.

The calculation of a remainder involves an implicit division. Activating the Protected against Division by Zero option protects the calculation of remainders from a zero divisor.

This option entails a performance penalty, so it should be deactivated to achieve maximum code efficiency.

Result on Division by Zero

When ASCET generates code to protect against division by 0 (activated via the Protected against Division by Zero option), this combo box determines the behavior upon division by zero.

If you select numerator (default), the numerator, limited to [value_range_min, value_range_max], is returned as result.

If you select user defined, a call to the user-defined C macro protDiv0(num, value_range_min, value_range_max) is returned. This macro has to be specified in one of the included header files.

Note

Make sure that the protDiv0 macro exists, and is correct, when you want to use the user defined option. An automatic existence or syntax check is not performed.

The macro arguments have the following meaning:

The second and third argument are used – in that order – to use the minimum and maximum of the value range of the division result. It is possible, for example, to provide the macro

#define protDiv0(num,min,max) (num<0?min:max)

to get, depending on the result data type, the largest, or smallest, possible integer value.

Note

The user macro is supposed to return a value in the range [value_range_min, value_range_max], because ASCET expects this for further optimizations.

Protected Division against Signed Overflow

Note

This option refers to generated C code, not to model divisions.

A signed overflow on a division occurs if the numerator value -2147483648 is divided by -1: the resulting value 2147483648 cannot be represented in a signed type, therefore, it overflows.

When this option is activated, divisions that might lead to a signed overflow at runtime are embedded, by the code generator, in a conditional operator that checks numerator and denominator of the division and – if necessary – uses the maximum value that can be represented by a signed type as division result.

This does not apply to integer divisions with arithmetic services, because arithmetic services routines are required to protect against signed overflow.

The calculation of a remainder involves an implicit division. Activating the Protected Division against Signed Overflow option also protects the calculation of remainders from signed overflow.

Note

A warning is generated if a potential division by 0 or signed overflow is not protected. By default, the warning is promoted to error (see Promoting Messages).

Protected Vector Indices

For the implementation experiment or object-based controller implementation, a warning of type WIle77 is issued when the code generator considers the index values of an array or matrix to be in danger of over- or underflow at runtime.

Note

By default, WIle77 is promoted to an error (see Promoting Messages).

If the Protected Vector Indices option is deactivated, the warning reads as follows:

index <%1> possibly out of bounds for indexed expression "%2" – will not be limited

If the Protected Vector Indices option is activated, the protection is implemented as a limitation of the index values. The warning now reads:

index <%1> possibly out of bounds for indexed expression "%2" – will be limited

If the array or matrix uses system constants to determine its size (see Variant Size for Arrays and Matrices), Protected Vector Indices uses the value of the system constant.

If the array or matrix uses variable size (see Variable Size for Arrays and Matrices), Protected Vector Indices uses the actual size.

Use Redundant Data Storage

This option allows to activate/deactivate redundant data storage for all elements marked as redundant. See also Redundant Data Storage.

Generation of Enums

This options controls how enumeration values are written to the generated code.

When you export a project to an AMD format V6.4.4 or older, or when you open an old project, the settings are transformed to the old option Closedas follows.

Add Comment with Implementation Information for each Assignment Statement

When this option is activated, a comment is generated in front of each assignment or return statement. This comment contains implementation information on the right-hand side of the assignment.

ClosedEXAMPLE

/* return with expr from doAddition:  

   min=-65536, max=65534, hex=1phys+0,  

   limit=(maxBitLength: true, assign: true)*/

return ((sint32)input1 + input2);

Add Comment with Specification Source for each Statement

When this option is activated, a comment is generated in front of each generated assignment. The comment contains the specification source of the assignment.

ESDL: line number

Block diagram: sequence call number

State machine: name of action/condition and respective state/transition

ClosedEXAMPLE (ESDL)

/* doAddition: line #1 */

self->cont->val = input1 + input2;

Add Comment with Generation Information for each Component

When this option is activated, comments are created at the beginning of the generated code for each component. The first comment contains information regarding the component and ASCET, the second contains all build and experiment/production code options.

Example: Comment with Generation Information for a Component

Allow References without Init Value

When this option is activated, it is possible to generate code for explicit references without intialization.

See also Initialization of Explicit References.

Expand names in #if in C Code Components

If this option is enabled, ASCET treats #if and #elif preprocessor directives in C code components like normal C code. This means that ASCET substitutes names of variables, constants, system constants, enumerations, etc.

Other preprocessor directives are kept as they are, especially #define.

Preprocess Internal Headers

If this option is enabled, ASCET perform name substitution and preprocessing also for the internal header of each C code component.

Prefix for Component Names

Inserts a character string as prefix for the component names in the generated code.

Casting

Allows the selection of a casting strategy. Available selections are MISRA compliant andTarget Optimized. The default selection is MISRA compliant.

The Arithmetic Services casting is no longer available.

Note

The following options are deprecated; they will be removed in future ASCET versions:

Force Parenthesis for Binary Logical Operators, Add parentheses for readability, Casting

See also

Component Manager – Promoting Messages

Variant Size for Arrays and Matrices

Variable Size for Arrays and Matrices

Redundant Data Storage

Comment with Generation Information for a Component

Initialization of Explicit References

MISRA Compliant

Target Optimized