Eugene Zelenko | 4b6ff6b | 2017-02-10 01:33:54 +0000 | [diff] [blame] | 1 | //===- MCAsmLexer.cpp - Abstract Asm Lexer Interface ----------------------===// |
Daniel Dunbar | 2b11c7d | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Daniel Dunbar | 2b11c7d | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Chris Lattner | 00646cf | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 9 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 10 | #include "llvm/ADT/StringRef.h" |
Eugene Zelenko | 4b6ff6b | 2017-02-10 01:33:54 +0000 | [diff] [blame] | 11 | #include "llvm/Support/SMLoc.h" |
Oliver Stannard | 5c032ce | 2018-03-06 14:02:14 +0000 | [diff] [blame] | 12 | #include "llvm/Support/Debug.h" |
| 13 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 2b11c7d | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace llvm; |
| 16 | |
Craig Topper | c81aff7 | 2018-09-25 20:55:55 +0000 | [diff] [blame] | 17 | MCAsmLexer::MCAsmLexer() { |
Nirav Dave | 1180e689 | 2016-06-02 17:15:05 +0000 | [diff] [blame] | 18 | CurTok.emplace_back(AsmToken::Space, StringRef()); |
Daniel Dunbar | 2b11c7d | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Eugene Zelenko | 4b6ff6b | 2017-02-10 01:33:54 +0000 | [diff] [blame] | 21 | MCAsmLexer::~MCAsmLexer() = default; |
Daniel Dunbar | cbf4faf | 2009-08-14 02:18:40 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | 4042c33 | 2010-07-12 17:10:00 +0000 | [diff] [blame] | 23 | SMLoc MCAsmLexer::getLoc() const { |
| 24 | return SMLoc::getFromPointer(TokStart); |
| 25 | } |
| 26 | |
Daniel Dunbar | cbf4faf | 2009-08-14 02:18:40 +0000 | [diff] [blame] | 27 | SMLoc AsmToken::getLoc() const { |
| 28 | return SMLoc::getFromPointer(Str.data()); |
| 29 | } |
Benjamin Kramer | 1930b00 | 2011-10-16 12:10:27 +0000 | [diff] [blame] | 30 | |
| 31 | SMLoc AsmToken::getEndLoc() const { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 32 | return SMLoc::getFromPointer(Str.data() + Str.size()); |
Benjamin Kramer | 1930b00 | 2011-10-16 12:10:27 +0000 | [diff] [blame] | 33 | } |
Daniel Sanders | ef638fe | 2014-10-03 15:37:37 +0000 | [diff] [blame] | 34 | |
| 35 | SMRange AsmToken::getLocRange() const { |
| 36 | return SMRange(getLoc(), getEndLoc()); |
| 37 | } |
Oliver Stannard | 5c032ce | 2018-03-06 14:02:14 +0000 | [diff] [blame] | 38 | |
| 39 | void AsmToken::dump(raw_ostream &OS) const { |
| 40 | switch (Kind) { |
| 41 | case AsmToken::Error: |
| 42 | OS << "error"; |
| 43 | break; |
| 44 | case AsmToken::Identifier: |
| 45 | OS << "identifier: " << getString(); |
| 46 | break; |
| 47 | case AsmToken::Integer: |
| 48 | OS << "int: " << getString(); |
| 49 | break; |
| 50 | case AsmToken::Real: |
| 51 | OS << "real: " << getString(); |
| 52 | break; |
| 53 | case AsmToken::String: |
| 54 | OS << "string: " << getString(); |
| 55 | break; |
| 56 | |
| 57 | case AsmToken::Amp: OS << "Amp"; break; |
| 58 | case AsmToken::AmpAmp: OS << "AmpAmp"; break; |
| 59 | case AsmToken::At: OS << "At"; break; |
| 60 | case AsmToken::BackSlash: OS << "BackSlash"; break; |
| 61 | case AsmToken::BigNum: OS << "BigNum"; break; |
| 62 | case AsmToken::Caret: OS << "Caret"; break; |
| 63 | case AsmToken::Colon: OS << "Colon"; break; |
| 64 | case AsmToken::Comma: OS << "Comma"; break; |
| 65 | case AsmToken::Comment: OS << "Comment"; break; |
| 66 | case AsmToken::Dollar: OS << "Dollar"; break; |
| 67 | case AsmToken::Dot: OS << "Dot"; break; |
| 68 | case AsmToken::EndOfStatement: OS << "EndOfStatement"; break; |
| 69 | case AsmToken::Eof: OS << "Eof"; break; |
| 70 | case AsmToken::Equal: OS << "Equal"; break; |
| 71 | case AsmToken::EqualEqual: OS << "EqualEqual"; break; |
| 72 | case AsmToken::Exclaim: OS << "Exclaim"; break; |
| 73 | case AsmToken::ExclaimEqual: OS << "ExclaimEqual"; break; |
| 74 | case AsmToken::Greater: OS << "Greater"; break; |
| 75 | case AsmToken::GreaterEqual: OS << "GreaterEqual"; break; |
| 76 | case AsmToken::GreaterGreater: OS << "GreaterGreater"; break; |
| 77 | case AsmToken::Hash: OS << "Hash"; break; |
| 78 | case AsmToken::HashDirective: OS << "HashDirective"; break; |
| 79 | case AsmToken::LBrac: OS << "LBrac"; break; |
| 80 | case AsmToken::LCurly: OS << "LCurly"; break; |
| 81 | case AsmToken::LParen: OS << "LParen"; break; |
| 82 | case AsmToken::Less: OS << "Less"; break; |
| 83 | case AsmToken::LessEqual: OS << "LessEqual"; break; |
| 84 | case AsmToken::LessGreater: OS << "LessGreater"; break; |
| 85 | case AsmToken::LessLess: OS << "LessLess"; break; |
| 86 | case AsmToken::Minus: OS << "Minus"; break; |
Wouter van Oortmerssen | 49482f8 | 2018-11-19 17:10:36 +0000 | [diff] [blame] | 87 | case AsmToken::MinusGreater: OS << "MinusGreater"; break; |
Oliver Stannard | 5c032ce | 2018-03-06 14:02:14 +0000 | [diff] [blame] | 88 | case AsmToken::Percent: OS << "Percent"; break; |
| 89 | case AsmToken::Pipe: OS << "Pipe"; break; |
| 90 | case AsmToken::PipePipe: OS << "PipePipe"; break; |
| 91 | case AsmToken::Plus: OS << "Plus"; break; |
| 92 | case AsmToken::RBrac: OS << "RBrac"; break; |
| 93 | case AsmToken::RCurly: OS << "RCurly"; break; |
| 94 | case AsmToken::RParen: OS << "RParen"; break; |
| 95 | case AsmToken::Slash: OS << "Slash"; break; |
| 96 | case AsmToken::Space: OS << "Space"; break; |
| 97 | case AsmToken::Star: OS << "Star"; break; |
| 98 | case AsmToken::Tilde: OS << "Tilde"; break; |
| 99 | case AsmToken::PercentCall16: OS << "PercentCall16"; break; |
| 100 | case AsmToken::PercentCall_Hi: OS << "PercentCall_Hi"; break; |
| 101 | case AsmToken::PercentCall_Lo: OS << "PercentCall_Lo"; break; |
| 102 | case AsmToken::PercentDtprel_Hi: OS << "PercentDtprel_Hi"; break; |
| 103 | case AsmToken::PercentDtprel_Lo: OS << "PercentDtprel_Lo"; break; |
| 104 | case AsmToken::PercentGot: OS << "PercentGot"; break; |
| 105 | case AsmToken::PercentGot_Disp: OS << "PercentGot_Disp"; break; |
| 106 | case AsmToken::PercentGot_Hi: OS << "PercentGot_Hi"; break; |
| 107 | case AsmToken::PercentGot_Lo: OS << "PercentGot_Lo"; break; |
| 108 | case AsmToken::PercentGot_Ofst: OS << "PercentGot_Ofst"; break; |
| 109 | case AsmToken::PercentGot_Page: OS << "PercentGot_Page"; break; |
| 110 | case AsmToken::PercentGottprel: OS << "PercentGottprel"; break; |
| 111 | case AsmToken::PercentGp_Rel: OS << "PercentGp_Rel"; break; |
| 112 | case AsmToken::PercentHi: OS << "PercentHi"; break; |
| 113 | case AsmToken::PercentHigher: OS << "PercentHigher"; break; |
| 114 | case AsmToken::PercentHighest: OS << "PercentHighest"; break; |
| 115 | case AsmToken::PercentLo: OS << "PercentLo"; break; |
| 116 | case AsmToken::PercentNeg: OS << "PercentNeg"; break; |
| 117 | case AsmToken::PercentPcrel_Hi: OS << "PercentPcrel_Hi"; break; |
| 118 | case AsmToken::PercentPcrel_Lo: OS << "PercentPcrel_Lo"; break; |
| 119 | case AsmToken::PercentTlsgd: OS << "PercentTlsgd"; break; |
| 120 | case AsmToken::PercentTlsldm: OS << "PercentTlsldm"; break; |
| 121 | case AsmToken::PercentTprel_Hi: OS << "PercentTprel_Hi"; break; |
| 122 | case AsmToken::PercentTprel_Lo: OS << "PercentTprel_Lo"; break; |
| 123 | } |
| 124 | |
| 125 | // Print the token string. |
| 126 | OS << " (\""; |
| 127 | OS.write_escaped(getString()); |
| 128 | OS << "\")"; |
| 129 | } |