llvm.org GIT mirror llvm / f7af931
Expose LLVMSetOperand and LLVMGetNumOperands to llvm-c and ocaml. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111625 91177308-0d34-0410-b5e6-96231b3b80d8 Erick Tryzelaar 10 years ago
6 changed file(s) with 38 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
279279
280280 (*--... Operations on users ................................................--*)
281281 external operand : llvalue -> int -> llvalue = "llvm_operand"
282 external set_operand : llvalue -> int -> llvalue -> unit = "llvm_set_operand"
283 external num_operands : llvalue -> int = "llvm_num_operands"
282284
283285 (*--... Operations on constants of (mostly) any type .......................--*)
284286 external is_constant : llvalue -> bool = "llvm_is_constant"
556556 method [llvm::User::getOperand]. *)
557557 external operand : llvalue -> int -> llvalue = "llvm_operand"
558558
559 (** [set_operand v i o] sets the operand of the value [v] at the index [i] to
560 the value [o].
561 See the method [llvm::User::setOperand]. *)
562 external set_operand : llvalue -> int -> llvalue -> unit = "llvm_set_operand"
563
564 (** [num_operands v] returns the number of operands for the value [v].
565 See the method [llvm::User::getNumOperands]. *)
566 external num_operands : llvalue -> int = "llvm_num_operands"
559567
560568 (** {7 Operations on constants of (mostly) any type} *)
561569
451451 return LLVMGetOperand(V, Int_val(I));
452452 }
453453
454 /* llvalue -> int -> llvalue -> unit */
455 CAMLprim value llvm_set_operand(LLVMValueRef U, value I, LLVMValueRef V) {
456 LLVMSetOperand(U, Int_val(I), V);
457 return Val_unit;
458 }
459
460 /* llvalue -> int */
461 CAMLprim value llvm_num_operands(LLVMValueRef V) {
462 return Val_int(LLVMGetNumOperands(V));
463 }
464
454465 /*--... Operations on constants of (mostly) any type .......................--*/
455466
456467 /* llvalue -> bool */
522522
523523 /* Operations on Users */
524524 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
525 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
526 int LLVMGetNumOperands(LLVMValueRef Val);
525527
526528 /* Operations on constants of any type */
527529 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
486486 /*--.. Operations on Users .................................................--*/
487487 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
488488 return wrap(unwrap(Val)->getOperand(Index));
489 }
490
491 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
492 unwrap(Val)->setOperand(Index, unwrap(Op));
493 }
494
495 int LLVMGetNumOperands(LLVMValueRef Val) {
496 return unwrap(Val)->getNumOperands();
489497 }
490498
491499 /*--.. Operations on constants of any type .................................--*/
641641
642642 let p1 = param fn 0 in
643643 let p2 = param fn 1 in
644 let a3 = build_alloca i32_type "user_alloca" b in
645 let p3 = build_load a3 "user_load" b in
644646 let i = build_add p1 p2 "sum" b in
645647
648 insist ((num_operands i) = 2);
646649 insist ((operand i 0) = p1);
647650 insist ((operand i 1) = p2);
651
652 set_operand i 1 p3;
653 insist ((operand i 1) != p2);
654 insist ((operand i 1) = p3);
648655
649656 ignore (build_unreachable b)
650657