[Mlir-commits] [mlir] [mlir] Add support for parsing nested PassPipelineOptions (PR #101118)

Nikhil Kalra llvmlistbot at llvm.org
Tue Jul 30 18:30:25 PDT 2024


================
@@ -159,13 +160,36 @@ const PassPipelineInfo *mlir::PassPipelineInfo::lookup(StringRef pipelineArg) {
 // PassOptions
 //===----------------------------------------------------------------------===//
 
+/// Extract an argument from 'options' and update it to point after the arg.
+/// Returns the cleaned argument string.
+static StringRef extractArgAndUpdateOptions(StringRef &options,
+                                            size_t argSize) {
+  StringRef str = options.take_front(argSize).trim();
+  options = options.drop_front(argSize).ltrim();
+  // Handle escape sequences
+  if (str.size() > 2) {
+    const auto escapePairs = {std::make_pair('\'', '\''),
+                              std::make_pair('"', '"'),
+                              std::make_pair('{', '}')};
+    for (const auto &escape : escapePairs) {
+      if (str.front() == escape.first && str.back() == escape.second) {
+        // Drop the escape characters and trim.
+        str = str.drop_front().drop_back().trim();
+        // Don't process additional escape sequences.
+        break;
+      }
+    }
+  }
+  return str;
+}
+
 LogicalResult detail::pass_options::parseCommaSeparatedList(
     llvm::cl::Option &opt, StringRef argName, StringRef optionStr,
     function_ref<LogicalResult(StringRef)> elementParseFn) {
   // Functor used for finding a character in a string, and skipping over
   // various "range" characters.
   llvm::unique_function<size_t(StringRef, size_t, char)> findChar =
-      [&](StringRef str, size_t index, char c) -> size_t {
+      [&findChar](StringRef str, size_t index, char c) -> size_t {
----------------
nikalra wrote:

Reverted -- I spent a couple of minutes re-reading this lambda to convince myself it didn't implicitly capture/modify anything, but it doesn't impact this change so I'll change it back.

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


More information about the Mlir-commits mailing list