John Carrino
2005-Mar-08 02:20 UTC
[LLVMdev] Recursive Types using the llvm support library
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* } Thanks for any help, John
Chris Lattner
2005-Mar-08 04:51 UTC
[LLVMdev] Recursive Types using the llvm support library
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; Elts.push_back(PointerType::get(StructTy)); Elts.push_back(PointerType::get(Type::SByteTy)); StructType *NewSTy = StructType::get(Elts); // At this point, NewSTy = "{ opaque*, sbyte* }", tell VMCore that // the struct and the opaque type are actually the same. cast<OpaqueType>(StructTy.get())->refineAbstractTypeTo(NewSTy); // NewSTy is potentially invalidated, but StructTy (a PATypeHolder) is // kept up-to-date. NewSTy = StructTy.get(); -Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/
John Carrino
2005-Mar-08 05:44 UTC
[LLVMdev] Recursive Types using the llvm support library
On Mon, Mar 07, 2005 at 10:51:30PM -0600, Chris Lattner wrote:> 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; > Elts.push_back(PointerType::get(StructTy)); > Elts.push_back(PointerType::get(Type::SByteTy)); > StructType *NewSTy = StructType::get(Elts); > > // At this point, NewSTy = "{ opaque*, sbyte* }", tell VMCore that > // the struct and the opaque type are actually the same. > cast<OpaqueType>(StructTy.get())->refineAbstractTypeTo(NewSTy); > > // NewSTy is potentially invalidated, but StructTy (a PATypeHolder) is > // kept up-to-date. > NewSTy = StructTy.get();Thanks much, Chris.
Vladimir Merzliakov
2005-Mar-08 14:09 UTC
[LLVMdev] Recursive Types using the llvm support library
>> 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; > Elts.push_back(PointerType::get(StructTy)); > Elts.push_back(PointerType::get(Type::SByteTy)); > StructType *NewSTy = StructType::get(Elts); > > // At this point, NewSTy = "{ opaque*, sbyte* }", tell VMCore that > // the struct and the opaque type are actually the same. > cast<OpaqueType>(StructTy.get())->refineAbstractTypeTo(NewSTy); > > // NewSTy is potentially invalidated, but StructTy (a PATypeHolder) is > // kept up-to-date. > NewSTy = StructTy.get(); >Is assert(!NewSTy->isAbstract()) must pass after this line? Vladimir
Apparently Analagous Threads
- [LLVMdev] Recursive Types using the llvm support library
- [LLVMdev] Recursive Types using the llvm support library
- [LLVMdev] Recursive Types using the llvm support library
- [LLVMdev] Dynamic Creation of a simple program
- [LLVMdev] Recursive Types using the llvm support library