[Mlir-commits] [mlir] 45d2033 - [MLIR][Printing] ASMPrinter prints escape characters in Resources
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Aug 24 22:51:12 PDT 2023
Author: Mogball
Date: 2023-08-25T05:51:08Z
New Revision: 45d20338281e4fd17a773c067f28f839db0f9b8e
URL: https://github.com/llvm/llvm-project/commit/45d20338281e4fd17a773c067f28f839db0f9b8e
DIFF: https://github.com/llvm/llvm-project/commit/45d20338281e4fd17a773c067f28f839db0f9b8e.diff
LOG: [MLIR][Printing] ASMPrinter prints escape characters in Resources
In https://reviews.llvm.org/D157928 ellison of printing resources was added.
In the refactor, the proper printing of escape characters was mistakenly removed.
This patch adds it back in and adds a small unit test.
Reviewed By: Mogball
Differential Revision: https://reviews.llvm.org/D158700
Added:
Modified:
mlir/lib/IR/AsmPrinter.cpp
mlir/test/IR/pretty-resources-print.mlir
Removed:
################################################################################
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index a39ad77a04205b..aeb6f0f3562635 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -3101,7 +3101,11 @@ class OperationPrinter : public AsmPrinter::Impl, private OpAsmPrinter {
}
void buildString(StringRef key, StringRef data) final {
- printFn(key, [&](raw_ostream &os) { os << "\"" << data << "\""; });
+ printFn(key, [&](raw_ostream &os) {
+ os << "\"";
+ llvm::printEscapedString(data, os);
+ os << "\"";
+ });
}
void buildBlob(StringRef key, ArrayRef<char> data,
diff --git a/mlir/test/IR/pretty-resources-print.mlir b/mlir/test/IR/pretty-resources-print.mlir
index ea6e9f4b28c280..625967fcb76038 100644
--- a/mlir/test/IR/pretty-resources-print.mlir
+++ b/mlir/test/IR/pretty-resources-print.mlir
@@ -1,6 +1,6 @@
// Check printing with --mlir-elide-resource-strings-if-larger elides printing large resources
-// RUN: mlir-opt %s --mlir-elide-resource-strings-if-larger=10| FileCheck %s
+// RUN: mlir-opt %s --mlir-elide-resource-strings-if-larger=20| FileCheck %s
// To ensure we print the resource keys, have reference to them
// CHECK: attr = dense_resource<blob1> : tensor<3xi64>
@@ -13,7 +13,7 @@
// CHECK-NEXT: external_resources: {
// CHECK-NEXT: external: {
// CHECK-NEXT: bool: true,
-// CHECK-NEXT: string: "string"
+// CHECK-NEXT: string: "\22string\22"
// CHECK-NEXT: },
// CHECK-NEXT: other_stuff: {
// CHECK-NEXT: bool: true
@@ -32,7 +32,7 @@
external: {
blob: "0x08000000010000000000000002000000000000000300000000000000",
bool: true,
- string: "string"
+ string: "\"string\"" // with escape characters
},
other_stuff: {
bool: true
More information about the Mlir-commits
mailing list