From 851f87c6c98af936ba68c5ca8962df3832f8a5fc Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 5 May 2010 23:51:28 +0000 Subject: [PATCH] fix rdar://7946934 - in some limited cases, the assembler should allow $ at the start of a symbol name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103137 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCParser/AsmLexer.cpp | 23 ++++++++++++++++------- test/MC/AsmParser/X86/x86_operands.s | 4 +--- test/MC/AsmParser/labels.s | 7 +++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/MC/MCParser/AsmLexer.cpp b/lib/MC/MCParser/AsmLexer.cpp index 11833127848..f157a896091 100644 --- a/lib/MC/MCParser/AsmLexer.cpp +++ b/lib/MC/MCParser/AsmLexer.cpp @@ -69,16 +69,26 @@ int AsmLexer::getNextChar() { } } -/// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* +/// LexIdentifier: [a-zA-Z_.$][a-zA-Z0-9_$.@]* +/// LexIdentifier: . +/// LexIdentifier: $ AsmToken AsmLexer::LexIdentifier() { while (isalnum(*CurPtr) || *CurPtr == '_' || *CurPtr == '$' || *CurPtr == '.' || *CurPtr == '@') ++CurPtr; // Handle . as a special case. - if (CurPtr == TokStart+1 && TokStart[0] == '.') - return AsmToken(AsmToken::Dot, StringRef(TokStart, 1)); - + if (CurPtr == TokStart+1) + if (TokStart[0] == '.') + return AsmToken(AsmToken::Dot, StringRef(TokStart, 1)); + + // Handle $ as a special case. $foo is an identifier, $42 is not. + if (TokStart[0] == '$' && + (CurPtr-TokStart == 1 || isdigit(TokStart[1]) || TokStart[1] == '"')) { + CurPtr = TokStart+1; + return AsmToken(AsmToken::Dollar, StringRef(TokStart, 1)); + } + return AsmToken(AsmToken::Identifier, StringRef(TokStart, CurPtr - TokStart)); } @@ -252,8 +262,8 @@ AsmToken AsmLexer::LexToken() { switch (CurChar) { default: - // Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]* - if (isalpha(CurChar) || CurChar == '_' || CurChar == '.') + // Handle identifier: [a-zA-Z_.$][a-zA-Z0-9_$.@]* + if (isalpha(CurChar) || CurChar == '_' || CurChar == '.' || CurChar == '$') return LexIdentifier(); // Unknown character, emit an error. @@ -279,7 +289,6 @@ AsmToken AsmLexer::LexToken() { case '}': return AsmToken(AsmToken::RCurly, StringRef(TokStart, 1)); case '*': return AsmToken(AsmToken::Star, StringRef(TokStart, 1)); case ',': return AsmToken(AsmToken::Comma, StringRef(TokStart, 1)); - case '$': return AsmToken(AsmToken::Dollar, StringRef(TokStart, 1)); case '=': if (*CurPtr == '=') return ++CurPtr, AsmToken(AsmToken::EqualEqual, StringRef(TokStart, 2)); diff --git a/test/MC/AsmParser/X86/x86_operands.s b/test/MC/AsmParser/X86/x86_operands.s index bf958d8478c..cd54a0bb0f6 100644 --- a/test/MC/AsmParser/X86/x86_operands.s +++ b/test/MC/AsmParser/X86/x86_operands.s @@ -1,5 +1,3 @@ -// FIXME: Actually test that we get the expected results. - // RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # Immediates @@ -7,7 +5,7 @@ addl $1, %eax # CHECK: addl $3, %eax addl $(1+2), %eax -# CHECK: addl $a, %eax +# CHECK: addl ($a), %eax addl $a, %eax # CHECK: addl $3, %eax addl $1 + 2, %eax diff --git a/test/MC/AsmParser/labels.s b/test/MC/AsmParser/labels.s index 3bc7e630ce4..c5a064fce25 100644 --- a/test/MC/AsmParser/labels.s +++ b/test/MC/AsmParser/labels.s @@ -57,3 +57,10 @@ foo: // CHECK: .long "a 9" .long "a 9" + + +// rdar://7946934 +// CHECK: .globl $abc + .globl $abc + + \ No newline at end of file