[llvm] [MIR] Replace bespoke DIExpression parser (PR #96827)
Scott Linder via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 14:53:20 PDT 2024
================
@@ -2302,48 +2302,14 @@ bool MIParser::parseMDNode(MDNode *&Node) {
}
bool MIParser::parseDIExpression(MDNode *&Expr) {
- assert(Token.is(MIToken::md_diexpr));
- lex();
-
- // FIXME: Share this parsing with the IL parser.
- SmallVector<uint64_t, 8> Elements;
-
- if (expectAndConsume(MIToken::lparen))
- return true;
-
- if (Token.isNot(MIToken::rparen)) {
- do {
- if (Token.is(MIToken::Identifier)) {
- if (unsigned Op = dwarf::getOperationEncoding(Token.stringValue())) {
- lex();
- Elements.push_back(Op);
- continue;
- }
- if (unsigned Enc = dwarf::getAttributeEncoding(Token.stringValue())) {
- lex();
- Elements.push_back(Enc);
- continue;
- }
- return error(Twine("invalid DWARF op '") + Token.stringValue() + "'");
- }
-
- if (Token.isNot(MIToken::IntegerLiteral) ||
- Token.integerValue().isSigned())
- return error("expected unsigned integer");
-
- auto &U = Token.integerValue();
- if (U.ugt(UINT64_MAX))
- return error("element too large, limit is " + Twine(UINT64_MAX));
- Elements.push_back(U.getZExtValue());
- lex();
-
- } while (consumeIfPresent(MIToken::comma));
- }
-
- if (expectAndConsume(MIToken::rparen))
- return true;
-
- Expr = DIExpression::get(MF.getFunction().getContext(), Elements);
+ unsigned Read;
+ Expr = llvm::parseDIExpressionBodyAtBeginning(
----------------
slinder1 wrote:
The `AtBeginning` relates to the fact that the buffer can be longer than the body of the `DIExpression`, i.e. there can be trailing characters in the buffer. I intended to add a test for that property but missed it, so I'll add one and update the test.
https://github.com/llvm/llvm-project/pull/96827
More information about the llvm-commits
mailing list