From 784da8a722b3a85121162340e904d7b5172bdfc0 Mon Sep 17 00:00:00 2001 From: Victor Campos Date: Thu, 11 Aug 2022 15:21:49 +0100 Subject: [PATCH] [ARM] Simplify the creation of escaped build attribute values There is an existing mechanism to escape strings, therefore the functions created to escape Tag_also_compatible_with values are not really needed. We can simply use the pre-existing utilities. Reviewed By: pratlucas Differential Revision: https://reviews.llvm.org/D131680 --- llvm/include/llvm/Support/ARMBuildAttributes.h | 2 -- llvm/lib/Support/ARMBuildAttrs.cpp | 38 +--------------------- .../lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp | 2 +- 3 files changed, 2 insertions(+), 40 deletions(-) diff --git a/llvm/include/llvm/Support/ARMBuildAttributes.h b/llvm/include/llvm/Support/ARMBuildAttributes.h index 1965bee..35f8992 100644 --- a/llvm/include/llvm/Support/ARMBuildAttributes.h +++ b/llvm/include/llvm/Support/ARMBuildAttributes.h @@ -263,8 +263,6 @@ enum { PACRETUsed = 1 }; -std::string encodeAttrTagValuePair(StringRef OriginalString); - } // namespace ARMBuildAttrs } // namespace llvm diff --git a/llvm/lib/Support/ARMBuildAttrs.cpp b/llvm/lib/Support/ARMBuildAttrs.cpp index c390136..11fe0c6 100644 --- a/llvm/lib/Support/ARMBuildAttrs.cpp +++ b/llvm/lib/Support/ARMBuildAttrs.cpp @@ -75,40 +75,4 @@ static const TagNameItem tagData[] = { constexpr TagNameMap ARMAttributeTags{tagData}; const TagNameMap &llvm::ARMBuildAttrs::getARMAttributeTags() { return ARMAttributeTags; -} - -static std::string getEncodedULEB128AsText(const uint8_t *Value, - unsigned Size) { - std::stringstream SS; - for (unsigned i = 0; i < Size; ++i) { - SS << "\\" << std::setfill('0') << std::setw(3) << std::oct - << int(Value[i]); - } - return SS.str(); -} - -std::string -llvm::ARMBuildAttrs::encodeAttrTagValuePair(StringRef OriginalString) { - auto BytesBegin = reinterpret_cast(OriginalString.data()); - auto BytesEnd = BytesBegin + OriginalString.size(); - - unsigned N = 0; - const char *Error = nullptr; - unsigned Tag = decodeULEB128(BytesBegin, &N, BytesEnd, &Error); - if (Error) - report_fatal_error("Could not decode Tag value: " + Twine(Error)); - - std::string EncodedPair = getEncodedULEB128AsText(BytesBegin, N); - switch (Tag) { - case ARMBuildAttrs::CPU_raw_name: - case ARMBuildAttrs::CPU_name: - case ARMBuildAttrs::compatibility: - case ARMBuildAttrs::conformance: - EncodedPair += OriginalString.substr(N); - break; - default: - EncodedPair += - getEncodedULEB128AsText(BytesBegin + N, OriginalString.size() - N); - } - return EncodedPair; -} +} \ No newline at end of file diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index 24ffa0c..15188e0 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -204,7 +204,7 @@ void ARMTargetAsmStreamer::emitTextAttribute(unsigned Attribute, default: OS << "\t.eabi_attribute\t" << Attribute << ", \""; if (Attribute == ARMBuildAttrs::also_compatible_with) - OS << ARMBuildAttrs::encodeAttrTagValuePair(String); + OS.write_escaped(String); else OS << String; OS << "\""; -- 2.7.4