[LLVMdev] code generation order revisited.

Hendrik Boom hendrik at topoi.pooq.com
Thu Jun 12 19:19:25 PDT 2008


On Thu, 12 Jun 2008 16:05:19 -0400, Gordon Henriksen wrote:

> 
> Partially opaque types can be refined. This section of the programmer's
> manual is applicable:
> 
> http://llvm.org/docs/ProgrammersManual.html#BuildRecType
> 
> — Gordon

Here it is:

: // Create the initial outer struct
: PATypeHolder StructTy = OpaqueType::get();
: std::vector<const Type*> Elts;
: Elts.push_back(PointerType::get(StructTy));
: Elts.push_back(Type::Int32Ty);
: StructType *NewSTy = StructType::get(Elts);

Here NewSTy is a pointer to StructType.

: // At this point, NewSTy = "{ opaque*, i32 }". 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 = cast<StructType>(StructTy.get());

At first I couldn't see the purpose of this statement, because presumably 
NewSTy is already that StructType.  But then I noticed that here we are 
assigning a StructType to a variable that is pointer-to-StructType 
instead.  So I don't even know what I should be wondering about.

: // Add a name for the type to the module symbol table (optional)
: MyModule->addTypeName("mylist", NewSTy);

-- hendrik




More information about the llvm-dev mailing list