comp.lang.ada
 help / color / mirror / Atom feed
* [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
@ 2004-01-02 11:59 Luke A. Guest
  2004-01-02 17:51 ` Stephen Leake
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Luke A. Guest @ 2004-01-02 11:59 UTC (permalink / raw)


Hi,

In my attempts to get a "hello world" style kernel running on my SGI O2,
I have been developing a simple program to dump out a character to the
PROM console.

I have a package which has all my definitions and types needed by the
functions in the ARCS PROM. I have also needed to add the
No_Elaboration_Code pragma to get static initialisation code much like
that of C. Now, here are the problems:

1) There are two <enum type>_rep_to_pos functions generated but never
used.

2) I have set up my SP_Block record instance to be located at a particular
memory address, yet the compiler still generates code to initialise this
structure.

So, my question is this; is this a bug in the compiler or am I missing
something?

I'm currently using GCC-3.3.2 with the FSF GNAT package.

I can remove the redundant code by using the following GCC options
"-ffunction-sections -fdata-sections" and linker option "--gc-sections"
but this is a workaround rather than a solution.

Thanks,
Luke.




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 11:59 [No_Elaboration_Code] GNAT still generating rep_to_pos, why? Luke A. Guest
@ 2004-01-02 17:51 ` Stephen Leake
  2004-01-02 18:14   ` Luke A. Guest
  2004-01-03  1:41 ` sk
  2004-01-03 10:48 ` Florian Weimer
  2 siblings, 1 reply; 20+ messages in thread
From: Stephen Leake @ 2004-01-02 17:51 UTC (permalink / raw)
  To: comp.lang.ada

"Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:

> So, my question is this; is this a bug in the compiler or am I missing
> something?

Try "pragma No_Run_Time" in your gnat.ads file. It says "don't
generate _anything_ not directly required by my code", in effect.

> I'm currently using GCC-3.3.2 with the FSF GNAT package.

"pragma No_Run_Time" may not be supported by this version. Look in the
gnat rm for similar pragmas; I think there is one to suppress the enum
stuff. 

Note that No_Run_Time is not documented.

> I can remove the redundant code by using the following GCC options
> "-ffunction-sections -fdata-sections" and linker option "--gc-sections"
> but this is a workaround rather than a solution.

Well, GNAT is not normally used to build kernels, and kernels are
_not_ like typical user programs. So I would not be surprised to need
some extra compiler/linker options. I'd call that a "solution", if
there is not a GNAT pragma that does what you need.

-- 
-- Stephe




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 17:51 ` Stephen Leake
@ 2004-01-02 18:14   ` Luke A. Guest
  2004-01-02 19:31     ` Per Sandberg
                       ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Luke A. Guest @ 2004-01-02 18:14 UTC (permalink / raw)


On Fri, 02 Jan 2004 12:51:56 -0500, Stephen Leake wrote:

> "Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:
> 
>> So, my question is this; is this a bug in the compiler or am I missing
>> something?
> 
> Try "pragma No_Run_Time" in your gnat.ads file. It says "don't
> generate _anything_ not directly required by my code", in effect.
> 
>> I'm currently using GCC-3.3.2 with the FSF GNAT package.
> 
> "pragma No_Run_Time" may not be supported by this version. Look in the
> gnat rm for similar pragmas; I think there is one to suppress the enum
> stuff. 
> 
> Note that No_Run_Time is not documented.

I have this in my gnat.adc (not gnat.ads) file:

pragma No_Run_Time;
pragma Restrictions(No_Exceptions);

This is in the GNAT RM from the GCC site:

"pragma No_Run_Time
    Syntax:

          pragma No_Run_Time;
          

    This is a configuration pragma that makes sure the user code does not
use nor need anything from the GNAT run time. This is mostly useful in
context where code certification is required. Please consult the GNAT Pro
High-Integrity Edition User's Guide for additional information."

>> I can remove the redundant code by using the following GCC options
>> "-ffunction-sections -fdata-sections" and linker option "--gc-sections"
>> but this is a workaround rather than a solution.
> 
> Well, GNAT is not normally used to build kernels, and kernels are
> _not_ like typical user programs. So I would not be surprised to need
> some extra compiler/linker options. I'd call that a "solution", if
> there is not a GNAT pragma that does what you need.

Although a kernel is not a *normal* program, Ada was designed to be
used in the embedded sector with or without an OS, so there must be a
solution as somebody must've needed to do what I'm wanting to do at some point.

Thanks,
Luke.




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 18:14   ` Luke A. Guest
@ 2004-01-02 19:31     ` Per Sandberg
  2004-01-02 19:46       ` Luke A. Guest
  2004-01-02 21:17     ` Stephen Leake
  2004-01-03  1:12     ` Robert I. Eachus
  2 siblings, 1 reply; 20+ messages in thread
From: Per Sandberg @ 2004-01-02 19:31 UTC (permalink / raw)
  To: Luke A. Guest; +Cc: comp.lang.ada

To avoid elaboration code is quite simple, just write all your packages 
in such a way that no elaboration code is needed.

The simplest way to make this hapend is to add
	"pragma pure"
or
	"pragma preelaborate"
in all your specs.
Then the compiler will force you to write the code in suh a way that no 
elaboration code is needed.

/Per

Luke A. Guest wrote:

> On Fri, 02 Jan 2004 12:51:56 -0500, Stephen Leake wrote:
> 
> 
>>"Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:
>>
>>
>>>So, my question is this; is this a bug in the compiler or am I missing
>>>something?
>>
>>Try "pragma No_Run_Time" in your gnat.ads file. It says "don't
>>generate _anything_ not directly required by my code", in effect.
>>
>>
>>>I'm currently using GCC-3.3.2 with the FSF GNAT package.
>>
>>"pragma No_Run_Time" may not be supported by this version. Look in the
>>gnat rm for similar pragmas; I think there is one to suppress the enum
>>stuff. 
>>
>>Note that No_Run_Time is not documented.
> 
> 
> I have this in my gnat.adc (not gnat.ads) file:
> 
> pragma No_Run_Time;
> pragma Restrictions(No_Exceptions);
> 
> This is in the GNAT RM from the GCC site:
> 
> "pragma No_Run_Time
>     Syntax:
> 
>           pragma No_Run_Time;
>           
> 
>     This is a configuration pragma that makes sure the user code does not
> use nor need anything from the GNAT run time. This is mostly useful in
> context where code certification is required. Please consult the GNAT Pro
> High-Integrity Edition User's Guide for additional information."
> 
> 
>>>I can remove the redundant code by using the following GCC options
>>>"-ffunction-sections -fdata-sections" and linker option "--gc-sections"
>>>but this is a workaround rather than a solution.
>>
>>Well, GNAT is not normally used to build kernels, and kernels are
>>_not_ like typical user programs. So I would not be surprised to need
>>some extra compiler/linker options. I'd call that a "solution", if
>>there is not a GNAT pragma that does what you need.
> 
> 
> Although a kernel is not a *normal* program, Ada was designed to be
> used in the embedded sector with or without an OS, so there must be a
> solution as somebody must've needed to do what I'm wanting to do at some point.
> 
> Thanks,
> Luke.
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 19:31     ` Per Sandberg
@ 2004-01-02 19:46       ` Luke A. Guest
  0 siblings, 0 replies; 20+ messages in thread
From: Luke A. Guest @ 2004-01-02 19:46 UTC (permalink / raw)


On Fri, 02 Jan 2004 20:31:53 +0100, Per Sandberg wrote:

> To avoid elaboration code is quite simple, just write all your packages 
> in such a way that no elaboration code is needed.
> 
> The simplest way to make this hapend is to add
> 	"pragma pure"

Can't use pure because this package has access types and an instance of a
record type.

> or
> 	"pragma preelaborate"
> in all your specs.
> Then the compiler will force you to write the code in suh a way that no 
> elaboration code is needed.

I tried this one, but the that code is still generated.

Thanks,
Luke.




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 18:14   ` Luke A. Guest
  2004-01-02 19:31     ` Per Sandberg
@ 2004-01-02 21:17     ` Stephen Leake
  2004-01-02 22:16       ` Luke A. Guest
  2004-01-03  8:44       ` Luke A. Guest
  2004-01-03  1:12     ` Robert I. Eachus
  2 siblings, 2 replies; 20+ messages in thread
From: Stephen Leake @ 2004-01-02 21:17 UTC (permalink / raw)
  To: comp.lang.ada

"Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:

> I have this in my gnat.adc (not gnat.ads) file:
> 
> pragma No_Run_Time;
> pragma Restrictions(No_Exceptions);
> 
> This is in the GNAT RM from the GCC site:
> 
> <snip>

Cool. So it's supported, and documented. I'd say you have found a bug
in the implementation of No_Run_Time, but I'm not really clear.

> >> I can remove the redundant code by using the following GCC options
> >> "-ffunction-sections -fdata-sections" and linker option "--gc-sections"
> >> but this is a workaround rather than a solution.
> > 
> > Well, GNAT is not normally used to build kernels, and kernels are
> > _not_ like typical user programs. So I would not be surprised to need
> > some extra compiler/linker options. I'd call that a "solution", if
> > there is not a GNAT pragma that does what you need.
> 
> Although a kernel is not a *normal* program, Ada was designed to be
> used in the embedded sector with or without an OS, so there must be
> a solution as somebody must've needed to do what I'm wanting to do
> at some point.

Well, when Ada is used "without an OS", that usually means the
compiler vendor supplies a "run-time" that looks a lot like a
multi-threading OS. That run-time may be written in Ada. If it is, it
probably uses some custom stuff in the vendor's compiler to get things
done.

If all you need in the way of "custom stuff" is the gcc flags above,
I'd say GNAT is in very good shape for doing what you want.

At the same time, it wouldn't hurt to send a message to
report@gnat.com, describing what you are doing and what you'd like to
see. Phrase it as a bug in No_Run_Time if you want. If enough people
(especially paying customers) ask for the same thing, eventually it
will get done.
 
-- 
-- Stephe




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 21:17     ` Stephen Leake
@ 2004-01-02 22:16       ` Luke A. Guest
  2004-01-03  1:43         ` Stephen Leake
       [not found]         ` <87ekuhe5wq.fsf@news.sdbk.de>
  2004-01-03  8:44       ` Luke A. Guest
  1 sibling, 2 replies; 20+ messages in thread
From: Luke A. Guest @ 2004-01-02 22:16 UTC (permalink / raw)


On Fri, 02 Jan 2004 16:17:59 -0500, Stephen Leake wrote:

> "Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:
> 
>> I have this in my gnat.adc (not gnat.ads) file:
>> 
>> pragma No_Run_Time;
>> pragma Restrictions(No_Exceptions);
>> 
>> This is in the GNAT RM from the GCC site:
>> 
>> <snip>
> 
> Cool. So it's supported, and documented. I'd say you have found a bug
> in the implementation of No_Run_Time, but I'm not really clear.

Ok ;-/

>> Although a kernel is not a *normal* program, Ada was designed to be
>> used in the embedded sector with or without an OS, so there must be
>> a solution as somebody must've needed to do what I'm wanting to do
>> at some point.
> 
> Well, when Ada is used "without an OS", that usually means the
> compiler vendor supplies a "run-time" that looks a lot like a
> multi-threading OS. That run-time may be written in Ada. If it is, it

Currently, I have copied over the following files from the
gcc-3.3.2/gcc/ada dir to my project dir:

1ic.ads, interfac.ads, s-stoele.ad[bs], s-unstyp.ads, system.ads &
unchconv.ads.

Really, all you need for this is the basic stuff, no exception handling,
no tasking, etc. But what files this is in, I have no clue ;-)

> probably uses some custom stuff in the vendor's compiler to get things
> done.
> 
> If all you need in the way of "custom stuff" is the gcc flags above,
> I'd say GNAT is in very good shape for doing what you want.

Yeah, that does reduce the final ELF file, which is good. But, like I
said, it's better to get the compiler to do it - if that's what it's
supposed to do.

> At the same time, it wouldn't hurt to send a message to
> report@gnat.com, describing what you are doing and what you'd like to
> see. Phrase it as a bug in No_Run_Time if you want. If enough people
> (especially paying customers) ask for the same thing, eventually it
> will get done.

Is there a GNAT specific (user) mail list I can join?

Thanks,
Luke.





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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 18:14   ` Luke A. Guest
  2004-01-02 19:31     ` Per Sandberg
  2004-01-02 21:17     ` Stephen Leake
@ 2004-01-03  1:12     ` Robert I. Eachus
  2004-01-03  8:41       ` Luke A. Guest
  2 siblings, 1 reply; 20+ messages in thread
From: Robert I. Eachus @ 2004-01-03  1:12 UTC (permalink / raw)


Luke A. Guest wrote:

> Although a kernel is not a *normal* program, Ada was designed to be
> used in the embedded sector with or without an OS, so there must be a
> solution as somebody must've needed to do what I'm wanting to do at some point.

It depends on what you need done.  I'm not sure, but from what you have 
posted it sounds like you have a data structure that has to be located 
at a particular location, and not be initialized by GNAT.

pragma No_Run_Time will not do this.  You need to use pragma Import if 
you don't want the access values to be set by default to null.  This is 
not done by the run-time, it is done by the elaboration code for the 
unit where the imported object is declared, usually the main program. 
See RM B.1(24).  This is one of those things which makes sense once you 
grok the whole--the only case where you don't want default 
initializations is where the initializations are explicitly performed by 
non-Ada code.  But it is often the case that the object you need not to 
be default initialized when calling C code is a pointer, not the data 
itself.  Sometimes you even need two pragma Imports for one object, one 
for a pointer, and one for the data object itself.

-- 
                                           Robert I. Eachus

"The war on terror is a different kind of war, waged capture by capture, 
cell by cell, and victory by victory. Our security is assured by our 
perseverance and by our sure belief in the success of liberty." -- 
George W. Bush




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 11:59 [No_Elaboration_Code] GNAT still generating rep_to_pos, why? Luke A. Guest
  2004-01-02 17:51 ` Stephen Leake
@ 2004-01-03  1:41 ` sk
  2004-01-03  2:29   ` Luke A. Guest
  2004-01-03 10:48 ` Florian Weimer
  2 siblings, 1 reply; 20+ messages in thread
From: sk @ 2004-01-03  1:41 UTC (permalink / raw)
  To: comp.lang.ada

"Luke A. Gueast" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk>

 > ... <snip> ...

I have a "Hello World" "kernel" for the i386 which might provide
a starting point for you.

It is ELF32, loaded by GRUB, incorporates the "pragma No_Run_Time"
and all the flags I used to create it.

The "kernel" is totally useless since once "Hello World" is printed,
the processor is halted.

www.ktc.com/~sknipe and follow the links.

-- 
-------------------------------------------------
-- Merge vertically for real address
--
--     s n p @ t . o
--      k i e k c c m
-------------------------------------------------




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 22:16       ` Luke A. Guest
@ 2004-01-03  1:43         ` Stephen Leake
       [not found]         ` <87ekuhe5wq.fsf@news.sdbk.de>
  1 sibling, 0 replies; 20+ messages in thread
From: Stephen Leake @ 2004-01-03  1:43 UTC (permalink / raw)
  To: comp.lang.ada

"Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:

> Is there a GNAT specific (user) mail list I can join?

Not that I'm aware of. comp.lang.ada is a good place for general GNAT
questions. 

-- 
-- Stephe




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-03  1:41 ` sk
@ 2004-01-03  2:29   ` Luke A. Guest
  0 siblings, 0 replies; 20+ messages in thread
From: Luke A. Guest @ 2004-01-03  2:29 UTC (permalink / raw)


On Fri, 02 Jan 2004 19:41:21 -0600, sk wrote:

> "Luke A. Gueast" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk>
> 
>  > ... <snip> ...
> 
> I have a "Hello World" "kernel" for the i386 which might provide
> a starting point for you.
> 
> It is ELF32, loaded by GRUB, incorporates the "pragma No_Run_Time"
> and all the flags I used to create it.
> 
> The "kernel" is totally useless since once "Hello World" is printed,
> the processor is halted.
> 
> www.ktc.com/~sknipe and follow the links.

Well, mine works, but it doesn't halt the processor so I can load another
compiled version staight away from the PROM.

Luke.




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-03  1:12     ` Robert I. Eachus
@ 2004-01-03  8:41       ` Luke A. Guest
  2004-01-03 11:53         ` Simon Wright
  0 siblings, 1 reply; 20+ messages in thread
From: Luke A. Guest @ 2004-01-03  8:41 UTC (permalink / raw)


On Fri, 02 Jan 2004 20:12:28 -0500, Robert I. Eachus wrote:

> pragma No_Run_Time will not do this.  You need to use pragma Import if 
> you don't want the access values to be set by default to null.  This is 

This is my code:

  type T_SPB is
    record
      ...
    end record;

  type T_SPB_PTR is access T_SPB;

  SP_Block : T_SPB;
  for SP_Block'Address use System'To_Address(16#80001000#);
  -- Tell the compiler that this record is defined elsewhere.
  -- Stops the compiler from producing a warning.
  pragma Import(Ada, SP_Block);

Luke.




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 21:17     ` Stephen Leake
  2004-01-02 22:16       ` Luke A. Guest
@ 2004-01-03  8:44       ` Luke A. Guest
  1 sibling, 0 replies; 20+ messages in thread
From: Luke A. Guest @ 2004-01-03  8:44 UTC (permalink / raw)


On Fri, 02 Jan 2004 16:17:59 -0500, Stephen Leake wrote:

> At the same time, it wouldn't hurt to send a message to
> report@gnat.com, describing what you are doing and what you'd like to

Well, I did that and here's the reply:

Luke A. Guest wrote:

 > I'm currently using GCC-3.3.2 with the FSF GNAT package.

Sorry, we don't provide any kind of support for versions of GNAT
compiled from the FSF sources at this address. But I have added a
couple of notes below.

> I have a package which has all my definitions and types needed by the
> functions in the ARCS PROM. I have also needed to add the
> No_Elaboration_Code pragma to get static initialisation code much like
> that of C. Now, here are the problems:

No_Run_Time is no longer a supported or documented pragma

> 1) There are two <enum type>_rep_to_pos functions generated but never
> used (it doesn't need them).
> 
> 2) I have set up my SP_Block record instance to be located at a
> particular memory address, yet the compiler still generates code to
> initialise this structure.

Although it is in fact working as intended.

> I have had to add the following GCC options "-ffunction-sections
> -fdata-sections" and linker option "--gc-sections" to remove the
> redundant code.

We do not claim to support these options, so you are on your own
if you use them

> I have this in my gnat.adc file:
> 
> pragma No_Run_Time;
> pragma Restrictions(No_Exceptions);
> 
> I also included this "pragma preelaborate" in my ARCS_Prom package.
> 
> You can see the rest of the conversation in comp.lang.ada
> "[No_Elaboration_Code] GNAT still generating rep_to_pos, why?"

Sorry, I do not read comp.lang.ada (and have not for a long time). 
Perhaps someone there can help you further.




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
       [not found]         ` <87ekuhe5wq.fsf@news.sdbk.de>
@ 2004-01-03  9:58           ` Luke A. Guest
  0 siblings, 0 replies; 20+ messages in thread
From: Luke A. Guest @ 2004-01-03  9:58 UTC (permalink / raw)


On Sat, 03 Jan 2004 10:29:57 +0100, Sebastian D.B. Krause wrote:

> http://news.gmane.org/gmane.comp.gcc.gnat/
> http://mail.gnu.org/mailman/listinfo/help-gnat

Yeah, I'd say that's dead.

Luke.




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-02 11:59 [No_Elaboration_Code] GNAT still generating rep_to_pos, why? Luke A. Guest
  2004-01-02 17:51 ` Stephen Leake
  2004-01-03  1:41 ` sk
@ 2004-01-03 10:48 ` Florian Weimer
  2004-01-03 11:32   ` Luke A. Guest
  2 siblings, 1 reply; 20+ messages in thread
From: Florian Weimer @ 2004-01-03 10:48 UTC (permalink / raw)


"Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:

> 1) There are two <enum type>_rep_to_pos functions generated but never
> used.

That's because you have an enumeration type with a non-standard
representation (see the GNAT source code).

> 2) I have set up my SP_Block record instance to be located at a particular
> memory address, yet the compiler still generates code to initialise this
> structure.

pragma Import with convention Ada (or C) should help.



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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-03 10:48 ` Florian Weimer
@ 2004-01-03 11:32   ` Luke A. Guest
  2004-01-03 13:11     ` Florian Weimer
  0 siblings, 1 reply; 20+ messages in thread
From: Luke A. Guest @ 2004-01-03 11:32 UTC (permalink / raw)


On Sat, 03 Jan 2004 11:48:28 +0100, Florian Weimer wrote:

> "Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:
> 
>> 1) There are two <enum type>_rep_to_pos functions generated but never
>> used.
> 
> That's because you have an enumeration type with a non-standard
> representation (see the GNAT source code).

Yes, but I was wondering whether I could tell the compiler not to generate
this code as I'm producing static initialisation here.

>> 2) I have set up my SP_Block record instance to be located at a particular
>> memory address, yet the compiler still generates code to initialise this
>> structure.
> 
> pragma Import with convention Ada (or C) should help.

I've already mentioned this in an earlier part of the thread.

This is my code:

  type T_SPB is
    record
      ...
    end record;

  type T_SPB_PTR is access T_SPB;

  SP_Block : T_SPB;
  for SP_Block'Address use System'To_Address(16#80001000#);
  -- Tell the compiler that this record is defined elsewhere.
  -- Stops the compiler from producing a warning.
  pragma Import(Ada, SP_Block);

The compiler still generates that code.

Luke.




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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-03  8:41       ` Luke A. Guest
@ 2004-01-03 11:53         ` Simon Wright
  2004-01-03 12:20           ` Luke A. Guest
  0 siblings, 1 reply; 20+ messages in thread
From: Simon Wright @ 2004-01-03 11:53 UTC (permalink / raw)


"Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:

> This is my code:
> 
>   type T_SPB is
>     record
>       ...
>     end record;
> 
>   type T_SPB_PTR is access T_SPB;
> 
>   SP_Block : T_SPB;
>   for SP_Block'Address use System'To_Address(16#80001000#);
>   -- Tell the compiler that this record is defined elsewhere.
>   -- Stops the compiler from producing a warning.
>   pragma Import(Ada, SP_Block);

Not sure whether this will help ..

   with System.Storage_Elements;

   package Luke is

      type P is access Integer;
      pragma Suppress_Initialization (P);

      type R is record
         The_P : P;
      end record;
      pragma Suppress_Initialization (R);

      V : R;
      for V'Address use System.Storage_Elements.To_Address (16#80001000#);
   --     pragma Import (Ada, V);

   end Luke;

I found Suppress_Initialization at
http://gcc.gnu.org/onlinedocs/gnat_rm/Implementation-Defined-Pragmas.html#Implementation%20Defined%20Pragmas
but I don't know whether it is officially supported by ACT for the
future (I tried it with 3.15p and 5.01a, the latter is closer to the
GCC version).

The key was to apply the pragma to type P.

I've managed to get myself confused about which combination of
options/compiler produced which effect, but I get the impression that
there is a difference between 3.15p and 5.01a here ..

I'm not familiar with System'To_Address .. neater than the
Storage_Elements version, but more difficult to grep for in the
source!

-- 
Simon Wright                               100% Ada, no bugs.



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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-03 11:53         ` Simon Wright
@ 2004-01-03 12:20           ` Luke A. Guest
  2004-01-04 12:26             ` Simon Wright
  0 siblings, 1 reply; 20+ messages in thread
From: Luke A. Guest @ 2004-01-03 12:20 UTC (permalink / raw)


On Sat, 03 Jan 2004 11:53:03 +0000, Simon Wright wrote:

> I found Suppress_Initialization at
> http://gcc.gnu.org/onlinedocs/gnat_rm/Implementation-Defined-Pragmas.html#Implementation%20Defined%20Pragmas
> but I don't know whether it is officially supported by ACT for the
> future (I tried it with 3.15p and 5.01a, the latter is closer to the
> GCC version).

As for support from ACT, I'm even sure if they'll give any kind of support
unless you pay for it. You'd think that a minimum level of support would
do?? Considering the email I got from Robert Dewar, I'm not too sure that
an OS built with GNAT would be too portable across different versions
either, which is bad in itself.
 
> The key was to apply the pragma to type P.

Genius! That does indeed work. Thanks for that one. I just need to be
careful of what I apply it to. I suppose for this kind of work, it could
possible be applied to all record types. I'll have to play and see.

> I've managed to get myself confused about which combination of
> options/compiler produced which effect, but I get the impression that
> there is a difference between 3.15p and 5.01a here ..
> 
> I'm not familiar with System'To_Address .. neater than the
> Storage_Elements version, but more difficult to grep for in the
> source!

Well, the difference is that System.Storage_Elements.To_Address is a
function call and System'To_Address isn't. So with the latter, you get a
nice static initialisation, which is what is really required in this case.

As for grepping, this works for me: grep -r System\'To\_Address *

Thanks,
Luke.





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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-03 11:32   ` Luke A. Guest
@ 2004-01-03 13:11     ` Florian Weimer
  0 siblings, 0 replies; 20+ messages in thread
From: Florian Weimer @ 2004-01-03 13:11 UTC (permalink / raw)


"Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:

> >> 2) I have set up my SP_Block record instance to be located at a particular
> >> memory address, yet the compiler still generates code to initialise this
> >> structure.
> > 
> > pragma Import with convention Ada (or C) should help.

> The compiler still generates that code.

This looks like a bug in the FSF version of GNAT.



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

* Re: [No_Elaboration_Code] GNAT still generating rep_to_pos, why?
  2004-01-03 12:20           ` Luke A. Guest
@ 2004-01-04 12:26             ` Simon Wright
  0 siblings, 0 replies; 20+ messages in thread
From: Simon Wright @ 2004-01-04 12:26 UTC (permalink / raw)


"Luke A. Guest" <laguest@n_o_p_o_r_k_a_n_d_h_a_m.abyss2.demon.co.uk> writes:

> > I'm not familiar with System'To_Address .. neater than the
> > Storage_Elements version, but more difficult to grep for in the
> > source!
> 
> Well, the difference is that System.Storage_Elements.To_Address is a
> function call and System'To_Address isn't. So with the latter, you
> get a nice static initialisation, which is what is really required
> in this case.

This is a GNAT attribute, I see.

   The System'To_Address (System is the only permissible prefix)
   denotes a function identical to System.Storage_Elements.To_Address
   except that it is a static attribute. This means that if its
   argument is a static expression, then the result of the attribute
   is a static expression. The result is that such an expression can
   be used in contexts (e.g. preelaborable packages) which require a
   static expression and where the function call could not be used
   (since the function call is always non-static, even if its argument
   is static).

> As for grepping, this works for me: grep -r System\'To\_Address *

No, I meant that you can't grep system.ads, so if you are thinking to
yourself "I know there's a To_Address function somewhere ..." you have
a long search ahead of you!

-- 
Simon Wright                               100% Ada, no bugs.



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

end of thread, other threads:[~2004-01-04 12:26 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-02 11:59 [No_Elaboration_Code] GNAT still generating rep_to_pos, why? Luke A. Guest
2004-01-02 17:51 ` Stephen Leake
2004-01-02 18:14   ` Luke A. Guest
2004-01-02 19:31     ` Per Sandberg
2004-01-02 19:46       ` Luke A. Guest
2004-01-02 21:17     ` Stephen Leake
2004-01-02 22:16       ` Luke A. Guest
2004-01-03  1:43         ` Stephen Leake
     [not found]         ` <87ekuhe5wq.fsf@news.sdbk.de>
2004-01-03  9:58           ` Luke A. Guest
2004-01-03  8:44       ` Luke A. Guest
2004-01-03  1:12     ` Robert I. Eachus
2004-01-03  8:41       ` Luke A. Guest
2004-01-03 11:53         ` Simon Wright
2004-01-03 12:20           ` Luke A. Guest
2004-01-04 12:26             ` Simon Wright
2004-01-03  1:41 ` sk
2004-01-03  2:29   ` Luke A. Guest
2004-01-03 10:48 ` Florian Weimer
2004-01-03 11:32   ` Luke A. Guest
2004-01-03 13:11     ` Florian Weimer

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