Hello everybody,
I started working on the GCC CLI back end just a few weeks ago and I'm having
some trouble declaring new fields and adding them to an already existing
structure. I'm still fairly unfamiliar with gcc's code so please bear with me :)
Since CLI doesn't support bit-fields I am trying to turn COMPONENT_REF
statements working on bit-fields into statements working on artificial fields
overlapping the bit-fields plus the necessary shift & mask operations so as to
simplify CLI emission later.
I'm currently somewhat uncertain on how to add my new artificial fields to a
structure (or union). I've looked through the code and ended up with this code
which builds a new field ('type' is the struct or union, 'fld_type' and
'fld_offset' the appropriate type and offset for the new field):
tree fld = build_decl (FIELD_DECL, NULL_TREE, fld_type);
DECL_FIELD_CONTEXT (fld) = type;
TREE_INT_CST (DECL_FIELD_OFFSET (fld)) = fld_offset;
TREE_INT_CST (DECL_FIELD_BIT_OFFSET (fld)) = double_int_zero;
DECL_ARTIFICIAL (fld) = 1;
Is this correct or did I miss something when initializing the new field? Do I
have to set the alignment with SET_DECL_OFFSET_ALIGN() or is it not needed?
Finally can I simply add the new fields the list obtained with TYPE_FIELDS() or
do I have to insert them in a specific order?