[LLVMdev] ConstantBuilder proposal
Talin
viridia at gmail.com
Fri Feb 4 14:33:56 PST 2011
On Fri, Feb 4, 2011 at 2:12 PM, Frits van Bommel <fvbommel at gmail.com> wrote:
> If you remove all the 'static's from the member functions, it'd work
> more like IRBuilder.
> It would also allow you to take the LLVMContext& as a constructor
> parameter, so that methods like this:
>
> On Fri, Feb 4, 2011 at 6:57 PM, Talin <viridia at gmail.com> wrote:
> > /// GetStruct - return a constant struct given a context and a vector
> > /// of elements.
> > static Constant *GetStruct(
> > LLVMContext &Context,
> > const std::vector<Constant*> &V,
> > bool Packed = false) {
> > return ConstantStruct::get(Context, V, Packed);
> > }
>
> can remove it from their parameter list. It's probably pretty unlikely
> a given ConstantBuilder instance would be used with multiple
> LLVMContexts.
>
I thought about that - the only issue is that the only methods that need a
context parameter are the ones for building structs, the rest can derive the
context from the arguments. (in fact, you could even get the context for the
struct-building methods from the arguments except in the case where the
struct was empty.)
>
> Making this a class you need an instance of would likely also allow
> typing to be reduced a bit because said instance can be given a
> shorter name than 'ConstantBuilder'. For example: 'cb.GetStruct(...)'
> instead of 'ConstantBuilder::GetStruct(MyContext, ...)'.
>
That would make sense if you were going to keep the builder around for
creating more than one constant with the same instance.
In my own code, I have a StructBuilder class that is specialized for
building structs:
Constant * foo = StructBuilder(context)
.add(ptr)
.addNullPtr(type)
.addInt32(10)
.build();
--
-- Talin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110204/7c29a091/attachment.html>
More information about the llvm-dev
mailing list