[llvm] [DebugCounter] Add support for non-continous ranges. (PR #89470)

Nicolai Hähnle via llvm-commits llvm-commits at lists.llvm.org
Thu May 16 12:47:32 PDT 2024


================
@@ -7,6 +7,83 @@
 
 using namespace llvm;
 
+namespace llvm {
+
+void Chunk::print(llvm::raw_ostream &OS) {
+  if (Begin == End)
+    OS << Begin;
+  else
+    OS << Begin << "-" << End;
+}
+
+void printChunks(raw_ostream &OS, ArrayRef<Chunk> Chunks) {
+  if (Chunks.empty()) {
+    OS << "empty";
+  } else {
+    bool IsFirst = true;
+    for (auto E : Chunks) {
+      if (!IsFirst)
+        OS << ":";
+      else
+        IsFirst = false;
+      E.print(OS);
+    }
+  }
+}
+
+bool parseChunks(StringRef Str, SmallVector<Chunk> &Chunks) {
+  StringRef Remaining = Str;
+
+  auto ConsumeInt = [&]() -> int64_t {
+    StringRef Number =
+        Remaining.take_until([](char c) { return c < '0' || c > '9'; });
+    int64_t Res;
+    if (Number.getAsInteger(10, Res)) {
+      errs() << "Failed to parse int at : " << Remaining << "\n";
+      return -1;
+    }
+    Remaining = Remaining.drop_front(Number.size());
+    return Res;
+  };
+
+  while (1) {
+    int64_t Num = ConsumeInt();
+    if (Num == -1) {
+      return true;
+    }
----------------
nhaehnle wrote:

Can drop the braces around a single-line body of an `if`

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


More information about the llvm-commits mailing list