diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-09-25 10:47:21 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-09-25 10:47:21 +0000 |
commit | 3f22cc1df64a6dd6a3ecc5e7e261f15af083f806 (patch) | |
tree | 22cf719d9177fb9d16b1c632e98ba7ed7330f217 /lib/MC | |
parent | 76f8ae87b4705f5c08c3995948223531715a2d58 (diff) | |
download | external_llvm-3f22cc1df64a6dd6a3ecc5e7e261f15af083f806.zip external_llvm-3f22cc1df64a6dd6a3ecc5e7e261f15af083f806.tar.gz external_llvm-3f22cc1df64a6dd6a3ecc5e7e261f15af083f806.tar.bz2 |
MC: Add support for treating $ as a reference to the PC
The binutils assembler supports a mode called DOLLAR_DOT which treats
the dollar sign token as a reference to the current program counter if
the dollar sign doesn't precede a constant or identifier.
This commit adds a new MCAsmInfo flag stating whether or not a given
target supports this interpretation of the dollar sign token; by
default, this flag is not enabled.
Further, enable this flag for PPC. The system assembler for AIX and
binutils both support using the dollar sign in this manner.
This fixes PR17353.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191368 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r-- | lib/MC/MCAsmInfo.cpp | 1 | ||||
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 16 |
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/MC/MCAsmInfo.cpp b/lib/MC/MCAsmInfo.cpp index 73dc74a..152aae1 100644 --- a/lib/MC/MCAsmInfo.cpp +++ b/lib/MC/MCAsmInfo.cpp @@ -35,6 +35,7 @@ MCAsmInfo::MCAsmInfo() { LinkerRequiresNonEmptyDwarfLines = false; MaxInstLength = 4; MinInstAlignment = 1; + DollarIsPC = false; SeparatorString = ";"; CommentColumn = 40; CommentString = "#"; diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 1267dc8..21cbd34 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -772,9 +772,19 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) { case AsmToken::Identifier: { StringRef Identifier; if (parseIdentifier(Identifier)) { - if (FirstTokenKind == AsmToken::Dollar) - return Error(FirstTokenLoc, "invalid token in expression"); - return true; + if (FirstTokenKind == AsmToken::Dollar) { + if (Lexer.getMAI().getDollarIsPC()) { + // This is a '$' reference, which references the current PC. Emit a + // temporary label to the streamer and refer to it. + MCSymbol *Sym = Ctx.CreateTempSymbol(); + Out.EmitLabel(Sym); + Res = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None, getContext()); + EndLoc = FirstTokenLoc; + return false; + } else + return Error(FirstTokenLoc, "invalid token in expression"); + return true; + } } EndLoc = SMLoc::getFromPointer(Identifier.end()); |