comp.lang.ada
 help / color / mirror / Atom feed
* Data Elaboration
@ 2001-06-21 16:22 Martin Dowie
  2001-06-21 22:12 ` Jeffrey Carter
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Dowie @ 2001-06-21 16:22 UTC (permalink / raw)


IF I have a package containing data object declarations, is
it specified with the RM that they will be elaborated in
the same order every time? e.g.

package Blah is

   Bool1 : Boolean;  -- always elaborates first

   Bool2 : Boolean;  -- always elaborates second

   Int1  : Integer;  -- always elaborates third

end Blah;






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Data Elaboration
  2001-06-21 16:22 Data Elaboration Martin Dowie
@ 2001-06-21 22:12 ` Jeffrey Carter
  2001-06-22  6:04   ` Vincent Smeets
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey Carter @ 2001-06-21 22:12 UTC (permalink / raw)


Martin Dowie wrote:
> 
> IF I have a package containing data object declarations, is
> it specified with the RM that they will be elaborated in
> the same order every time? e.g.
> 
> package Blah is
> 
>    Bool1 : Boolean;  -- always elaborates first
> 
>    Bool2 : Boolean;  -- always elaborates second
> 
>    Int1  : Integer;  -- always elaborates third
> 
> end Blah;

Yes.

ARM 3.11(7) says "The elaboration of a declarative_part consists of the
elaboration of the declarative_items, if any, in the order in which they
are given in the declarative_part."

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Data Elaboration
  2001-06-21 22:12 ` Jeffrey Carter
@ 2001-06-22  6:04   ` Vincent Smeets
  2001-06-22  7:23     ` Martin Dowie
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Smeets @ 2001-06-22  6:04 UTC (permalink / raw)


Jeffrey Carter wrote:
> 
> Martin Dowie wrote:
> >
> > IF I have a package containing data object declarations, is
> > it specified with the RM that they will be elaborated in
> > the same order every time? e.g.
> >
> > package Blah is
> >
> >    Bool1 : Boolean;  -- always elaborates first
> >
> >    Bool2 : Boolean;  -- always elaborates second
> >
> >    Int1  : Integer;  -- always elaborates third
> >
> > end Blah;
> 
> Yes.
> 
> ARM 3.11(7) says "The elaboration of a declarative_part consists of the
> elaboration of the declarative_items, if any, in the order in which they
> are given in the declarative_part."

The answer is correct but I want to extend it with my practical view.

The above declartions require no special processing. The only thing that
has to be done is to reserve space in memory. This can be done by
extending the non initialize data segment or (in case of local
declarations) by changing the stack pointer. So you see that the
elaboration of these three variables can be done with one instruction
(all three at the same time).

An other case are variables initialized by constants. See the following
declarations:
	Bool1 : Boolean := True;
	Bool2 : Boolean := False;
Here (in case of global variables), room is allocated in the initialized
data segment which is initialized at startup of the program by copying
the values from the Object file to memory. In case of local variables,
the room is allocated at the stack and initialized. The compiler can
optimize the elaboration by copying more than one values to more than
one variables. (It can copy 8 bytes to the memory consiting of Bool1 and
Bool2).

Consider the case of initialized by Functions/variables. See the
following declarations:
	Bool1 : Boolean := Pkg2.Func1;
	Bool2 : Boolean := Pkg2.Bool;
Here the elaboration has to be done in order. The compiler can not know
if the function Pkg2.Func1 will cange the value of Pkg2.Bool1.



