[llvm] [NFC][TableGen] Emit more readable builtin string table (PR #105445)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 07:29:14 PDT 2024


================
@@ -52,6 +53,32 @@ class StringToOffsetTable {
     return II->second;
   }
 
+  // Emit the string using string literal concatenation, for better readability
+  // and searchability.
+  void EmitStringLiteralDef(raw_ostream &OS, const Twine &Decl,
+                            const Twine &Indent = "  ") const {
+    OS << formatv(R"(
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Woverlength-strings"
+#endif
+{0}{1} = )",
+                  Indent, Decl);
+
+    for (StringRef Str : split(AggregateString, '\0')) {
+      OS << "\n" << Indent << "  \"";
+      OS.write_escaped(Str);
+      OS << "\\0\"";
+    }
+    OS << formatv(R"(;
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
+)",
+                  Indent);
----------------
jurahul wrote:

Fixed.

https://github.com/llvm/llvm-project/pull/105445


More information about the llvm-commits mailing list