Adding fields in a already built type?

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?

Thanks

Stéphane Letz

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

Thanks.

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?)

Thanks

Stéphane Letz