On Fri, Feb 4, 2011 at 2:12 PM, Frits van Bommel <span dir="ltr"><<a href="mailto:fvbommel@gmail.com">fvbommel@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

If you remove all the 'static's from the member functions, it'd work<br>
more like IRBuilder.<br>
It would also allow you to take the LLVMContext& as a constructor<br>
parameter, so that methods like this:<br>
<div class="im"><br>
On Fri, Feb 4, 2011 at 6:57 PM, Talin <<a href="mailto:viridia@gmail.com">viridia@gmail.com</a>> wrote:<br>
>   /// GetStruct - return a constant struct given a context and a vector<br>
>   /// of elements.<br>
>   static Constant *GetStruct(<br>
>     LLVMContext &Context,<br>
>     const std::vector<Constant*> &V,<br>
>     bool Packed = false) {<br>
>     return ConstantStruct::get(Context, V, Packed);<br>
>   }<br>
<br>
</div>can remove it from their parameter list. It's probably pretty unlikely<br>
a given ConstantBuilder instance would be used with multiple<br>
LLVMContexts.<br></blockquote><div><br></div><div>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.)</div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Making this a class you need an instance of would likely also allow<br>
typing to be reduced a bit because said instance can be given a<br>
shorter name than 'ConstantBuilder'. For example: 'cb.GetStruct(...)'<br>
instead of 'ConstantBuilder::GetStruct(MyContext, ...)'.<br>
</blockquote></div><div><br></div><div>That would make sense if you were going to keep the builder around for creating more than one constant with the same instance.</div><div><br></div>In my own code, I have a StructBuilder class that is specialized for building structs:<div>

<br></div><div><font class="Apple-style-span" face="'courier new', monospace">   Constant * foo = StructBuilder(context)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">     .add(ptr)</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">     .addNullPtr(type)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">     .addInt32(10)</font></div><div>

<font class="Apple-style-span" face="'courier new', monospace">     .build();</font><br></div><div><br>-- <br>-- Talin<br>
</div>