www.digitalmars.com         C & C++   DMDScript  

D - Modifying the dmd compiler to add support for bitfields

reply Sandeep Datta <datta.sandeep gmail.com> writes:
Hi All,

To gain a better understanding of how the D compiler works I am
trying to implement support for bit fields in structures. I have
modified the parser code to admit the following syntax (for now)...

struct A{
    uint:8 a;
    uint:5 b;
    uint:* unused; //Takes up the remaining space.
    //Raise an error when the computed size is zero.
}

You can see my changes here...https://github.com/SDX2000/dmd

I have been trying to work out a strategy for modifying the compiler
code generation for quite some time now but haven't been able to
make much headway in this direction.

I would appreciate any help at this point.

Regards,
Sandeep Datta.
Jan 07 2012
parent reply "Mike James" <foo bar.com> writes:
"Sandeep Datta"  wrote in message news:jebbof$1nkb$1 digitalmars.com...

Hi All,

To gain a better understanding of how the D compiler works I am
trying to implement support for bit fields in structures. I have
modified the parser code to admit the following syntax (for now)...

struct A{
    uint:8 a;
    uint:5 b;
    uint:* unused; //Takes up the remaining space.
    //Raise an error when the computed size is zero.
}

You can see my changes here...https://github.com/SDX2000/dmd

I have been trying to work out a strategy for modifying the compiler
code generation for quite some time now but haven't been able to
make much headway in this direction.

I would appreciate any help at this point.

Regards,
Sandeep Datta.

What about also allowing definition of bitsize and position in the integer, 
for want of a better syntax:

struct A {
    uint:<0..7> a;
    uint:<8..12> b;
    uint:<13> errorFlag; // single bit allocation
}

Regards,
<mike> 
Jan 08 2012
parent Sandeep Datta <datta.sandeep gmail.com> writes:
I think that is a good idea but I would prefer dropping the angle
brackets altogether...

struct A {
    uint:0..7 a;
    uint:8..12 b;
    uint:13 errorFlag; // single bit allocation
}
Jan 08 2012