forked from OSchip/llvm-project
[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
This commit is contained in:
parent
96ec0ff2b7
commit
1b79efdc72
|
@ -9,6 +9,7 @@
|
||||||
#include "mlir/Dialect/EmitC/IR/EmitC.h"
|
#include "mlir/Dialect/EmitC/IR/EmitC.h"
|
||||||
#include "mlir/IR/Builders.h"
|
#include "mlir/IR/Builders.h"
|
||||||
#include "mlir/IR/DialectImplementation.h"
|
#include "mlir/IR/DialectImplementation.h"
|
||||||
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/ADT/TypeSwitch.h"
|
#include "llvm/ADT/TypeSwitch.h"
|
||||||
|
|
||||||
using namespace mlir;
|
using namespace mlir;
|
||||||
|
@ -201,7 +202,9 @@ void EmitCDialect::printAttribute(Attribute attr, DialectAsmPrinter &os) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitc::OpaqueAttr::print(DialectAsmPrinter &printer) 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 {
|
void emitc::OpaqueType::print(DialectAsmPrinter &printer) const {
|
||||||
printer << "opaque<\"" << getValue() << "\">";
|
printer << "opaque<\"";
|
||||||
|
llvm::printEscapedString(getValue(), printer.getStream());
|
||||||
|
printer << "\">";
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -5,14 +5,15 @@
|
||||||
// CHECK-LABEL: func @opaque_types() {
|
// CHECK-LABEL: func @opaque_types() {
|
||||||
func @opaque_types() {
|
func @opaque_types() {
|
||||||
// CHECK-NEXT: !emitc.opaque<"int">
|
// 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">
|
// 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">
|
// 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">
|
// 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>">
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue