<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 27, 2015 at 1:05 PM, Rodney M. Bates <span dir="ltr"><<a href="mailto:rodney_bates@lcwb.coop" target="_blank">rodney_bates@lcwb.coop</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
<br>
On 07/27/2015 10:59 AM, Rodney M. Bates wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
On 07/25/2015 08:57 PM, Andrew Wilkins wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sun, 26 Jul 2015 at 06:48 Rodney M. Bates <<a href="mailto:rodney_bates@lcwb.coop" target="_blank">rodney_bates@lcwb.coop</a> <mailto:<a href="mailto:rodney_bates@lcwb.coop" target="_blank">rodney_bates@lcwb.coop</a>>> wrote:<br>
<br>
    In trying to write a C binding for DIBuilder of llvm 3.6.1, I can't see a way to unwrap<br>
    llvm::DITypeRef, declared in include/llvm/IR/DebugInfo.h.  This is a class with one<br>
    data member, a pointer to Metadata.<br>
<br>
    If I try to make my C type a struct with one pointer, I can't cast it to DITypeRef.<br>
    If I try to go inside the classes and use the pointer, I can cast, but can't construct<br>
    a DITypeRef when unwrapping, as both its pointer field 'Val' and the constructor are<br>
    private.<br>
<br>
<br>
I don't know if I'm understanding the problem exactly, so I'll just point you to what the Go bindings are doing.<br>
<br>
First, define wrap/unwrap for llvm::Metadata (of which DIType is a descendant):<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_klaus_llvm_blob_master_bindings_go_llvm_IRBindings.h-23L-2D63&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=v50zQxK2tPjt9d0PU8BGXVfQ3v79dVWRfcT-Zc1_9o8&s=vkkPcdkWF12TYN8DTszM09u5QEHOFrMjPA39pfM9HRE&e=" rel="noreferrer" target="_blank">http://llvm.org/klaus/llvm/blob/master/bindings/go/llvm/IRBindings.h#L-63</a><br>
<br>
Then use wrapped llvm::Metadata in the C API:<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_klaus_llvm_blob_master_bindings_go_llvm_DIBuilderBindings.h&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=v50zQxK2tPjt9d0PU8BGXVfQ3v79dVWRfcT-Zc1_9o8&s=8Wu6sb6WbEro42ShUNeULvISPkek06zv1h-m5V2qpww&e=" rel="noreferrer" target="_blank">http://llvm.org/klaus/llvm/blob/master/bindings/go/llvm/DIBuilderBindings.h</a><br>
<br>
(You could have DIType-specific wrap/unwrap too, using the same method.)<br>
<br>
</blockquote>
<br>
My problem is not DIType, it's DITypeRef.  This was added sometime after 3.4.2 and<br>
by 3.6.1.  It is used, e.g. for formal parameter Ty of DIBuilder::createLocalVariable.<br>
These Go bindings apparently have not been updated to 3.6.1, as they give DIType in<br>
such places.<br>
<br>
However, in looking more carefully at DIType, with the intention of being able to better<br>
explain why DITypeRef gives me a problem that DIType does not, I find the way I need<br>
to construct a DITypeRef is actually declared in DIType:<br>
<br>
<br>
class DIType : public DIScope {<br>
  ...<br>
  public:<br>
   ...<br>
   operator DITypeRef () const {<br>
   ^^^^^^^^^^^^^^^^^^<br>
     assert(isType() &&<br>
            "constructing DITypeRef from an MDNode that is not a type");<br>
     return DITypeRef(&*getRef());<br>
   }<br>
<br>
This, through a series of specializations, befriendings, etc., is able to<br>
get to the private constructor of DITypeRef.<br>
<br>
This should help solve my problem, once I figure out how to construct a<br>
properly equivalent DIType.<br>
<br>
</blockquote>
<br></div></div>
I was mistaken.  This does not solve my problem.  The implicit conversion<br>
operator DITypeRef converts from a DIType, which can contain only an MDNode*,<br>
but I need to construct a DITypeRef, which can contain a Metadata*.  The<br>
constructor I need is here:<br>
<br>
template <typename T> class DIRef {<br>
  template <typename DescTy><br>
  friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;<br>
  friend DIScopeRef DIScope::getContext() const;<br>
  friend DIScopeRef DIScope::getRef() const;<br>
  friend class DIType;<br>
<br>
  /// \brief Val can be either a MDNode or a MDString.<br>
  ///<br>
  /// In the latter, MDString specifies the type identifier.<br>
  const Metadata *Val;<br>
  explicit DIRef(const Metadata *V);<br>
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
<br>
but it is private.  I am trying very hard to avoid in-llvm-tree modifications<br>
(we've been down that path with a gcc-derived back end.)  Do I have any alternative?<br>
Would the project accept making this constructor public?</blockquote><div><br></div><div>Have you found where it's called from yet? (perhaps by putting an "assert(false)" or defining it as deleted ("= delete") and recompiling/running tests) Then see about using the same mechanism for your use case?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
HTH,<br>
Andrew<br>
</blockquote>
<br>
</blockquote>
<br>
-- <br>
Rodney Bates<br>
<a href="mailto:rodney.m.bates@acm.org" target="_blank">rodney.m.bates@acm.org</a><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div></div>