Your browser does not support JavaScript! Skip to main content
Free 30-day trial Customer portal Careers DO-178C Handbook
 
Rapita Systems
 

Industry leading verification tools & services

Rapita Verification Suite (RVS)

  RapiTest - Unit/system testing   RapiCover - Structural coverage analysis   RapiTime - Timing analysis (inc. WCET)   RapiTask - Scheduling visualization   RapiCoverZero - Zero footprint coverage analysis   RapiTimeZero - Zero footprint timing analysis   RapiTaskZero - Zero footprint scheduling analysis

Multicore Verification

  MACH178  Multicore Timing Solution  RapiDaemons

Engineering Services

  V & V Services  Qualification  Training  Tool Integration  Support

Industries

  Aerospace (DO-178C)   Automotive (ISO 26262)   Space

Other

  RTBx   Mx-Suite   Software licensing   Product life cycle policy  RVS development roadmap

Latest from Rapita HQ

Latest news

RVS 3.18 Launched
Solid Sands partners with Rapita Systems
Danlaw Acquires Maspatechnologies - Expanding Rapita Systems to Spain
Rapita co-authored paper wins ERTS22 Best paper award
View News

Latest from the Rapita blog

Measuring response times and more with RapiTime
Why mitigating interference alone isn’t enough to verify timing performance for multicore DO-178C projects
There are how many sources of interference in a multicore system?
Supporting modern development methodologies for verification of safety-critical software
View Blog

Latest discovery pages

do178c DO-178C Guidance: Introduction to RTCA DO-178 certification
matlab_simulink MATLAB® Simulink® MCDC coverage and WCET analysis
code_coverage_ada Code coverage for Ada, C and C++
amc-20-193 AMC 20-193
View Discovery pages

Upcoming events

NAVAIR FACE & SOSA TIM and Expo
2023-09-12
DASC 2023
2023-10-01
HISC 2023
2023-10-17
Aerospace Tech Week Americas 2023
2023-11-14
View Events

Technical resources for industry professionals

Latest White papers

DO178C Handbook
Efficient Verification Through the DO-178C Life Cycle
A Commercial Solution for Safety-Critical Multicore Timing Analysis
Compliance with the Future Airborne Capability Environment (FACE) standard
View White papers

Latest Videos

Challenges of certifying multicore avionics in line with A(M)C 20-193 objectives - ATW Europe 2023
Streamlined software verification with RVS 3.18
Sequence analysis with RapiTime
Visualize call dependencies with RVS thumbnail
Visualize call dependencies with RVS
View Videos

Latest Case studies

Supporting ISO 26262 ASIL D software verification for EasyMile
RapiCover’s advanced features accelerate the certification of military UAV Engine Control
Front cover of whitepaper collins
Delivering world-class tool support to Collins Aerospace
View Case studies

Other Downloads

 Webinars

 Brochures

 Product briefs

 Technical notes

 Research projects

Discover Rapita

Who we are

The company menu

  • About us
  • Customers
  • Distributors
  • Locations
  • Partners
  • Research projects
  • Contact us

US office

+1 248-957-9801
info@rapitasystems.com
Rapita Systems, Inc.
41131 Vincenti Ct.
Novi
MI 48375
USA

UK office

+44 (0)1904 413945
info@rapitasystems.com
Rapita Systems Ltd.
Atlas House
Osbaldwick Link Road
York, YO10 3JB
UK

Spain office

+34 93 351 02 05
info@rapitasystems.com
Rapita Systems S.L.
Parc UPC, Edificio K2M
c/ Jordi Girona, 1-3
Barcelona 08034
Spain

Working at Rapita

Careers

Careers menu

  • Current opportunities & application process
  • Working at Rapita
Back to Top

Ada enumerations are sometimes functions

Breadcrumb

  1. Home
  2. Blog
  3. Ada enumerations are sometimes functions
2016-04-18

In Ada, you declare a new enumeration type by providing a list of literals:

type Position is ( Left, Middle, Right );

Ada also lets you use character literals in an enumeration:

type Calc_Op is ( '*', '/', '+', '-' );

or even:

type DNACode is ( 'A', 'C', 'G', 'T', Unknown );

Once you have an enumeration type, you can use these literals just as you would other literals:

op: Calc_Op := '*';
...
case op
is
when '*' => ...

In Ada, each literal is technically the name of a function taking no arguments and returning the corresponding value. However, these functions are not generated in the object code unless they are actually needed. When such a function is needed, the compiler generates additional object code that does not correspond directly to the source code. For example, the "return" of the generated function does not correspond to a "return" statement in the source text. At DO-178B and DO-178C level A, it is important to analyse cases where the compiler introduces additional object code in this way (DO-178B 6.4.4.2(b)). Here are two straightforward cases that will cause this to happen.

Explicit renaming

The most direct way this happens is when you create a function that renames a literal:

function make_times return Calc_Op renames '*';

