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 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_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 */