[LLVMdev] Order of fiels and structure usage

Hendrik Boom hendrik at topoi.pooq.com
Sat Sep 13 19:22:09 PDT 2008


On Sat, 13 Sep 2008 11:45:50 -0700, Eli Friedman wrote:

> On Sat, Sep 13, 2008 at 11:09 AM, Hendrik Boom <hendrik at topoi.pooq.com>
> wrote:
>> What I want is to be able to use the fields that have already been
>> defined, even though the type isn't complete yet.  The vector<const
>> Type*> is all I have at that moment, and it isn't a type.  But by the
>> time I have a type it's frozen and I can't add new fields to it.
>>
>> Do I gather that I keep making new types, each slightly larger than the
>> previous ones, cast each pointer to my growing type to the type-of-the-
>> moment, and field-select from it;  then finally complete the type when
>> all is known?  That might just work, if field-allocation is independent
>> of later fields, but it is ugly.
> 
> Field-allocation is guaranteed to be independent of later fields, so the
> casting solution would work.

Thanks for the idea.  I was starting to despair about making the compiler 
as flexible as I wanted it without abandoning llvm.

> 
> It might be slightly cleaner to define the types recursively... for
> example, define a struct as { i32 { float { i32* } } }.  That way, you
> wouldn't have a bunch of partial types floating around.

Just curious -- would struct{struct{i32, i8} i8} take just 6 bytes on the 
usual architectures?

-- hendrik





More information about the llvm-dev mailing list