[llvm] r194136 - [OCaml] Implement Llvm.string_of_llvalue
Peter Zotov
whitequark at whitequark.org
Wed Nov 6 01:21:09 PST 2013
Author: whitequark
Date: Wed Nov 6 03:21:08 2013
New Revision: 194136
URL: http://llvm.org/viewvc/llvm-project?rev=194136&view=rev
Log:
[OCaml] Implement Llvm.string_of_llvalue
Modified:
llvm/trunk/bindings/ocaml/llvm/llvm.ml
llvm/trunk/bindings/ocaml/llvm/llvm.mli
llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
llvm/trunk/test/Bindings/Ocaml/vmcore.ml
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.ml?rev=194136&r1=194135&r2=194136&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.ml (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.ml Wed Nov 6 03:21:08 2013
@@ -382,6 +382,7 @@ external type_of : llvalue -> lltype = "
external value_name : llvalue -> string = "llvm_value_name"
external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
external dump_value : llvalue -> unit = "llvm_dump_value"
+external string_of_llvalue : llvalue -> string = "llvm_string_of_llvalue"
external replace_all_uses_with : llvalue -> llvalue -> unit
= "llvm_replace_all_uses_with"
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.mli
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.mli?rev=194136&r1=194135&r2=194136&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.mli (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.mli Wed Nov 6 03:21:08 2013
@@ -654,6 +654,9 @@ val set_value_name : string -> llvalue -
error. See the method [llvm::Value::dump]. *)
val dump_value : llvalue -> unit
+(** [string_of_llvalue v] returns a string describing the value [v]. *)
+val string_of_llvalue : llvalue -> string
+
(** [replace_all_uses_with old new] replaces all uses of the value [old]
with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
val replace_all_uses_with : llvalue -> llvalue -> unit
Modified: llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c?rev=194136&r1=194135&r2=194136&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c Wed Nov 6 03:21:08 2013
@@ -527,6 +527,17 @@ CAMLprim value llvm_dump_value(LLVMValue
return Val_unit;
}
+/* llvalue -> string */
+CAMLprim value llvm_string_of_llvalue(LLVMTypeRef M) {
+ char* TypeCStr;
+ TypeCStr = LLVMPrintValueToString(M);
+
+ value TypeStr = caml_copy_string(TypeCStr);
+ LLVMDisposeMessage(TypeCStr);
+
+ return TypeStr;
+}
+
/* llvalue -> llvalue -> unit */
CAMLprim value llvm_replace_all_uses_with(LLVMValueRef OldVal,
LLVMValueRef NewVal) {
Modified: llvm/trunk/test/Bindings/Ocaml/vmcore.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/Ocaml/vmcore.ml?rev=194136&r1=194135&r2=194136&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/Ocaml/vmcore.ml (original)
+++ llvm/trunk/test/Bindings/Ocaml/vmcore.ml Wed Nov 6 03:21:08 2013
@@ -67,6 +67,14 @@ let filename = Sys.argv.(1)
let m = create_module context filename
+(*===-- Conversion --------------------------------------------------------===*)
+
+let test_conversion () =
+ insist ("i32" = (string_of_lltype i32_type));
+ let c = const_int i32_type 42 in
+ insist ("i32 42" = (string_of_llvalue c))
+
+
(*===-- Target ------------------------------------------------------------===*)
let test_target () =
@@ -1392,6 +1400,7 @@ let test_writer () =
(*===-- Driver ------------------------------------------------------------===*)
let _ =
+ suite "conversion" test_conversion;
suite "target" test_target;
suite "constants" test_constants;
suite "global values" test_global_values;
More information about the llvm-commits
mailing list