[LLVMdev] [un]wrapping llvm:DITypeRef

Andrew Wilkins
Sun, 26 Jul 2015 01:57:23 -0000

On Sun, 26 Jul 2015 at 06:48 Rodney M. Bates <rodney_bates at lcwb.coop>
wrote:

> In trying to write a C binding for DIBuilder of llvm 3.6.1, I can't see
a
> way to unwrap
> llvm::DITypeRef, declared in include/llvm/IR/DebugInfo.h.  This is a class
> with one
> data member, a pointer to Metadata.
>
> If I try to make my C type a struct with one pointer, I can't cast it
to
> DITypeRef.
> If I try to go inside the classes and use the pointer, I can cast, but
> can't construct
> a DITypeRef when unwrapping, as both its pointer field 'Val' and
the
> constructor are
> private.
>

I don't know if I'm understanding the problem exactly, so I'll just
point
you to what the Go bindings are doing.

First, define wrap/unwrap for llvm::Metadata (of which DIType is a
descendant):

http://llvm.org/klaus/llvm/blob/master/bindings/go/llvm/IRBindings.h#L-63

Then use wrapped llvm::Metadata in the C API:

http://llvm.org/klaus/llvm/blob/master/bindings/go/llvm/DIBuilderBindings.h

(You could have DIType-specific wrap/unwrap too, using the same method.)

HTH,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20150726/2b53a0c4/attachment.html>