Expose LLVMSetOperand and LLVMGetNumOperands to llvm-c and ocaml.
authorErick Tryzelaar <idadesub@users.sourceforge.net>
Fri, 20 Aug 2010 14:51:22 +0000 (14:51 +0000)
committerErick Tryzelaar <idadesub@users.sourceforge.net>
Fri, 20 Aug 2010 14:51:22 +0000 (14:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111625 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/ocaml/llvm/llvm.ml
bindings/ocaml/llvm/llvm.mli
bindings/ocaml/llvm/llvm_ocaml.c
include/llvm-c/Core.h
lib/VMCore/Core.cpp
test/Bindings/Ocaml/vmcore.ml

index 7ab6f51efb9f60f7b4792e3d71643cfb87a61e8a..e0c168a2d9d44eaaf4ff5f8cbce0f2fdae94fdc7 100644 (file)
@@ -280,6 +280,8 @@ let fold_right_uses f v init =
 
 (*--... Operations on users ................................................--*)
 external operand : llvalue -> int -> llvalue = "llvm_operand"
+external set_operand : llvalue -> int -> llvalue -> unit = "llvm_set_operand"
+external num_operands : llvalue -> int = "llvm_num_operands"
 
 (*--... Operations on constants of (mostly) any type .......................--*)
 external is_constant : llvalue -> bool = "llvm_is_constant"
index 742265cd3d5c97654447ff8af2bcf9c575d175b1..2f9e83797f0f058f865da3704e6a345bdfae18d4 100644 (file)
@@ -557,6 +557,14 @@ val fold_right_uses : (lluse -> 'a -> 'a) -> llvalue -> 'a -> 'a
     method [llvm::User::getOperand]. *)
 external operand : llvalue -> int -> llvalue = "llvm_operand"
 
+(** [set_operand v i o] sets the operand of the value [v] at the index [i] to
+    the value [o].
+    See the method [llvm::User::setOperand]. *)
+external set_operand : llvalue -> int -> llvalue -> unit = "llvm_set_operand"
+
+(** [num_operands v] returns the number of operands for the value [v].
+    See the method [llvm::User::getNumOperands]. *)
+external num_operands : llvalue -> int = "llvm_num_operands"
 
 (** {7 Operations on constants of (mostly) any type} *)
 
index 2caa3876dc48f6cf4f50d752f63c3798560283d1..d25d2942d147d3568d19c11b20ea027677e3c6b8 100644 (file)
@@ -452,6 +452,17 @@ CAMLprim LLVMValueRef llvm_operand(LLVMValueRef V, value I) {
   return LLVMGetOperand(V, Int_val(I));
 }
 
+/* llvalue -> int -> llvalue -> unit */
+CAMLprim value llvm_set_operand(LLVMValueRef U, value I, LLVMValueRef V) {
+  LLVMSetOperand(U, Int_val(I), V);
+  return Val_unit;
+}
+
+/* llvalue -> int */
+CAMLprim value llvm_num_operands(LLVMValueRef V) {
+  return Val_int(LLVMGetNumOperands(V));
+}
+
 /*--... Operations on constants of (mostly) any type .......................--*/
 
 /* llvalue -> bool */
index 99de9e33987d72aa5485d80f36f6e1350b894906..665dd0447c98a391a43752fbd5c8cdbce06e45bc 100644 (file)
@@ -523,6 +523,8 @@ LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
 
 /* Operations on Users */
 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
+void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val);
+int LLVMGetNumOperands(LLVMValueRef Val);
 
 /* Operations on constants of any type */
 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
index e42a68baff9ce9b8f1109d1a750f9bc1c8d5564c..f458051c31c70950ac55828286ef8a732362edef 100644 (file)
@@ -489,6 +489,14 @@ LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
   return wrap(unwrap<User>(Val)->getOperand(Index));
 }
 
+void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
+  unwrap<User>(Val)->setOperand(Index, unwrap(Op));
+}
+
+int LLVMGetNumOperands(LLVMValueRef Val) {
+  return unwrap<User>(Val)->getNumOperands();
+}
+
 /*--.. Operations on constants of any type .................................--*/
 
 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
index ba8c6962a55aa6169f3d7b07801db1b5bd7ef5e8..2894637e2b8408dd514fa59c843d5c2bf0e8602a 100644 (file)
@@ -642,11 +642,18 @@ let test_users () =
 
   let p1 = param fn 0 in
   let p2 = param fn 1 in
+  let a3 = build_alloca i32_type "user_alloca" b in
+  let p3 = build_load a3 "user_load" b in
   let i = build_add p1 p2 "sum" b in
 
+  insist ((num_operands i) = 2);
   insist ((operand i 0) = p1);
   insist ((operand i 1) = p2);
 
+  set_operand i 1 p3;
+  insist ((operand i 1) != p2);
+  insist ((operand i 1) = p3);
+
   ignore (build_unreachable b)