[llvm] [AArch64] Refactor @plt, @gotpcrel, and @AUTH to use parseDataExpr (PR #134202)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 4 09:04:26 PDT 2025


================
@@ -8086,11 +8106,56 @@ bool AArch64AsmParser::parseDirectiveAeabiAArch64Attr(SMLoc L) {
   return false;
 }
 
-bool AArch64AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
-  // Try @AUTH expressions: they're more complex than the usual symbol variants.
-  if (!parseAuthExpr(Res, EndLoc))
+bool AArch64AsmParser::parseDataExpr(const MCExpr *&Res) {
+  SMLoc EndLoc;
+
+  if (getParser().parseExpression(Res))
+    return true;
+  MCAsmParser &Parser = getParser();
+  if (!parseOptionalToken(AsmToken::At))
     return false;
-  return getParser().parsePrimaryExpr(Res, EndLoc, nullptr);
+  if (getLexer().getKind() != AsmToken::Identifier)
+    return Error(getLoc(), "expected relocation specifier");
+
+  std::string Identifier = Parser.getTok().getIdentifier().lower();
+  SMLoc Loc = getLoc();
+  Lex();
+  if (Identifier == "auth")
+    return parseAuthExpr(Res, EndLoc);
+
+  auto Spec = MCSymbolRefExpr::VK_None;
+  if (STI->getTargetTriple().isOSBinFormatMachO()) {
+    if (Identifier == "got")
+      Spec = MCSymbolRefExpr::VK_GOT;
+  } else {
+    // Unofficial, experimental syntax that will be changed.
+    if (Identifier == "gotpcrel")
+      Spec = MCSymbolRefExpr::VK_GOTPCREL;
+    else if (Identifier == "plt")
+      Spec = MCSymbolRefExpr::VK_PLT;
+  }
+  if (Spec == MCSymbolRefExpr::VK_None)
+    return Error(Loc, "invalid relocation specifier");
----------------
smithp35 wrote:

Is there scope to print the identifier? Yes it can be determined by the `^` but it can help to see it in the text.

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


More information about the llvm-commits mailing list