[sledge] Switch from Llvm.demangle to __cxa_demangle via Ctypes

Summary:
Call __cxa_demangle from libstdc++ using Ctypes instead of the
wrapper in Llvm.

Reviewed By: mbouaziz

Differential Revision: D9939682

fbshipit-source-id: a9f02fff5
master
Josh Berdine 6 years ago committed by Facebook Github Bot
parent 27f08ab53a
commit e71ea9f0ed

@ -10,6 +10,8 @@ build: [
depends: [
"cmdliner"
"core_kernel" {>= "v0.11.0"}
"ctypes"
"ctypes-foreign"
"dune" {build}
"llvm" {build & = "7.0.0"}
"ppx_compare" {>= "v0.11.0"}

@ -10,6 +10,8 @@ build: [
depends: [
"cmdliner"
"core_kernel" {>= "v0.11.0"}
"ctypes"
"ctypes-foreign"
"dune" {build}
"llvm" {build & = "7.0.0"}
"ppx_compare" {>= "v0.11.0"}

@ -10,6 +10,6 @@ Jbuild_plugin.V1.send
(name llair_)
(public_name llair)
%s
(libraries llvm llvm.irreader llvm.analysis llvm.scalar_opts llvm.target %s))
(libraries ctypes ctypes.foreign llvm llvm.irreader llvm.analysis llvm.scalar_opts llvm.target %s))
|}
(flags deps) (libraries deps)

@ -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

Loading…
Cancel
Save