[Mlir-commits] [mlir] [mlir][Pass] Handle escaped pipline option values (PR #97667)

Nikhil Kalra llvmlistbot at llvm.org
Thu Jul 4 13:43:25 PDT 2024


================
@@ -60,6 +60,20 @@ template <typename ParserT>
 static void printOptionValue(raw_ostream &os, const bool &value) {
   os << (value ? StringRef("true") : StringRef("false"));
 }
+template <typename ParserT>
+static void printOptionValue(raw_ostream &os, const std::string &str) {
+  // Check if the string needs to be escaped before writing it to the ostream.
+  const size_t spaceIndex = str.find_first_of(' ');
+  const size_t escapeIndex =
+      std::min({str.find_first_of('{'), str.find_first_of('\''),
+                str.find_first_of('"')});
+  const bool requiresEscape = spaceIndex < escapeIndex;
----------------
nikalra wrote:

I think that should still be ok since the parser just looks for ` ` or the corresponding end terminator (if the first character after `=` is an escape character) to extract the argument. For example:
```
❯ mlir-opt mlir/test/Pass/pipeline-options-parsing.mlir -verify-each=false -pass-pipeline='builtin.module(builtin.module(func.func(test-options-pass{list=3}), func.func(test-options-pass{enum=one list=1,2,3,4 string=foo"bar"baz})))' -dump-pass-pipeline

Pass Manager with 1 passes:
builtin.module(builtin.module(func.func(test-options-pass{enum=zero list=3 string= }),func.func(test-options-pass{enum=one list=1,2,3,4 string=foo"bar"baz })))
```

https://github.com/llvm/llvm-project/pull/97667


More information about the Mlir-commits mailing list