diff options
author | Torok Edwin <edwintorok@gmail.com> | 2011-10-06 12:13:11 +0000 |
---|---|---|
committer | Torok Edwin <edwintorok@gmail.com> | 2011-10-06 12:13:11 +0000 |
commit | fec812e1f1642bb59bcee7b211a2c316ea091691 (patch) | |
tree | 6e58ca14b72076c08de149d8551e7908b1c1ad81 /llvm/lib/VMCore/Core.cpp | |
parent | 0d5f6ae881a82cba8f2cdc538937dbd58a3c0375 (diff) | |
download | bcm5719-llvm-fec812e1f1642bb59bcee7b211a2c316ea091691.tar.gz bcm5719-llvm-fec812e1f1642bb59bcee7b211a2c316ea091691.zip |
ocaml/C bindings: getmdstring, add num_op, get_op should work on metadata too
llvm-svn: 141286
Diffstat (limited to 'llvm/lib/VMCore/Core.cpp')
-rw-r--r-- | llvm/lib/VMCore/Core.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/llvm/lib/VMCore/Core.cpp b/llvm/lib/VMCore/Core.cpp index 8560de4455c..a21ec7a3f3e 100644 --- a/llvm/lib/VMCore/Core.cpp +++ b/llvm/lib/VMCore/Core.cpp @@ -456,7 +456,10 @@ LLVMValueRef LLVMGetUsedValue(LLVMUseRef U) { /*--.. Operations on Users .................................................--*/ LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) { - return wrap(unwrap<User>(Val)->getOperand(Index)); + Value *V = unwrap(Val); + if (MDNode *MD = dyn_cast<MDNode>(V)) + return wrap(MD->getOperand(Index)); + return wrap(cast<User>(V)->getOperand(Index)); } void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) { @@ -464,7 +467,10 @@ void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) { } int LLVMGetNumOperands(LLVMValueRef Val) { - return unwrap<User>(Val)->getNumOperands(); + Value *V = unwrap(Val); + if (MDNode *MD = dyn_cast<MDNode>(V)) + return MD->getNumOperands(); + return cast<User>(V)->getNumOperands(); } /*--.. Operations on constants of any type .................................--*/ @@ -521,6 +527,32 @@ LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) { return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count); } +const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len) { + if (const MDString *S = dyn_cast<MDString>(unwrap(V))) { + *Len = S->getString().size(); + return S->getString().data(); + } + *Len = 0; + return 0; +} + +unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name) +{ + if (NamedMDNode *N = unwrap(M)->getNamedMetadata(name)) { + return N->getNumOperands(); + } + return 0; +} + +void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest) +{ + NamedMDNode *N = unwrap(M)->getNamedMetadata(name); + if (!N) + return; + for (unsigned i=0;i<N->getNumOperands();i++) + Dest[i] = wrap(N->getOperand(i)); +} + /*--.. Operations on scalar constants ......................................--*/ LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, |