-- Vincent Smeets                    Competence Center Informatik GmbH
-- Tel. : +49-5931-805461            Postfach 1225
-- Fax  : +49-5931-805175            49702 Meppen, Germany
-- mailto:Vincent.Smeets@CCI.Sema.de http://www.CCI.de/
-- PGP fingerprint: E2437E38AAA9CA7D A31E7D751F1B6454 8AED7B76



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Data Elaboration
  2001-06-22  6:04   ` Vincent Smeets
@ 2001-06-22  7:23     ` Martin Dowie
  2001-06-22  9:29       ` Vincent Smeets
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Dowie @ 2001-06-22  7:23 UTC (permalink / raw)


Ok then, here's part 2 of the question! Given that they
will be elaborated in order (I was looking at section 3.3.1
not 3.11 :-(. If I change that to -

  with My_Allocator;

  package Blah is

     Bool1 : Boolean;  -- always elaborates first
    pragma Import (Ada, Bool1);
    pragma Volatile (Bool1);
    for Bool1'Address use My_Allocator (Bool1'Size);

    Bool2 : Boolean;  -- always elaborates second
    pragma Import (Ada, Bool2);
    pragma Volatile (Bool2);
    for Bool2'Address use My_Allocator (Bool2'Size);

     Int1  : Integer;  -- always elaborates third
    pragma Import (Ada, Int1);
    pragma Volatile (Int1);
    for Int'Address use My_Allocator (Int1'Size);

  end Blah;

where My_Allocator assigns memory space from a particular
start address, my objects will always elaborate to the
same locations, yes? (My_Allocator containing a protect
object to ensure sequential calculation of the addresses).

Vincent Smeets <Vincent.Smeets@CCI.Sema.de> wrote in message
news:3B32DFEB.1786FEE5@CCI.Sema.de...
> Jeffrey Carter wrote:
> >
> > Martin Dowie wrote:
> > >
> > > IF I have a package containing data object declarations, is
> > > it specified with the RM that they will be elaborated in
> > > the same order every time? e.g.
> > >
> > > package Blah is
> > >
> > >    Bool1 : Boolean;  -- always elaborates first
> > >
> > >    Bool2 : Boolean;  -- always elaborates second
> > >
> > >    Int1  : Integer;  -- always elaborates third
> > >
> > > end Blah;
> >
> > Yes.
> >
> > ARM 3.11(7) says "The elaboration of a declarative_part consists of the
> > elaboration of the declarative_items, if any, in the order in which they
> > are given in the declarative_part."
>
> The answer is correct but I want to extend it with my practical view.
>
> The above declartions require no special processing. The only thing that
> has to be done is to reserve space in memory. This can be done by
> extending the non initialize data segment or (in case of local
> declarations) by changing the stack pointer. So you see that the
> elaboration of these three variables can be done with one instruction
> (all three at the same time).
>
> An other case are variables initialized by constants. See the following
> declarations:
> Bool1 : Boolean := True;
> Bool2 : Boolean := False;
> Here (in case of global variables), room is allocated in the initialized
> data segment which is initialized at startup of the program by copying
> the values from the Object file to memory. In case of local variables,
> the room is allocated at the stack and initialized. The compiler can
> optimize the elaboration by copying more than one values to more than
> one variables. (It can copy 8 bytes to the memory consiting of Bool1 and
> Bool2).
>
> Consider the case of initialized by Functions/variables. See the
> following declarations:
> Bool1 : Boolean := Pkg2.Func1;
> Bool2 : Boolean := Pkg2.Bool;
> Here the elaboration has to be done in order. The compiler can not know
> if the function Pkg2.Func1 will cange the value of Pkg2.Bool1.
>
>
>
> -- Vincent Smeets                    Competence Center Informatik GmbH
> -- Tel. : +49-5931-805461            Postfach 1225
> -- Fax  : +49-5931-805175            49702 Meppen, Germany
> -- mailto:Vincent.Smeets@CCI.Sema.de http://www.CCI.de/
> -- PGP fingerprint: E2437E38AAA9CA7D A31E7D751F1B6454 8AED7B76





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Data Elaboration
  2001-06-22  7:23     ` Martin Dowie
@ 2001-06-22  9:29       ` Vincent Smeets
  2001-06-22 10:21         ` Martin Dowie
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Smeets @ 2001-06-22  9:29 UTC (permalink / raw)


Martin Dowie wrote:
> 
> Ok then, here's part 2 of the question! Given that they
> will be elaborated in order (I was looking at section 3.3.1
> not 3.11 :-(. If I change that to -
> 
>   with My_Allocator;
> 
>   package Blah is
> 
>      Bool1 : Boolean;  -- always elaborates first
>     pragma Import (Ada, Bool1);
>     pragma Volatile (Bool1);
>     for Bool1'Address use My_Allocator (Bool1'Size);
> 
>     Bool2 : Boolean;  -- always elaborates second
>     pragma Import (Ada, Bool2);
>     pragma Volatile (Bool2);
>     for Bool2'Address use My_Allocator (Bool2'Size);
> 
>      Int1  : Integer;  -- always elaborates third
>     pragma Import (Ada, Int1);
>     pragma Volatile (Int1);
>     for Int'Address use My_Allocator (Int1'Size);
> 
>   end Blah;
> 
> where My_Allocator assigns memory space from a particular
> start address, my objects will always elaborate to the
> same locations, yes? (My_Allocator containing a protect
> object to ensure sequential calculation of the addresses).

I would say (I'm not 100% sure) that the order of elaboration of Bool1,
Bool2 and Int1 will be the same. This does not mean that they always
will use the same memory. In case you have an other package with the
same allocation-construct, you can't directly predickt the order of
elaboration of packages. You can do some tuning with "pargma Elaborate".

By the way. You will need a pragma Elaborate (My_Allocator); for this
package.

Vincent

-- Vincent Smeets                    Competence Center Informatik GmbH
-- Tel. : +49-5931-805461            Postfach 1225
-- Fax  : +49-5931-805175            49702 Meppen, Germany
-- mailto:Vincent.Smeets@CCI.Sema.de http://www.CCI.de/
-- PGP fingerprint: E2437E38AAA9CA7D A31E7D751F1B6454 8AED7B76



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Data Elaboration
  2001-06-22  9:29       ` Vincent Smeets
@ 2001-06-22 10:21         ` Martin Dowie
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Dowie @ 2001-06-22 10:21 UTC (permalink / raw)


> I would say (I'm not 100% sure) that the order of elaboration of Bool1,
> Bool2 and Int1 will be the same. This does not mean that they always
> will use the same memory. In case you have an other package with the
> same allocation-construct, you can't directly predickt the order of
> elaboration of packages. You can do some tuning with "pargma Elaborate".

The cunning plan was to only allow these declarations from within
a single package, so I think we're covered.

> By the way. You will need a pragma Elaborate (My_Allocator); for this
> package.

Good point, well made. (it just happens to work with our current
compiler)





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-06-22 10:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-21 16:22 Data Elaboration Martin Dowie
2001-06-21 22:12 ` Jeffrey Carter
2001-06-22  6:04   ` Vincent Smeets
2001-06-22  7:23     ` Martin Dowie
2001-06-22  9:29       ` Vincent Smeets
2001-06-22 10:21         ` Martin Dowie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox