[mlir] Escape strings of opaque attributes
Opaque attributes that currently contain string literals can't currently be properly roundtripped as they are not printed as escaped strings. This leads to incorrect tokens being generated and the parser to almost certainly fail. This patch simply uses llvm::printEscapedString from LLVM. It escapes all non printable characters and quotes to \xx hex literals, and backslashes to two backslashes. This syntax is supported by MLIRs Lexer as well. The same function is also currently in use for the same purpose in printSymbolReference, printAttribute for StringAttr and many more in AsmPrinter.cpp. Differential Revision: https://reviews.llvm.org/D105405
This commit is contained in:
parent
14b62f7e2f
commit
a96911c49b
|
@ -1516,8 +1516,9 @@ static void printDialectSymbol(raw_ostream &os, StringRef symPrefix,
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: escape the symbol name, it could contain " characters.
|
||||
os << "<\"" << symString << "\">";
|
||||
os << "<\"";
|
||||
llvm::printEscapedString(symString, os);
|
||||
os << "\">";
|
||||
}
|
||||
|
||||
/// Returns true if the given string can be represented as a bare identifier.
|
||||
|
|
|
@ -1239,6 +1239,12 @@ func @"\"_string_symbol_reference\""() {
|
|||
return
|
||||
}
|
||||
|
||||
// CHECK-LABEL: func private @parse_opaque_attr_escape
|
||||
func private @parse_opaque_attr_escape() {
|
||||
// CHECK: value = #foo<"\22escaped\\\0A\22">
|
||||
"foo.constant"() {value = #foo<"\"escaped\\\n\"">} : () -> ()
|
||||
}
|
||||
|
||||
// CHECK-LABEL: func private @string_attr_name
|
||||
// CHECK-SAME: {"0 . 0", nested = {"0 . 0"}}
|
||||
func private @string_attr_name() attributes {"0 . 0", nested = {"0 . 0"}}
|
||||
|
|
Loading…
Reference in New Issue