From 5ecdba8a678af0752733744bbe6f91c3c4718c16 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Wed, 1 Nov 2023 17:25:26 -0700 Subject: [PATCH] Add functions peekNextN(unsigned) and assignNewExpr(ArrayRef) to DIExpressionCursor This commit adds two functions to the DIExpressionCursor class. peekNextN(unsigned) works like peekNext, but lets you peek the next Nth element assignNewExpr(ArrayRef) lets you assign a new expression to the same DIExpressionCursor object --- llvm/include/llvm/IR/DebugInfoMetadata.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h index a1c554677f8bf..555bd623ad9ef 100644 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -3199,6 +3199,23 @@ class DIExpressionCursor { return *Next; } + std::optional peekNextN(unsigned N) const { + if (Start == End) + return std::nullopt; + DIExpression::expr_op_iterator Nth = Start; + for (unsigned I = 0; I < N; I++) { + Nth = Nth.getNext(); + if (Nth == End) + return std::nullopt; + } + return *Nth; + } + + void assignNewExpr(ArrayRef Expr) { + this->Start = DIExpression::expr_op_iterator(Expr.begin()); + this->End = DIExpression::expr_op_iterator(Expr.end()); + } + /// Determine whether there are any operations left in this expression. operator bool() const { return Start != End; }