From 151ad37fed2685f020bbed5b342ad7c0c35616bd Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Thu, 20 Jun 2013 16:24:17 +0000 Subject: [PATCH] [MC] Support @ variants with directional labels The assembler parser common code supports recognizing symbol variants using the @ modifer. On PowerPC, it should also be possible to use (some of) those modifiers with directional labels, like "1f@l". This patch adds support for accepting symbol variants on directional labels as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184437 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCParser/AsmParser.cpp | 14 ++++++++++++-- test/MC/PowerPC/ppc64-fixup-apply.s | 8 +++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 270579717a2..167e64174fb 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -805,11 +805,21 @@ bool AsmParser::ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) { // Look for 'b' or 'f' following an Integer as a directional label if (Lexer.getKind() == AsmToken::Identifier) { StringRef IDVal = getTok().getString(); + // Lookup the symbol variant if used. + std::pair Split = IDVal.split('@'); + MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; + if (Split.first.size() != IDVal.size()) { + Variant = MCSymbolRefExpr::getVariantKindForName(Split.second); + if (Variant == MCSymbolRefExpr::VK_Invalid) { + Variant = MCSymbolRefExpr::VK_None; + return TokError("invalid variant '" + Split.second + "'"); + } + IDVal = Split.first; + } if (IDVal == "f" || IDVal == "b"){ MCSymbol *Sym = Ctx.GetDirectionalLocalSymbol(IntVal, IDVal == "f" ? 1 : 0); - Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, - getContext()); + Res = MCSymbolRefExpr::Create(Sym, Variant, getContext()); if (IDVal == "b" && Sym->isUndefined()) return Error(Loc, "invalid reference to undefined symbol"); EndLoc = Lexer.getTok().getEndLoc(); diff --git a/test/MC/PowerPC/ppc64-fixup-apply.s b/test/MC/PowerPC/ppc64-fixup-apply.s index ca33a4455b0..565a8e984d6 100644 --- a/test/MC/PowerPC/ppc64-fixup-apply.s +++ b/test/MC/PowerPC/ppc64-fixup-apply.s @@ -28,6 +28,11 @@ addis 1, 1, target5+0x8000@ha .set target5, 0x10000001 +1: +addi 1, 1, 2f-1b@l +addis 1, 1, 1b-2f@ha +2: + .data .quad v1 @@ -49,7 +54,7 @@ addis 1, 1, target5+0x8000@ha # CHECK-NEXT: ] # CHECK-NEXT: Address: 0x0 # CHECK-NEXT: Offset: -# CHECK-NEXT: Size: 32 +# CHECK-NEXT: Size: 40 # CHECK-NEXT: Link: 0 # CHECK-NEXT: Info: 0 # CHECK-NEXT: AddressAlignment: 4 @@ -57,6 +62,7 @@ addis 1, 1, target5+0x8000@ha # CHECK-NEXT: SectionData ( # CHECK-NEXT: 0000: 38211234 3C211234 38215678 3C211234 # CHECK-NEXT: 0010: 38214444 3C211111 38218001 3C211001 +# CHECK-NEXT: 0020: 38210008 3C210000 # CHECK-NEXT: ) # CHECK-NEXT: }