@ -12,6 +12,23 @@ type t = {var: Var.t; init: Exp.t option; siz: int; typ: Typ.t; loc: Loc.t}
let equal = [ % compare . equal : t ]
let demangle =
let open Ctypes in
let cxa_demangle =
(* char * __cxa_demangle ( const char * , char * , size_t * , int * ) *)
Foreign . foreign " __cxa_demangle "
( string @- > ptr char @- > ptr size_t @- > ptr int
@- > returning string_opt )
in
let null_ptr_char = from_voidp char null in
let null_ptr_size_t = from_voidp size_t null in
let status = allocate int 0 in
fun mangled ->
let demangled =
cxa_demangle mangled null_ptr_char null_ptr_size_t status
in
if !@ status = 0 then demangled else None
let pp fs { var } =
let name = Var . name var in
let pf pp =
@ -19,9 +36,10 @@ let pp fs {var} =
Format . kfprintf ( fun fs -> Format . pp_close_box fs () ) fs pp
in
pf " @%s%t " name ( fun fs ->
let demangled = Llvm . demangle name in
if not ( String . is_empty demangled | | String . equal name demangled ) then
Format . fprintf fs " “%s” " demangled )
match demangle name with
| Some demangled when not ( String . equal name demangled ) ->
Format . fprintf fs " “%s” " demangled
| _ -> () )
let pp_defn fs { var ; init ; typ } =
Format . fprintf fs " @[<2>%a %a%a@] " Typ . pp typ Var . pp var