[PATCH] D52213: [OCaml] Add OCaml API for __cxa_demangle
Josh Berdine via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 17 18:26:09 PDT 2018
jberdine created this revision.
jberdine added a reviewer: whitequark.
Herald added subscribers: llvm-commits, erik.pilkington.
Adds a demangle function to the OCaml API to expose the internal
implementation of __cxa_demangle. This is useful for OCaml clients
which would not otherwise link to libstdc++.
Repository:
rL LLVM
https://reviews.llvm.org/D52213
Files:
bindings/ocaml/llvm/llvm.ml
bindings/ocaml/llvm/llvm.mli
bindings/ocaml/llvm/llvm_ocaml.c
Index: bindings/ocaml/llvm/llvm_ocaml.c
===================================================================
--- bindings/ocaml/llvm/llvm_ocaml.c
+++ bindings/ocaml/llvm/llvm_ocaml.c
@@ -850,7 +850,6 @@
return Val_int(LLVMGetDebugLocColumn(Inst));
}
-
/*--... Operations on metadata .............................................--*/
/* llcontext -> string -> llvalue */
@@ -1204,6 +1203,19 @@
return Val_unit;
}
+extern char *__cxa_demangle(const char *, char *, size_t *, int *);
+
+/* string -> string */
+CAMLprim value llvm_demangle(value Mangled) {
+ int status;
+ char *demangled = __cxa_demangle(String_val(Mangled), NULL, NULL, &status);
+ if (demangled) {
+ return(caml_copy_string(demangled));
+ } else {
+ return caml_copy_string("");
+ }
+}
+
/*--... Operations on uses .................................................--*/
/* llvalue -> lluse option */
@@ -1682,7 +1694,6 @@
return LLVMInstructionClone(Inst);
}
-
/*--... Operations on call sites ...........................................--*/
/* llvalue -> int */
@@ -1923,7 +1934,6 @@
return Val_unit;
}
-
/*--... Terminators ........................................................--*/
/* llbuilder -> llvalue */
Index: bindings/ocaml/llvm/llvm.mli
===================================================================
--- bindings/ocaml/llvm/llvm.mli
+++ bindings/ocaml/llvm/llvm.mli
@@ -1388,6 +1388,9 @@
[n] bytes. See the method [llvm::GlobalValue::setAlignment]. *)
val set_alignment : int -> llvalue -> unit
+(** [demangle s] is the demangled form of [s], obtained from [__cxa_demangle]. *)
+val demangle : string -> string
+
(** {7 Operations on global variables} *)
Index: bindings/ocaml/llvm/llvm.ml
===================================================================
--- bindings/ocaml/llvm/llvm.ml
+++ bindings/ocaml/llvm/llvm.ml
@@ -706,6 +706,7 @@
external is_global_constant : llvalue -> bool = "llvm_is_global_constant"
external set_global_constant : bool -> llvalue -> unit
= "llvm_set_global_constant"
+external demangle : string -> string = "llvm_demangle"
(*--... Operations on global variables .....................................--*)
external declare_global : lltype -> string -> llmodule -> llvalue
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52213.165871.patch
Type: text/x-patch
Size: 2288 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180918/d5510380/attachment.bin>
More information about the llvm-commits
mailing list