-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MLIR] print/parse resource handle key quoted and escaped #119746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
752429f
857e8e7
f670ae3
f3930de
83b1057
78161de
ec71677
d7b11af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2146,13 +2146,6 @@ void AsmPrinter::Impl::printLocation(LocationAttr loc, bool allowAlias) { | |
| os << ')'; | ||
| } | ||
|
|
||
| void AsmPrinter::Impl::printResourceHandle( | ||
| const AsmDialectResourceHandle &resource) { | ||
| auto *interface = cast<OpAsmDialectInterface>(resource.getDialect()); | ||
| os << interface->getResourceKey(resource); | ||
| state.getDialectResources()[resource.getDialect()].insert(resource); | ||
| } | ||
|
|
||
| /// Returns true if the given dialect symbol data is simple enough to print in | ||
| /// the pretty form. This is essentially when the symbol takes the form: | ||
| /// identifier (`<` body `>`)? | ||
|
|
@@ -2237,6 +2230,13 @@ static void printElidedElementsAttr(raw_ostream &os) { | |
| os << R"(dense_resource<__elided__>)"; | ||
| } | ||
|
|
||
| void AsmPrinter::Impl::printResourceHandle( | ||
| const AsmDialectResourceHandle &resource) { | ||
| auto *interface = cast<OpAsmDialectInterface>(resource.getDialect()); | ||
| ::printKeywordOrString(interface->getResourceKey(resource), os); | ||
| state.getDialectResources()[resource.getDialect()].insert(resource); | ||
| } | ||
|
|
||
| LogicalResult AsmPrinter::Impl::printAlias(Attribute attr) { | ||
| return state.getAliasState().getAlias(attr, os); | ||
| } | ||
|
|
@@ -3331,41 +3331,41 @@ void OperationPrinter::printResourceFileMetadata( | |
| auto printFn = [&](StringRef key, ResourceBuilder::ValueFn valueFn) { | ||
| checkAddMetadataDict(); | ||
|
|
||
| auto printFormatting = [&]() { | ||
| // Emit the top-level resource entry if we haven't yet. | ||
| if (!std::exchange(hadResource, true)) { | ||
| if (needResourceComma) | ||
| os << "," << newLine; | ||
| os << " " << dictName << "_resources: {" << newLine; | ||
| } | ||
| // Emit the parent resource entry if we haven't yet. | ||
| if (!std::exchange(hadEntry, true)) { | ||
| if (needEntryComma) | ||
| os << "," << newLine; | ||
| os << " " << name << ": {" << newLine; | ||
| } else { | ||
| os << "," << newLine; | ||
| } | ||
| }; | ||
|
|
||
| std::string resourceStr; | ||
| auto printResourceStr = [&](raw_ostream &os) { os << resourceStr; }; | ||
| std::optional<uint64_t> charLimit = | ||
| printerFlags.getLargeResourceStringLimit(); | ||
| if (charLimit.has_value()) { | ||
| std::string resourceStr; | ||
| llvm::raw_string_ostream ss(resourceStr); | ||
| valueFn(ss); | ||
|
|
||
| // Only print entry if it's string is small enough | ||
| // Only print entry if its string is small enough. | ||
| if (resourceStr.size() > charLimit.value()) | ||
| return; | ||
|
|
||
| printFormatting(); | ||
| os << " " << key << ": " << resourceStr; | ||
| // Don't recompute resourceStr when valueFn is called below. | ||
| valueFn = printResourceStr; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the old implementation of therefore I refactored the implementation to instead “reprogram” valueFn in the case where resourceStr is materialized to check charLimit |
||
| } | ||
|
|
||
| // Emit the top-level resource entry if we haven't yet. | ||
| if (!std::exchange(hadResource, true)) { | ||
| if (needResourceComma) | ||
| os << "," << newLine; | ||
| os << " " << dictName << "_resources: {" << newLine; | ||
| } | ||
| // Emit the parent resource entry if we haven't yet. | ||
| if (!std::exchange(hadEntry, true)) { | ||
| if (needEntryComma) | ||
| os << "," << newLine; | ||
| os << " " << name << ": {" << newLine; | ||
| } else { | ||
| printFormatting(); | ||
| os << " " << key << ": "; | ||
| valueFn(os); | ||
| os << "," << newLine; | ||
| } | ||
| os << " "; | ||
| ::printKeywordOrString(key, os); | ||
| os << ": "; | ||
| // Call printResourceStr or original valueFn, depending on charLimit. | ||
| valueFn(os); | ||
| }; | ||
| ResourceBuilder entryBuilder(printFn); | ||
| provider.buildResources(op, providerArgs..., entryBuilder); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the version of this in AsmParserImpl to call into this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I did the same for the related parseOptionalKeyword and parserOptionalString methods