[LLVMdev] Recursive Types using the llvm support library

Chris Lattner sabre at nondot.org
Mon Mar 7 20:51:30 PST 2005

On Mon, 7 Mar 2005, John Carrino wrote:
> As far as I can tell, when you construct a type using the support
> library StructType::get, you have to pass in a list of types.  How can
> you make a Recursive type by passing in a pointer to the type you are
> constucting.
> An example where something really simple like the line below was output
> would be perfect.
> %struct.linked_list = type { %struct.linked_list*, %sbyte* }

Use something like this:

   PATypeHolder StructTy = OpaqueType::get();
   std::vector<const Type*> Elts;
   StructType *NewSTy = StructType::get(Elts);

   // At this point, NewSTy = "{ opaque*, sbyte* }", tell VMCore that
   // the struct and the opaque type are actually the same.

   // NewSTy is potentially invalidated, but StructTy (a PATypeHolder) is
   // kept up-to-date.
   NewSTy = StructTy.get();



More information about the llvm-dev mailing list