[Mlir-commits] [mlir] 1b79efd - [mlir] Fix printing of EmitC attrs/types with escape characters
Marius Brehler
llvmlistbot at llvm.org
Wed Sep 15 11:17:58 PDT 2021
Author: Simon Camphausen
Date: 2021-09-15T18:15:38Z
New Revision: 1b79efdc72e640fb7a70e5974d0e7352d72ce997
URL: https://github.com/llvm/llvm-project/commit/1b79efdc72e640fb7a70e5974d0e7352d72ce997
DIFF: https://github.com/llvm/llvm-project/commit/1b79efdc72e640fb7a70e5974d0e7352d72ce997.diff
LOG: [mlir] Fix printing of EmitC attrs/types with escape characters
Attributes and types were not escaped when printing.
Reviewed By: jpienaar, marbre
Differential Revision: https://reviews.llvm.org/D109143
Added:
mlir/test/Dialect/EmitC/attrs.mlir
mlir/test/Target/Cpp/attrs.mlir
mlir/test/Target/Cpp/types.mlir
Modified:
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
mlir/test/Dialect/EmitC/types.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index f243d470c064a..4350f6c813e26 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -9,6 +9,7 @@
#include "mlir/Dialect/EmitC/IR/EmitC.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/DialectImplementation.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h"
using namespace mlir;
@@ -201,7 +202,9 @@ void EmitCDialect::printAttribute(Attribute attr, DialectAsmPrinter &os) const {
}
void emitc::OpaqueAttr::print(DialectAsmPrinter &printer) const {
- printer << "opaque<\"" << getValue() << "\">";
+ printer << "opaque<\"";
+ llvm::printEscapedString(getValue(), printer.getStream());
+ printer << "\">";
}
//===----------------------------------------------------------------------===//
@@ -245,5 +248,7 @@ void EmitCDialect::printType(Type type, DialectAsmPrinter &os) const {
}
void emitc::OpaqueType::print(DialectAsmPrinter &printer) const {
- printer << "opaque<\"" << getValue() << "\">";
+ printer << "opaque<\"";
+ llvm::printEscapedString(getValue(), printer.getStream());
+ printer << "\">";
}
diff --git a/mlir/test/Dialect/EmitC/attrs.mlir b/mlir/test/Dialect/EmitC/attrs.mlir
new file mode 100644
index 0000000000000..804f16bc1ed08
--- /dev/null
+++ b/mlir/test/Dialect/EmitC/attrs.mlir
@@ -0,0 +1,12 @@
+// RUN: mlir-opt -verify-diagnostics %s | FileCheck %s
+// check parser
+// RUN: mlir-opt -verify-diagnostics %s | mlir-opt -verify-diagnostics | FileCheck %s
+
+// CHECK-LABEL: func @opaque_attrs() {
+func @opaque_attrs() {
+ // CHECK-NEXT: #emitc.opaque<"attr">
+ emitc.call "f"() {args = [#emitc.opaque<"attr">]} : () -> ()
+ // CHECK-NEXT: #emitc.opaque<"\22quoted_attr\22">
+ emitc.call "f"() {args = [#emitc.opaque<"\"quoted_attr\"">]} : () -> ()
+ return
+}
diff --git a/mlir/test/Dialect/EmitC/types.mlir b/mlir/test/Dialect/EmitC/types.mlir
index f1ffce74e4c2c..26ddf19e3953b 100644
--- a/mlir/test/Dialect/EmitC/types.mlir
+++ b/mlir/test/Dialect/EmitC/types.mlir
@@ -5,14 +5,15 @@
// CHECK-LABEL: func @opaque_types() {
func @opaque_types() {
// CHECK-NEXT: !emitc.opaque<"int">
- emitc.call "f"() {args = [!emitc<"opaque<\"int\">">]} : () -> ()
+ emitc.call "f"() {template_args = [!emitc<"opaque<\"int\">">]} : () -> ()
// CHECK-NEXT: !emitc.opaque<"byte">
- emitc.call "f"() {args = [!emitc<"opaque<\"byte\">">]} : () -> ()
+ emitc.call "f"() {template_args = [!emitc<"opaque<\"byte\">">]} : () -> ()
// CHECK-NEXT: !emitc.opaque<"unsigned">
- emitc.call "f"() {args = [!emitc<"opaque<\"unsigned\">">]} : () -> ()
+ emitc.call "f"() {template_args = [!emitc<"opaque<\"unsigned\">">]} : () -> ()
// CHECK-NEXT: !emitc.opaque<"status_t">
- emitc.call "f"() {args = [!emitc<"opaque<\"status_t\">">]} : () -> ()
+ emitc.call "f"() {template_args = [!emitc<"opaque<\"status_t\">">]} : () -> ()
// CHECK-NEXT: !emitc.opaque<"std::vector<std::string>">
- emitc.call "f"() {args = [!emitc.opaque<"std::vector<std::string>">]} : () -> ()
+ emitc.call "f"() {template_args = [!emitc.opaque<"std::vector<std::string>">]} : () -> ()
+
return
}
diff --git a/mlir/test/Target/Cpp/attrs.mlir b/mlir/test/Target/Cpp/attrs.mlir
new file mode 100644
index 0000000000000..932ee4cba1245
--- /dev/null
+++ b/mlir/test/Target/Cpp/attrs.mlir
@@ -0,0 +1,10 @@
+// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s
+
+// CHECK-LABEL: void opaque_attrs() {
+func @opaque_attrs() {
+ // CHECK-NEXT: f(OPAQUE_ENUM_VALUE);
+ emitc.call "f"() {args = [#emitc.opaque<"OPAQUE_ENUM_VALUE">]} : () -> ()
+ // CHECK-NEXT: f("some string");
+ emitc.call "f"() {args = [#emitc.opaque<"\"some string\"">]} : () -> ()
+ return
+}
diff --git a/mlir/test/Target/Cpp/types.mlir b/mlir/test/Target/Cpp/types.mlir
new file mode 100644
index 0000000000000..70febba61140a
--- /dev/null
+++ b/mlir/test/Target/Cpp/types.mlir
@@ -0,0 +1,17 @@
+// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s
+
+// CHECK-LABEL: void opaque_template_args() {
+func @opaque_template_args() {
+ // CHECK-NEXT: f<int>();
+ emitc.call "f"() {template_args = [!emitc<"opaque<\"int\">">]} : () -> ()
+ // CHECK-NEXT: f<byte>();
+ emitc.call "f"() {template_args = [!emitc<"opaque<\"byte\">">]} : () -> ()
+ // CHECK-NEXT: f<unsigned>();
+ emitc.call "f"() {template_args = [!emitc<"opaque<\"unsigned\">">]} : () -> ()
+ // CHECK-NEXT: f<status_t>();
+ emitc.call "f"() {template_args = [!emitc<"opaque<\"status_t\">">]} : () -> ()
+ // CHECK-NEXT: f<std::vector<std::string>>();
+ emitc.call "f"() {template_args = [!emitc.opaque<"std::vector<std::string>">]} : () -> ()
+
+ return
+}
More information about the Mlir-commits
mailing list