Add support getting the operands of a User to ocaml.
authorErick Tryzelaar <idadesub@users.sourceforge.net>
Sun, 28 Feb 2010 20:45:03 +0000 (20:45 +0000)
committerErick Tryzelaar <idadesub@users.sourceforge.net>
Sun, 28 Feb 2010 20:45:03 +0000 (20:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97414 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/ocaml/llvm/llvm.ml
bindings/ocaml/llvm/llvm.mli
bindings/ocaml/llvm/llvm_ocaml.c
test/Bindings/Ocaml/vmcore.ml

index 48f649a3cfcbe2410b567b6caa5c083bec6e2b1e..0af8f48fa3bdf42dc8d7f02523ae8648ffc148da 100644 (file)
@@ -242,6 +242,9 @@ external dump_value : llvalue -> unit = "llvm_dump_value"
 external replace_all_uses_with : llvalue -> llvalue -> unit
                                = "LLVMReplaceAllUsesWith"
 
 external replace_all_uses_with : llvalue -> llvalue -> unit
                                = "LLVMReplaceAllUsesWith"
 
+(*--... Operations on users ................................................--*)
+external operand : llvalue -> int -> llvalue = "llvm_operand"
+
 (*--... Operations on constants of (mostly) any type .......................--*)
 external is_constant : llvalue -> bool = "llvm_is_constant"
 external const_null : lltype -> llvalue = "LLVMConstNull"
 (*--... Operations on constants of (mostly) any type .......................--*)
 external is_constant : llvalue -> bool = "llvm_is_constant"
 external const_null : lltype -> llvalue = "LLVMConstNull"
index 3413a646609f2b9c66e2ec77146b7d8cd7ed1f5d..674ec9e9c077215adbc414c4aae6773edc13cf50 100644 (file)
@@ -513,6 +513,13 @@ external replace_all_uses_with : llvalue -> llvalue -> unit
                                = "LLVMReplaceAllUsesWith"
 
 
                                = "LLVMReplaceAllUsesWith"
 
 
+(* {6 Users} *)
+
+(** [operand v i] returns the operand at index [i] for the value [v]. See the
+    method [llvm::User::getOperand]. *)
+external operand : llvalue -> int -> llvalue = "llvm_operand"
+
+
 (** {7 Operations on constants of (mostly) any type} *)
 
 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
 (** {7 Operations on constants of (mostly) any type} *)
 
 (** [is_constant v] returns [true] if the value [v] is a constant, [false]
index 78cf6e436851377cd05e02f8e573e9477a4f1bd5..cdd137e51bc0650b4c590d734864a524366aedac 100644 (file)
@@ -440,6 +440,13 @@ CAMLprim value llvm_dump_value(LLVMValueRef Val) {
   return Val_unit;
 }
 
   return Val_unit;
 }
 
+/*--... Operations on users ................................................--*/
+
+/* llvalue -> int -> llvalue */
+CAMLprim LLVMValueRef llvm_operand(LLVMValueRef V, value I) {
+  return LLVMGetOperand(V, Int_val(I));
+}
+
 /*--... Operations on constants of (mostly) any type .......................--*/
 
 /* llvalue -> bool */
 /*--... Operations on constants of (mostly) any type .......................--*/
 
 /* llvalue -> bool */
index 1b7200b19f47cb741e06436c3d9cc583a412cab1..cbd52e46bba4a57091434cf686119fd6309819e3 100644 (file)
@@ -606,6 +606,24 @@ let test_global_variables () =
     dispose_module m
   end
 
     dispose_module m
   end
 
+
+(*===-- Users -------------------------------------------------------------===*)
+
+let test_users () =
+  let ty = function_type i32_type [| i32_type; i32_type |] in
+  let fn = define_function "user_function" ty m in
+  let b = builder_at_end context (entry_block fn) in
+
+  let p1 = param fn 0 in
+  let p2 = param fn 1 in
+  let i = build_add p1 p2 "sum" b in
+
+  insist ((operand i 0) = p1);
+  insist ((operand i 1) = p2);
+
+  ignore (build_unreachable b)
+
+
 (*===-- Aliases -----------------------------------------------------------===*)
 
 let test_aliases () =
 (*===-- Aliases -----------------------------------------------------------===*)
 
 let test_aliases () =
@@ -1273,6 +1291,7 @@ let _ =
   suite "constants"        test_constants;
   suite "global values"    test_global_values;
   suite "global variables" test_global_variables;
   suite "constants"        test_constants;
   suite "global values"    test_global_values;
   suite "global variables" test_global_variables;
+  suite "users"            test_users;
   suite "aliases"          test_aliases;
   suite "functions"        test_functions;
   suite "params"           test_params;
   suite "aliases"          test_aliases;
   suite "functions"        test_functions;
   suite "params"           test_params;