Reputation: 13036
I want to add debug metadata to my generated llvm IR, which is created via the C API. However, I can't figure out how to create named metadata nodes (such as !llvm.dbg.cu), or even how to create metadata nodes with unique numbers (ie. !0, !1, etc.). Adding metadata operands to instructions looks pretty simple, but I cannot figure out how to create standalone metadata nodes.
Upvotes: 4
Views: 621
Reputation: 7083
As at LLVM 3.0, there is no function exposed in the C API for creating or modifying named metadata. A new function (LLVMAddNamedMetadataOperand) was recently added to the API, after the 3.0 release.
If you're comfortable building LLVM from source, you can get this support from the trunk. See the Getting Started page on how to build LLVM. Otherwise you'll have to wait until LLVM 3.1 is released.
When the function is available, it'll be a simple matter of calling:
LLVMAddNamedMetadataOperand(module, "named_md_name", mdnode);
If there is no named metadata with the name "named_md_name", then one will be created. Otherwise the existing object will be updated.
Upvotes: 4