diff --git a/llvm/include/llvm/Demangle/RustDemangle.h b/llvm/include/llvm/Demangle/RustDemangle.h --- a/llvm/include/llvm/Demangle/RustDemangle.h +++ b/llvm/include/llvm/Demangle/RustDemangle.h @@ -88,6 +88,7 @@ void demangleImplPath(InType InType); void demangleGenericArg(); void demangleType(); + void demangleFnSig(); void demangleConst(); void demangleConstInt(); void demangleConstBool(); diff --git a/llvm/lib/Demangle/RustDemangle.cpp b/llvm/lib/Demangle/RustDemangle.cpp --- a/llvm/lib/Demangle/RustDemangle.cpp +++ b/llvm/lib/Demangle/RustDemangle.cpp @@ -472,6 +472,9 @@ print("*mut "); demangleType(); break; + case 'F': + demangleFnSig(); + break; default: Position = Start; demanglePath(rust_demangle::InType::Yes); @@ -479,6 +482,47 @@ } } +// := [] ["U"] ["K" ] {} "E" +// = "C" +// | +void Demangler::demangleFnSig() { + // FIXME demangle binder. + + if (consumeIf('U')) + print("unsafe "); + + if (consumeIf('K')) { + print("extern \""); + if (consumeIf('C')) { + print("C"); + } else { + Identifier Ident = parseIdentifier(); + for (char C : Ident.Name) { + // When mangling ABI string, the "-" is replaced with "_". + if (C == '_') + C = '-'; + print(C); + } + } + print("\" "); + } + + print("fn("); + for (size_t I = 0; !Error && !consumeIf('E'); ++I) { + if (I > 0) + print(", "); + demangleType(); + } + print(")"); + + if (consumeIf('u')) { + // Skip the unit type from the output. + } else { + print(" -> "); + demangleType(); + } +} + // = // | "p" // placeholder // | diff --git a/llvm/test/Demangle/rust.test b/llvm/test/Demangle/rust.test --- a/llvm/test/Demangle/rust.test +++ b/llvm/test/Demangle/rust.test @@ -187,6 +187,35 @@ CHECK: types::<*mut _> _RIC5typesOpE +; Function signatures + +CHECK: function:: + _RIC8functionFEuE + +CHECK: function:: _> + _RIC8functionFEpE + +CHECK: function:: + _RIC8functionFpEuE + +CHECK: function:: + _RIC8functionFppEuE + +CHECK: function:: + _RIC8functionFpppEuE + +CHECK: function:: + _RIC8functionFUEuE + +CHECK: function:: + _RIC8functionFKCEuE + +CHECK: function:: + _RIC8functionFK5cdeclEuE + +CHECK: function:: + _RIC8functionFUK21C_cmse_nonsecure_callEuE + ; Integer constants. Test value demangling. CHECK: integer::<0>