[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] translating C bit fields
From: |
SiTex Graphics |
Subject: |
Re: [Gm2] translating C bit fields |
Date: |
Wed, 23 Nov 2011 14:19:30 -0800 |
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> 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> 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] translating C bit fields, SiTex Graphics, 2011/11/16
- Re: [Gm2] translating C bit fields, Gaius Mulley, 2011/11/19
- Re: [Gm2] translating C bit fields, SiTex Graphics, 2011/11/21
- Re: [Gm2] translating C bit fields, Gaius Mulley, 2011/11/23
- Re: [Gm2] translating C bit fields, Dragiša Durić, 2011/11/23
- Re: [Gm2] translating C bit fields, Gaius Mulley, 2011/11/23
- Re: [Gm2] translating C bit fields, Dragiša Durić, 2011/11/23
- Re: [Gm2] translating C bit fields,
SiTex Graphics <=
- Re: [Gm2] translating C bit fields, Dragiša Durić, 2011/11/23
- Re: [Gm2] translating C bit fields, Fischlin Andreas, 2011/11/24
- Re: [Gm2] translating C bit fields, Gaius Mulley, 2011/11/23