This causes the GNAT expander (we use gnatmake options -gnatDGL for this) to emit this definition:

function lee__make_times return lee__calc_op is
begin
return '*';
end lee__make_times;

If the renamed function is not called, later optimisation stages remove it. Otherwise, you get object code as follows (on a standard host platform):

00401510 <_lee__make_times.2282>:
401510:   55                      push   %ebp
401511:   89 e5                   mov    %esp,%ebp
401513:   83 ec 18                sub    $0x18,%esp
401516:   89 4d f4                mov    %ecx,-0xc(%ebp)
401519:   b8 00 00 00 00          mov    $0x0,%eax
40151e:   c9                      leave
40151f:   c3                      ret

Note here that the internal representation of '*' is not its ASCII code; it's allocated as per any other enumeration, starting from 0. Ada lets you take an access to such a function, but does not allow an access directly to the corresponding literal.

Generic parameters

If a parameter to a generic is a function of no arguments returning an enumeration value, a literal may be supplied directly without any need for renaming. In this example, the user can instantiate an evaluate function based on a Calc_Op :

generic
with function get_op return Calc_Op;
function evaluate( L, R: Integer )
return Integer;
function evaluate( L, R: Integer )
return Integer
is
begin
case get_op is
when '*' => return L * R;
when '/' => return L / R;
when '+' => return L + R;
when '-' => return L - R;
end case;
end evaluate;
function multiply is new evaluate( '*' );

In the expanded code, among the other package creation and expansion, GNAT provides a function for '*' . In the start of the new instance of evaluate, it creates a call to get_op :

function lee__multiply (l : integer; r : integer) return integer is
begin
R31b : constant lee__calc_op := lee__multiplyGP644__get_op;
...

and then later on, it creates a body for lee__multiplyGP644__get_op :

function lee__multiplyGP644__get_op return lee__calc_op is
begin
return '*';
end lee__multiplyGP644__get_op;

This makes some kind of sense: from the point of view of the code within the generic, whatever is supplied for get_op must behave exactly like a function, including taking an access to that function. The same thing happens with default values. Here is the same code with a default for get_op :

generic
with function get_op return Calc_Op is '+';
function evaluate( L, R: Integer )
return Integer;

Instantiating this without providing anything for get_op leads to a new function in the expander:

function multiply2 is new evaluate;
function lee__multiply2GP1096__get_op return lee__calc_op is
begin
return '+';
end lee__multiply2GP1096__get_op;

Function coverage and literals

If using this feature of the Ada language, we recommend analysing the generated object code on your platform to investigate how these implicit functions are generated. The intermediate view from the expander is helpful in explaining the intent of the additional object code. DO-178B and DO-178C structural coverage is assessed at the source level. You need to decide whether you want to treat functions that rename literals - directly or via generic formal functions - as source-level functions for which coverage should be demonstrated, or as compiler-added object code for which additional review is needed. Or, as with a lot of convenient features, impose a coding standard that forbids the use of these features in your critical code.

DO-178C webinars

DO178C webinars

White papers

DO178C Handbook Efficient Verification Through the DO-178C Life Cycle
A Commercial Solution for Safety-Critical Multicore Timing Analysis
Compliance with the Future Airborne Capability Environment (FACE) standard
5 key factors to consider when selecting an embedded testing tool

Related blog posts

Evolving language support in RVS: Libadalang

.
2020-04-09

Test your Ada skills with our puzzle

.
2019-06-18

Highlights from Ada-Europe 2018

.
2018-07-03

Highlights from Ada Europe 2016

.
2016-07-06

Pagination

  • Current page 1
  • Page 2
  • Page 3
  • Page 4
  • Page 5
  • Next page Next ›
  • Last page Last »
  • Solutions
    • Rapita Verification Suite
    • RapiTest
    • RapiCover
    • RapiTime
    • RapiTask
    • MACH178

    • Verification and Validation Services
    • Qualification
    • Training
    • Integration
  • Latest
  • Latest menu

    • News
    • Blog
    • Events
    • Videos
  • Downloads
  • Downloads menu

    • Brochures
    • Webinars
    • White Papers
    • Case Studies
    • Product briefs
    • Technical notes
    • Software licensing
  • Company
  • Company menu

    • About Rapita
    • Careers
    • Customers
    • Distributors
    • Industries
    • Locations
    • Partners
    • Research projects
    • Contact
  • Discover
    • AMC 20-193
    • What is CAST-32A?
    • Multicore Timing Analysis
    • MC/DC Coverage
    • Code coverage for Ada, C & C++
    • Embedded Software Testing Tools
    • Aerospace Software Testing
    • Automotive Software Testing
    • Certifying eVTOL
    • DO-178C
    • WCET Tools
    • Worst Case Execution Time
    • Timing analysis (WCET) & Code coverage for MATLAB® Simulink®

All materials © Rapita Systems Ltd. 2023 - All rights reserved | Privacy information | Trademark notice Subscribe to our newsletter