[LLVMdev] Adding fields in a already built type?

Stéphane Letz letz at grame.fr
Mon Jun 14 14:15:44 PDT 2010

Le 14 juin 2010 à 22:32, Chris Lattner a écrit :

> On Jun 14, 2010, at 1:22 PM, Stéphane Letz wrote:
>> Hi,
>> We build a type with StructType::get(fModule->getContext(), fDspFields, false); with a fDspFields  (std::vector<const llvm::Type*> fDspFields;)  that is not yet completely known when we have to build the type. It is possible to add fields in a already build type? 
> Nope, types are immutable once created.  The only thing you can do is "refine" opaque types to other types.  There is a section in the programmer's manual on this:
> http://llvm.org/docs/ProgrammersManual.html#TypeResolve
> -Chris


So I was doing (with this still uncomplete fDspFields vector) :

fStruct_Llvm_dsp = StructType::get(fModule->getContext(), fDspFields, false);
fStruct_Llvm_dsp_ptr = PointerType::get(fStruct_Llvm_dsp, 0);
fModule->addTypeName("struct.llvm_dsp", fStruct_Llvm_dsp);
No I'm trying to use:

 PATypeHolder fStruct_Llvm_dsp_tmp = OpaqueType::get(fModule->getContext());
 fStruct_Llvm_dsp_ptr = PointerType::get(fStruct_Llvm_dsp_tmp.get(), 0);
hoping I can safely use fStruct_Llvm_dsp_ptr in code that need it, and finish the type creation when fDspFields is completely filled with "refineAbstractTypeTo"

but this doe not work.

I'll still not clear if this  "fStruct_Llvm_dsp_ptr" can be used. Should I use this "AbstractTypeUser" class ?  (but thing seems to become tricky if a lot of code using the "fStruct_Llvm_dsp_ptr" has to be updated?)


Stéphane Letz

More information about the llvm-dev mailing list