[PATCH] D131680: [ARM] Simplify the creation of escaped build attribute values

Victor Campos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 11 07:29:10 PDT 2022


vhscampos created this revision.
Herald added subscribers: jdoerfert, hiraditya, kristof.beyls.
Herald added a project: All.
vhscampos requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131680

Files:
  llvm/include/llvm/Support/ARMBuildAttributes.h
  llvm/lib/Support/ARMBuildAttrs.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp


Index: llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
===================================================================
--- llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
+++ llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
@@ -204,7 +204,7 @@
   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 << "\"";
Index: llvm/lib/Support/ARMBuildAttrs.cpp
===================================================================
--- llvm/lib/Support/ARMBuildAttrs.cpp
+++ llvm/lib/Support/ARMBuildAttrs.cpp
@@ -75,40 +75,4 @@
 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<const uint8_t *>(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
Index: llvm/include/llvm/Support/ARMBuildAttributes.h
===================================================================
--- llvm/include/llvm/Support/ARMBuildAttributes.h
+++ llvm/include/llvm/Support/ARMBuildAttributes.h
@@ -263,8 +263,6 @@
   PACRETUsed = 1
 };
 
-std::string encodeAttrTagValuePair(StringRef OriginalString);
-
 } // namespace ARMBuildAttrs
 } // namespace llvm
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131680.451854.patch
Type: text/x-patch
Size: 2469 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220811/6d5734b3/attachment.bin>


More information about the llvm-commits mailing list