From: rod.chapman@praxis-cs.co.uk (Rod Chapman)
Subject: Re: pragma Import with 'Address clause
Date: 19 Mar 2003 14:29:01 -0800
Date: 2003-03-19T22:29:01+00:00 [thread overview]
Message-ID: <cf2c6063.0303191429.53f2fc13@posting.google.com> (raw)
In-Reply-To: slrnb7h93l.nt.lutz@taranis.iks-jena.de
Lutz Donnerhacke <lutz@iks-jena.de> wrote in message news:<slrnb7h93l.nt.lutz@taranis.iks-jena.de>...
> function get_b return BT is
> b : BT;
> for b'Address use xxx;
> begin
> return b+b;
> end get_b;
>
Again, this is really bad style. Giving Address clauses to local
variable is dubious at best and also defeats SPARK's information flow
model in various ways. Try something like this:
package Simple_Port
--# own in B; -- volatile "in" mode external variable
is
function Get_B return BT;
--# global in B;
end Simple_Port;
package body Simple_Port
is
B : BT;
for B'Address use ...; -- external variable with Address clause;
pragma Volatile (B); -- probably needed, so better safe than sorry...
function Get_B return BT
is
Raw_B, Result : BT;
begin
Raw_B := B; -- simple assignment OK.
if Raw_B'Valid then
Result := Raw_B + Raw_B; -- or whatever...
else
Result := BT'First; -- or some other safe value
end if;
return Result;
end Get_B;
end Simple_Port;
This is 100% SPARK and freedom from exceptions and invalid values
can be proven. Note that
1) The Examiner DOESN'T assert that "Local_B in BT" directly following
the first assignment, since the Examiner is clever enough to know
that something coming from a memory-mapped location might not have a
valid representation.
2) 'Valid can be used to re-establish validity.
3) In this context, an assignment such as
Raw_B := B + B;
is illegal in SPARK, since B is known to be Volatile, and therefore
such expressions are susceptible to undesirable evaluation
order dependencies.
We thought about these issues very hard indeed when designing the
external-variable and volatility model in SPARK! :-)
- Rod, SPARK Team.
next prev parent reply other threads:[~2003-03-19 22:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-19 14:12 pragma Import with 'Address clause Lutz Donnerhacke
2003-03-19 15:17 ` B0966864
2003-03-19 16:51 ` Stephen Leake
2003-03-19 17:10 ` Lutz Donnerhacke
2003-03-19 22:29 ` Rod Chapman [this message]
2003-03-21 11:13 ` Lutz Donnerhacke
2003-03-19 18:07 ` Rod Chapman
2003-03-21 11:31 ` Lutz Donnerhacke
-- strict thread matches above, loose matches on Subject: below --
2003-03-19 16:59 Beard, Frank Randolph CIV
2003-03-19 21:03 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox