comp.lang.ada
 help / color / mirror / Atom feed
* Tagged Rep Spec
@ 1999-06-15  0:00 jsanchor
  1999-06-15  0:00 ` Tom Moran
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: jsanchor @ 1999-06-15  0:00 UTC (permalink / raw)


Hi all,

I was wondering. Can a person Rep Spec a tagged record?


Type  Interrupt_Record_Type is tagged
   Record
     watchdog_warning   : boolean;
     utility_clock               : boolean;
     timer1                        :boolean;
     rs232                         :boolean;
     mailbox                      :boolean;
   end record;

for Interrupt_Record_Type use
   record
     watchdog_warning   at 0 range 0..0;
     utility_clock               at 0 range 1..1;
     timer1                        at 0 range 2..2;
     rs232                         at 0 range 3..3;
     mailbox                      at 0 range 4..4;
   end record;

Has anyone done this before? I think there also has to be a tag in the
record.


Thank you in advance.

Jay Sanchorawala


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Tagged Rep Spec
  1999-06-15  0:00 Tagged Rep Spec jsanchor
  1999-06-15  0:00 ` Tom Moran
@ 1999-06-15  0:00 ` Marin David Condic
  1999-06-16  0:00 ` Matthew Heaney
  2 siblings, 0 replies; 7+ messages in thread
From: Marin David Condic @ 1999-06-15  0:00 UTC (permalink / raw)


jsanchor@cs5.dasd.honeywell.com wrote:
> 
> Hi all,
> 
> I was wondering. Can a person Rep Spec a tagged record?
> 
Yes, you can apply a representation clause to a tagged record, but there
are lots of problems with doing so. First, the method of implementing a
tagged record is not specified by the language, so you will see some
variance in how it is done from one compiler to another. Does there have
to be a tag as part of the record structure? If so, where will the tag
be located? How big will it be? So whatever you do, it is going to get
implementation dependent.

In addition, you have no effective means of controlling (or at least
finding out and utilizing) the representation of the tag, so you can't
guarantee where it is going to be when you want to strip out the part of
the record that is really of interest to you. And just in case that
isn't complicated enough, you may find that when you get to the child
records of a tagged record with a representation clause, you may be
limited in placement of their fields. For example, the implementation
may insist on aligning child fields on a longword boundary, effectively
inserting unused space between the parent fields and the child fields.

There may be ways to flog the compiler into submission, but so far, I
have not found any. Tagged records would be a very natural
representation of some of the communication capabilities I work with,
but the inability to *really* control the representation has kept me
from exploiting them much. Maybe the compiler writers can 'splain it up
to me and get my mind right, but I don't see how it is useful to have a
representation clause capability for a type when it doesn't matter what
you ask for because you're going to get what the compiler felt like
giving you anyway. Sort of like a nasty waitress in a diner where no
matter what you order, she is going to bring you eggs over easy and dry
white toast. ;-)

MDC
-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
***To reply, remove "bogon" from the domain name.***

Visit my web page at: http://www.mcondic.com/




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

* Re: Tagged Rep Spec
  1999-06-15  0:00 Tagged Rep Spec jsanchor
@ 1999-06-15  0:00 ` Tom Moran
  1999-06-16  0:00   ` jsanchor
  1999-06-15  0:00 ` Marin David Condic
  1999-06-16  0:00 ` Matthew Heaney
  2 siblings, 1 reply; 7+ messages in thread
From: Tom Moran @ 1999-06-15  0:00 UTC (permalink / raw)


Though some compilers used to have troubles with this, it seems to
work now on the compilers I've tried.  
Tag_Size : constant := 4; -- compiler dependent stuff!
for Interrupt_Record_Type use
   record
     watchdog_warning   at 0+Tag_Size range 0..0;
     utility_clock               at 0+Tag_Size range 1..1;
     timer1                        at 0+Tag_Size range 2..2;
     rs232                         at 0+Tag_Size range 3..3;
     mailbox                      at 0+Tag_Size range 4..4;
   end record;

As MDC points out, it's very compiler dependent and non-portable.
Could you use
  type Inner_Record is ... -- not tagged
  for Inner_Record use ...
 type Interrupt_Record_Type is new ... with record
   Contents : Inner_Record;
end record;
  Usually you need to give rep specs because you are dealing with
external hardward or software that has its own ideas.  Usually such
hardware or software has no idea what a tag might mean, so you really
would rather communicate with it via Inner_Record than via a tagged
record.  If you really need the tag, perhaps you should use Streams
instead.




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

* Re: Tagged Rep Spec
  1999-06-15  0:00 Tagged Rep Spec jsanchor
  1999-06-15  0:00 ` Tom Moran
  1999-06-15  0:00 ` Marin David Condic
@ 1999-06-16  0:00 ` Matthew Heaney
  1999-06-25  0:00   ` Robert Dewar
  2 siblings, 1 reply; 7+ messages in thread
From: Matthew Heaney @ 1999-06-16  0:00 UTC (permalink / raw)


On 15 Jun 1999 14:08, jsanchor@cs5.dasd.honeywell.com wrote:

> I was wondering. Can a person Rep Spec a tagged record?

The correct term is rep "clause."  

Although the RM allows you to specify a rep clause for a tagged type, I
don't see the point, since you don't know 

  1) how big the tag is

  2) if the compiler needs the tag to be placed at a specific offset

  3) if there even is a tag


If you need to transmit this data across an external interface, then use
the streams facility.  That way you won't have to go mucking around with
non-portable, ill-defined rep clauses.

If you don't need type extension for this abstraction, then don't bother
making the type tagged.  Not every type needs to be a tagged type.

 
> Type  Interrupt_Record_Type is tagged
>    Record
>      watchdog_warning   : boolean;
>      utility_clock               : boolean;
>      timer1                        :boolean;
>      rs232                         :boolean;
>      mailbox                      :boolean;
>    end record;
> 
> for Interrupt_Record_Type use
>    record
>      watchdog_warning   at 0 range 0..0;
>      utility_clock               at 0 range 1..1;
>      timer1                        at 0 range 2..2;
>      rs232                         at 0 range 3..3;
>      mailbox                      at 0 range 4..4;
>    end record;


This looks like it doesn't need to be tagged, as it seems low-level.






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

* Re: Tagged Rep Spec
  1999-06-15  0:00 ` Tom Moran
@ 1999-06-16  0:00   ` jsanchor
  0 siblings, 0 replies; 7+ messages in thread
From: jsanchor @ 1999-06-16  0:00 UTC (permalink / raw)




> Could you use
>   type Inner_Record is ... -- not tagged
>   for Inner_Record use ...
>  type Interrupt_Record_Type is new ... with record
>    Contents : Inner_Record;
> end record;

I could use a non tagged type, but I thought a nontagged type were
nonextending. I was thinking that maybe my initial record could be
represented as a rep speced records.  The ones that are constant I
represent and then other projects could add their project specific
contents above the ones that are given.



>   Usually you need to give rep specs because you are dealing with
> external hardward or software that has its own ideas.  Usually such
> hardware or software has no idea what a tag might mean, so you really
> would rather communicate with it via Inner_Record than via a tagged
> record.  If you really need the tag, perhaps you should use Streams
> instead.
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Tagged Rep Spec
  1999-06-16  0:00 ` Matthew Heaney
@ 1999-06-25  0:00   ` Robert Dewar
  1999-06-28  0:00     ` Marin David Condic
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Dewar @ 1999-06-25  0:00 UTC (permalink / raw)


In article <m3btegoyj6.fsf@mheaney.ni.net>,
  Matthew Heaney <matthew_heaney@acm.org> wrote:
> On 15 Jun 1999 14:08, jsanchor@cs5.dasd.honeywell.com wrote:
>
> > I was wondering. Can a person Rep Spec a tagged record?
>
> The correct term is rep "clause."
>
> Although the RM allows you to specify a rep clause for a
tagged type, I
> don't see the point, since you don't know
>
>   1) how big the tag is
>
>   2) if the compiler needs the tag to be placed at a specific
>      offset
>
>   3) if there even is a tag


These are not reasons for not specifying a rep clause, they
are just reminders that the rep clause will likely be
impl dependent, but then MANY rep clauses are impl dependent.

The subset of portable rep clauses required by the RM is a
small subset of the useful rep clauses, and in our experience
real life large programs are full of all kinds of rep clauses
outside the set required by the RM.

For example, consider array packing. The RM requires close
packing only for the cases of 1,2,4,8,16 etc bits. That's
very restrictive. In GNAT we allow close packing for any
component size up to 64 bits. That still may not be enough,
we just got a request from a customer to support close packing
for various sizes (136, 255) up to 256 bits.

In the case of tagged types, the tag in GNAT is a single pointer
sized object at offset 0 in the record. Rep clauses can be
freely used to position the specified fields of the type,
providing that the space for the tag is not stomped on.

There are many useful uses of this capability.

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Tagged Rep Spec
  1999-06-25  0:00   ` Robert Dewar
@ 1999-06-28  0:00     ` Marin David Condic
  0 siblings, 0 replies; 7+ messages in thread
From: Marin David Condic @ 1999-06-28  0:00 UTC (permalink / raw)


Robert Dewar wrote:
> 
> These are not reasons for not specifying a rep clause, they
> are just reminders that the rep clause will likely be
> impl dependent, but then MANY rep clauses are impl dependent.
> 
That's fair enough. If I can always count on the compiler I have (and
its future versions!) putting a 32 bit tag at the front of the record, I
can build useful stuff from there. But it would still be nice if there
were attributes to determine the tag placement (or even if there is a
tag - one might imagine an implementation where there is no tag - or
maybe like arrays, it is "invisible" WRT representation clauses.) 

> In the case of tagged types, the tag in GNAT is a single pointer
> sized object at offset 0 in the record. Rep clauses can be
> freely used to position the specified fields of the type,
> providing that the space for the tag is not stomped on.
> 
Yes, but there is a problem with child types. I don't so much mind if
there is a tag in front of the record if it is consistently applied,
because I can consistently remove it when necessary. However, when child
records are created, they are forced onto longword alignments which
can't seem to be overriden with a rep clause. So if I want to capture
all of my "real" data and bypass "spare" fields allocated by the
compiler, I have no reliable way of doing it. With just the tag, I might
be able to compute ((X'Size / System.Storage_Unit) - 4) the proper
number of raw bytes to move, but without good control of the placement
of all subsequent fields, the rep clause quickly becomes useless. Unless
there is some trick that I'm missing?

MDC
-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
***To reply, remove "bogon" from the domain name.***

Visit my web page at: http://www.mcondic.com/




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

end of thread, other threads:[~1999-06-28  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-15  0:00 Tagged Rep Spec jsanchor
1999-06-15  0:00 ` Tom Moran
1999-06-16  0:00   ` jsanchor
1999-06-15  0:00 ` Marin David Condic
1999-06-16  0:00 ` Matthew Heaney
1999-06-25  0:00   ` Robert Dewar
1999-06-28  0:00     ` Marin David Condic

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