[llvm-commits] [llvm] r111934 - in /llvm/trunk: lib/MC/MCParser/AsmParser.cpp test/MC/AsmParser/dollars-in-identifiers.s
Daniel Dunbar
daniel at zuster.org
Tue Aug 24 11:12:12 PDT 2010
Author: ddunbar
Date: Tue Aug 24 13:12:12 2010
New Revision: 111934
URL: http://llvm.org/viewvc/llvm-project?rev=111934&view=rev
Log:
MC/Parser: Accept leading dollar signs in identifiers.
- Implemented by manually splicing the tokens. If this turns out to be
problematically platform specific, a more elegant solution would be to
implement some context dependent lexing support.
Added:
llvm/trunk/test/MC/AsmParser/dollars-in-identifiers.s
Modified:
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=111934&r1=111933&r2=111934&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Aug 24 13:12:12 2010
@@ -1127,6 +1127,30 @@
/// ::= identifier
/// ::= string
bool AsmParser::ParseIdentifier(StringRef &Res) {
+ // The assembler has relaxed rules for accepting identifiers, in particular we
+ // allow things like '.globl $foo', which would normally be separate
+ // tokens. At this level, we have already lexed so we cannot (currently)
+ // handle this as a context dependent token, instead we detect adjacent tokens
+ // and return the combined identifier.
+ if (Lexer.is(AsmToken::Dollar)) {
+ SMLoc DollarLoc = getLexer().getLoc();
+
+ // Consume the dollar sign, and check for a following identifier.
+ Lex();
+ if (Lexer.isNot(AsmToken::Identifier))
+ return true;
+
+ // We have a '$' followed by an identifier, make sure they are adjacent.
+ if (DollarLoc.getPointer() + 1 != getTok().getLoc().getPointer())
+ return true;
+
+ // Construct the joined identifier and consume the token.
+ Res = StringRef(DollarLoc.getPointer(),
+ getTok().getIdentifier().size() + 1);
+ Lex();
+ return false;
+ }
+
if (Lexer.isNot(AsmToken::Identifier) &&
Lexer.isNot(AsmToken::String))
return true;
Added: llvm/trunk/test/MC/AsmParser/dollars-in-identifiers.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/dollars-in-identifiers.s?rev=111934&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/dollars-in-identifiers.s (added)
+++ llvm/trunk/test/MC/AsmParser/dollars-in-identifiers.s Tue Aug 24 13:12:12 2010
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s > %t
+# RUN: FileCheck < %t %s
+
+// CHECK: .globl $foo
+.globl $foo
More information about the llvm-commits
mailing list