<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sun, 26 Jul 2015 at 06:48 Rodney M. Bates <<a href="mailto:rodney_bates@lcwb.coop">rodney_bates@lcwb.coop</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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></blockquote><div><br></div><div>I don't know if I'm understanding the problem exactly, so I'll just point you to what the Go bindings are doing.</div><div><br></div><div>First, define wrap/unwrap for llvm::Metadata (of which DIType is a descendant):</div><div>    <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=3nne51LGwDyxcw9RmuxfNLZLyP0Ut3lYKKz-XOlO9e4&s=3v6MyRJ-H9Gd951t2Ew1UANjFNFEaQAiPnz6t1ndxHs&e=">http://llvm.org/klaus/llvm/blob/master/bindings/go/llvm/IRBindings.h#L-63</a></div><div><br></div><div>Then use wrapped llvm::Metadata in the C API:</div><div>    <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=3nne51LGwDyxcw9RmuxfNLZLyP0Ut3lYKKz-XOlO9e4&s=TPo0Q6M_vegjION2iGgzwY640nIFzkRHzWGb7mXet7I&e=">http://llvm.org/klaus/llvm/blob/master/bindings/go/llvm/DIBuilderBindings.h</a></div><div><br></div><div>(You could have DIType-specific wrap/unwrap too, using the same method.)<br></div><div><br></div><div>HTH,</div><div>Andrew</div></div></div>