gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] translating C bit fields


From: Fischlin Andreas
Subject: Re: [Gm2] translating C bit fields
Date: Thu, 24 Nov 2011 07:26:58 +0000

I suggest reserved word PACKED in a construct such as PACKED SET or the 
solution of P1 PACKEDSET 
(http://www.awiedemann.de/compiler/manual/comp2.html#L2_3_3).

Regards,
Andreas


NOTE: I have a new mobile number!

ETH Zurich
Prof. Dr. Andreas Fischlin
Systems Ecology - Institute of Integrative Biology
CHN E 21.1
Universitaetstrasse 16
8092 Zurich
SWITZERLAND

address@hidden<mailto:address@hidden>
www.sysecol.ethz.ch<http://www.sysecol.ethz.ch>

+41 44 633-6090 phone
+41 44 633-1136 fax
+41 79 595-4050 mobile

             Make it as simple as possible, but distrust it!
________________________________________________________________________






On 23/11/2011, at 23:29 , Dragiša Durić wrote:

Good thinking..

We need to have syntax for packing,
and also a way to control byte boundaries (MOD 0, MOD 2, MOD 4, MOD 8) of 
fields and whole record.
I don't see MOD even-number as needed, but before I met my Gtk2 problem, I 
didn't think MOD 8 can be an issue too.. So, systematize and let it in gm2.

dd

On Nov 23, 2011, at 11:19 PM, SiTex Graphics wrote:

Looks good to me.  Control over byte alignment would be a welcome
addition.  Could there be a shorthand to set the default alignment for
an entire record?  Maybe:

TYPE
 mytype = RECORD MOD 1
    foo : CHAR;
    bar: CARDINAL;
 END;

-Scott


On Wed, Nov 23, 2011 at 1:05 PM, Dragiša Durić 
<address@hidden<mailto:address@hidden>> wrote:
Hi Gaius,

It looks good.I suppose we can also use this to put "ordinary" fields "out of" 
standard alignment ?

RECORD
a: BOOLEAN BY 8;
b: CARDINAL MOD 0 BY 32?
END;

Or..?

dd

On Nov 23, 2011, at 3:29 PM, Gaius Mulley wrote:

Dragiša Durić <address@hidden<mailto:address@hidden>> writes:

Gaius,

IMO - we also need a mechanism to fix a sequence of fields to word boundary.
Obviousy, a field without "BY" will fit to its default alignment position, but
what if we have

type = RECORD
foo: INTEGER BY 2;
bar: CARDINAL BY 4;
butalso: CARDINAL BY 2; (* and we need to have this aligned to some boundary…
*)
END;

Alignment can be pretty complicated these days when on same architecture some
people decide to align 64 bit values to  byte positions divisible by 8… And
other do not. I met such a situation while wrapping Gtk2 to Modula-3… gcc
aligns such values to divisible-by-4 byte positions, while cm3 aligns to
divisible-by-8…

Hi Dragiša,

ok - how about:

type = RECORD
 foo: INTEGER BY 2;
 bar: CARDINAL BY 4;
 butalso: CARDINAL MOD 4 BY 2; (* and we need to have this aligned to some 
boundary *)
END;

so we extend the ebnf to include:

FieldAlignment := [ ByteAlignment | BitAlignment ] =:

BitAlignment := [ 'MOD' ConstExpression ] 'BY' ConstExpression =:

ByteAlignment := "__ATTRIBUTE__" "(" "(" Ident "(" ConstExpression ")" ")" ")"
             =:

where the MOD indicates the byte alignment and BY indicates the bit
length?  MOD 0 indicates packed, MOD 1 the next byte.

regards,
Gaius



_______________________________________________
gm2 mailing list
address@hidden<mailto:address@hidden>
https://lists.nongnu.org/mailman/listinfo/gm2


_______________________________________________
gm2 mailing list
address@hidden<mailto:address@hidden>
https://lists.nongnu.org/mailman/listinfo/gm2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]