Skip to content

Commit

Permalink
Add support for accessing an MDNode's operands via the C binding. Pat…
Browse files Browse the repository at this point in the history
…ch by

Anthony Bryant.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164247 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
CunningBaldrick committed Sep 19, 2012
1 parent 6c9176a commit 4caf528
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,27 @@ LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
*/
const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);

/**
* Obtain the number of operands from an MDNode value.
*
* @param V MDNode to get number of operands from.
* @return Number of operands of the MDNode.
*/
unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V);

/**
* Obtain the given MDNode's operands.
*
* The passed LLVMValueRef pointer should point to enough memory to hold all of
* the operands of the given MDNode (see LLVMGetMDNodeNumOperands) as
* LLVMValueRefs. This memory will be populated with the LLVMValueRefs of the
* MDNode's operands.
*
* @param V MDNode to get the operands from.
* @param Dest Destination array for operands.
*/
void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest);

/**
* @}
*/
Expand Down
13 changes: 13 additions & 0 deletions lib/VMCore/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,19 @@ const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len) {
return 0;
}

unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V)
{
return cast<MDNode>(unwrap(V))->getNumOperands();
}

void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest)
{
const MDNode *N = cast<MDNode>(unwrap(V));
const unsigned numOperands = N->getNumOperands();
for (unsigned i = 0; i < numOperands; i++)
Dest[i] = wrap(N->getOperand(i));
}

unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name)
{
if (NamedMDNode *N = unwrap(M)->getNamedMetadata(name)) {
Expand Down

0 comments on commit 4caf528

Please sign in to comment.