diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-07-21 21:23:08 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-07-21 21:23:08 +0000 |
commit | c1fbb3540a22c64b0afcfb3c2e99171ae7b13414 (patch) | |
tree | 0f5105622e9e8f702918713678ac2cf836cdb2db /llvm/lib/CodeGen/MIRParser/MILexer.cpp | |
parent | 2bf2cadc005edda3c56e5bcf960d43170b5f79e1 (diff) | |
download | bcm5719-llvm-c1fbb3540a22c64b0afcfb3c2e99171ae7b13414.tar.gz bcm5719-llvm-c1fbb3540a22c64b0afcfb3c2e99171ae7b13414.zip |
MIR Parser: Reuse the function 'lexName' when lexing global value tokens. NFC.
This commit refactors the function 'maybeLexGlobalValue' so that now it reuses
the function 'lexName' when lexing a named global value token.
llvm-svn: 242837
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser/MILexer.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.cpp | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index 2a1caab5794..ab9dff8632e 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -240,37 +240,6 @@ static Cursor maybeLexRegister(Cursor C, MIToken &Token) { return C; } -static Cursor maybeLexGlobalValue( - Cursor C, MIToken &Token, - function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { - if (C.peek() != '@') - return None; - auto Range = C; - C.advance(); // Skip the '@' - if (C.peek() == '"') { - if (Cursor R = lexStringConstant(C, ErrorCallback)) { - Token = MIToken(MIToken::QuotedNamedGlobalValue, Range.upto(R), - /*StringOffset=*/1); // Drop the '@' - return R; - } - Token = MIToken(MIToken::Error, Range.remaining()); - return Range; - } - if (!isdigit(C.peek())) { - while (isIdentifierChar(C.peek())) - C.advance(); - Token = MIToken(MIToken::NamedGlobalValue, Range.upto(C), - /*StringOffset=*/1); // Drop the '@' - return C; - } - auto NumberRange = C; - while (isdigit(C.peek())) - C.advance(); - Token = - MIToken(MIToken::GlobalValue, Range.upto(C), APSInt(NumberRange.upto(C))); - return C; -} - static Cursor lexName( Cursor C, MIToken &Token, MIToken::TokenKind Type, MIToken::TokenKind QuotedType, unsigned PrefixLength, @@ -291,6 +260,25 @@ static Cursor lexName( return C; } +static Cursor maybeLexGlobalValue( + Cursor C, MIToken &Token, + function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { + if (C.peek() != '@') + return None; + if (!isdigit(C.peek(1))) + return lexName(C, Token, MIToken::NamedGlobalValue, + MIToken::QuotedNamedGlobalValue, /*PrefixLength=*/1, + ErrorCallback); + auto Range = C; + C.advance(1); // Skip the '@' + auto NumberRange = C; + while (isdigit(C.peek())) + C.advance(); + Token = + MIToken(MIToken::GlobalValue, Range.upto(C), APSInt(NumberRange.upto(C))); + return C; +} + static Cursor maybeLexExternalSymbol( Cursor C, MIToken &Token, function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { |