[LLVMdev] Correct way to resolve recursive type information?

James Williams junk at giantblob.com
Wed Jan 6 05:20:13 PST 2010


Hi,

I've followed the instructions on constructing recursive types (
http://llvm.org/docs/ProgrammersManual.html#BuildRecType) and I can
succesfully create simple recursive types using the C bindings (e.g. struct
Test { struct Test *t };). I want to generalize this to get type information
from my language into generated LLVM code. My language allows arbitrary
forward type declarations that I resolve using two passes - first all type
names are entered into the symbol table in turn and then all type structures
are built in turn with references to other types being resolved from the
symbol table.

To make this work with LLVM I plan to:

- in the first type resolution pass, for every structured type in the
compiled source create a type handle referencing an opaque type with
LLVMCreateTypeHandle(LLVMCreateOpaqueType() and store it in the type's
symbol table entry
- in the second type resolution pass, create an LLVM structured type for
every structured type in the program. The element types for any referenced
types will be those types' opaque types
- in a third pass, for every structured type in the program, resolve its
opaque type to its structured type with LLVMRefineType

Will I have a problem with TypeRefs becoming invalid underneath me as I
repeatedly call LLVMRefineType in the third pass? If so how can I construct
a web of mutually recursive types - is there some kind of atomic
LLVMRefineType alternative that can refine the whole lot in one go?

I'd be grateful for any advice,
-- James Williams
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100106/9276e14a/attachment.html>


More information about the llvm-dev mailing list