[LLVMdev] Adding fields in a already built type?
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:
>> 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:
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);
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?)
More information about the llvm-dev