llvm.org GIT mirror llvm / 4f661ab
ocaml/C bindings: getmdstring, add num_op, get_op should work on metadata too git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141286 91177308-0d34-0410-b5e6-96231b3b80d8 Torok Edwin 7 years ago
5 changed file(s) with 76 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
280280 (*--... Operations on metadata .......,.....................................--*)
281281 external mdstring : llcontext -> string -> llvalue = "llvm_mdstring"
282282 external mdnode : llcontext -> llvalue array -> llvalue = "llvm_mdnode"
283 external get_mdstring : llvalue -> string option = "llvm_get_mdstring"
284 external get_named_metadata : llmodule -> string -> llvalue array = "llvm_get_namedmd"
283285
284286 (*--... Operations on scalar constants .....................................--*)
285287 external const_int : lltype -> int -> llvalue = "llvm_const_int"
570570 See the method [llvm::MDNode::get]. *)
571571 val mdnode : llcontext -> llvalue array -> llvalue
572572
573 (** [get_mdstring v] returns the MDString.
574 * See the method [llvm::MDString::getString] *)
575 val get_mdstring : llvalue -> string option
576
577 (** [get_named_metadata m name] return all the MDNodes belonging to the named
578 * metadata (if any).
579 * See the method [llvm::NamedMDNode::getOperand]. *)
580 val get_named_metadata : llmodule -> string -> llvalue array
573581
574582 (** {7 Operations on scalar constants} *)
575583
2323 #include "llvm/Config/config.h"
2424 #include
2525 #include
26 #include
2627
2728
2829 /* Can't use the recommended caml_named_value mechanism for backwards
467468 Wosize_val(ElementVals));
468469 }
469470
471 /* llvalue -> string option */
472 CAMLprim value llvm_get_mdstring(LLVMValueRef V) {
473 CAMLparam0();
474 const char *S;
475 unsigned Len;
476
477 if ((S = LLVMGetMDString(V, &Len))) {
478 CAMLlocal2(Option, Str);
479
480 Str = caml_alloc_string(Len);
481 memcpy(String_val(Str), S, Len);
482 Option = alloc(1,0);
483 Store_field(Option, 0, Str);
484 CAMLreturn(Option);
485 }
486 CAMLreturn(Val_int(0));
487 }
488
489 CAMLprim value llvm_get_namedmd(LLVMModuleRef M, value name)
490 {
491 CAMLparam1(name);
492 CAMLlocal1(Nodes);
493 Nodes = alloc(LLVMGetNamedMetadataNumOperands(M, String_val(name)), 0);
494 LLVMGetNamedMetadataOperands(M, String_val(name), (LLVMValueRef *) Nodes);
495 CAMLreturn(Nodes);
496 }
470497 /*--... Operations on scalar constants .....................................--*/
471498
472499 /* lltype -> int -> llvalue */
549549 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
550550 unsigned Count);
551551 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count);
552 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len);
553 int LLVMGetMDNodeNumOperands(LLVMValueRef V);
554 LLVMValueRef *LLVMGetMDNodeOperand(LLVMValueRef V, unsigned i);
555 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name);
556 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest);
552557
553558 /* Operations on scalar constants */
554559 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
455455
456456 /*--.. Operations on Users .................................................--*/
457457 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
458 return wrap(unwrap(Val)->getOperand(Index));
458 Value *V = unwrap(Val);
459 if (MDNode *MD = dyn_cast(V))
460 return wrap(MD->getOperand(Index));
461 return wrap(cast(V)->getOperand(Index));
459462 }
460463
461464 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
463466 }
464467
465468 int LLVMGetNumOperands(LLVMValueRef Val) {
466 return unwrap(Val)->getNumOperands();
469 Value *V = unwrap(Val);
470 if (MDNode *MD = dyn_cast(V))
471 return MD->getNumOperands();
472 return cast(V)->getNumOperands();
467473 }
468474
469475 /*--.. Operations on constants of any type .................................--*/
518524
519525 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
520526 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
527 }
528
529 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len) {
530 if (const MDString *S = dyn_cast(unwrap(V))) {
531 *Len = S->getString().size();
532 return S->getString().data();
533 }
534 *Len = 0;
535 return 0;
536 }
537
538 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name)
539 {
540 if (NamedMDNode *N = unwrap(M)->getNamedMetadata(name)) {
541 return N->getNumOperands();
542 }
543 return 0;
544 }
545
546 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest)
547 {
548 NamedMDNode *N = unwrap(M)->getNamedMetadata(name);
549 if (!N)
550 return;
551 for (unsigned i=0;igetNumOperands();i++)
552 Dest[i] = wrap(N->getOperand(i));
521553 }
522554
523555 /*--.. Operations on scalar constants ......................................--*/