LLVM  13.0.0git
MCAsmLexer.cpp
Go to the documentation of this file.
1 //===- MCAsmLexer.cpp - Abstract Asm Lexer Interface ----------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/Support/SMLoc.h"
12 #include "llvm/Support/Debug.h"
14 
15 using namespace llvm;
16 
18  CurTok.emplace_back(AsmToken::Space, StringRef());
19 }
20 
21 MCAsmLexer::~MCAsmLexer() = default;
22 
25 }
26 
28  return SMLoc::getFromPointer(Str.data());
29 }
30 
32  return SMLoc::getFromPointer(Str.data() + Str.size());
33 }
34 
36  return SMRange(getLoc(), getEndLoc());
37 }
38 
39 void AsmToken::dump(raw_ostream &OS) const {
40  switch (Kind) {
41  case AsmToken::Error:
42  OS << "error";
43  break;
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;
87  case AsmToken::MinusGreater: OS << "MinusGreater"; break;
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 }
llvm::AsmToken::PercentPcrel_Lo
@ PercentPcrel_Lo
Definition: MCAsmMacro.h:61
llvm
Definition: AllocatorList.h:23
llvm::AsmToken::PercentGottprel
@ PercentGottprel
Definition: MCAsmMacro.h:59
llvm::AsmToken::PercentNeg
@ PercentNeg
Definition: MCAsmMacro.h:60
llvm::AsmToken::LBrac
@ LBrac
Definition: MCAsmMacro.h:48
StringRef.h
llvm::AsmToken::Dot
@ Dot
Definition: MCAsmMacro.h:49
llvm::AsmToken::EndOfStatement
@ EndOfStatement
Definition: MCAsmMacro.h:42
llvm::AsmToken::Eof
@ Eof
Definition: MCAsmMacro.h:25
llvm::raw_ostream::write_escaped
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
Definition: raw_ostream.cpp:163
llvm::AsmToken::PercentPcrel_Hi
@ PercentPcrel_Hi
Definition: MCAsmMacro.h:60
llvm::AsmToken::PercentHi
@ PercentHi
Definition: MCAsmMacro.h:59
llvm::AsmToken::Integer
@ Integer
Definition: MCAsmMacro.h:32
llvm::AsmToken::PercentTlsldm
@ PercentTlsldm
Definition: MCAsmMacro.h:61
llvm::AsmToken::ExclaimEqual
@ ExclaimEqual
Definition: MCAsmMacro.h:52
llvm::AsmToken::Minus
@ Minus
Definition: MCAsmMacro.h:45
llvm::AsmToken::LParen
@ LParen
Definition: MCAsmMacro.h:48
llvm::MCAsmLexer::~MCAsmLexer
virtual ~MCAsmLexer()
llvm::AsmToken::Dollar
@ Dollar
Definition: MCAsmMacro.h:49
llvm::AsmToken::PercentGot_Page
@ PercentGot_Page
Definition: MCAsmMacro.h:59
llvm::AsmToken::PercentCall16
@ PercentCall16
Definition: MCAsmMacro.h:57
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::AsmToken::GreaterGreater
@ GreaterGreater
Definition: MCAsmMacro.h:54
llvm::AsmToken::BackSlash
@ BackSlash
Definition: MCAsmMacro.h:47
llvm::AsmToken::PercentTprel_Hi
@ PercentTprel_Hi
Definition: MCAsmMacro.h:61
llvm::AsmToken::Star
@ Star
Definition: MCAsmMacro.h:49
SMLoc.h
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::AsmToken::MinusGreater
@ MinusGreater
Definition: MCAsmMacro.h:54
llvm::AsmToken::dump
void dump(raw_ostream &OS) const
Definition: MCAsmLexer.cpp:39
llvm::AsmToken::Percent
@ Percent
Definition: MCAsmMacro.h:52
llvm::MCAsmLexer::MCAsmLexer
MCAsmLexer()
Definition: MCAsmLexer.cpp:17
llvm::AsmToken::PercentDtprel_Lo
@ PercentDtprel_Lo
Definition: MCAsmMacro.h:58
llvm::AsmToken::HashDirective
@ HashDirective
Definition: MCAsmMacro.h:40
llvm::AsmToken::Error
@ Error
Definition: MCAsmMacro.h:25
llvm::AsmToken::PercentDtprel_Hi
@ PercentDtprel_Hi
Definition: MCAsmMacro.h:57
llvm::AsmToken::Equal
@ Equal
Definition: MCAsmMacro.h:49
MCAsmLexer.h
llvm::AsmToken::Greater
@ Greater
Definition: MCAsmMacro.h:54
llvm::AsmToken::PercentLo
@ PercentLo
Definition: MCAsmMacro.h:60
llvm::MCAsmLexer::getLoc
SMLoc getLoc() const
Get the current source location.
Definition: MCAsmLexer.cpp:23
llvm::AsmToken::At
@ At
Definition: MCAsmMacro.h:54
llvm::AsmToken::AmpAmp
@ AmpAmp
Definition: MCAsmMacro.h:52
llvm::AsmToken::Colon
@ Colon
Definition: MCAsmMacro.h:43
llvm::AsmToken::PercentGot_Hi
@ PercentGot_Hi
Definition: MCAsmMacro.h:58
llvm::AsmToken::BigNum
@ BigNum
Definition: MCAsmMacro.h:33
llvm::AsmToken::Slash
@ Slash
Definition: MCAsmMacro.h:46
llvm::AsmToken::Exclaim
@ Exclaim
Definition: MCAsmMacro.h:52
llvm::AsmToken::Amp
@ Amp
Definition: MCAsmMacro.h:52
llvm::AsmToken::PercentTlsgd
@ PercentTlsgd
Definition: MCAsmMacro.h:61
llvm::AsmToken::PercentHighest
@ PercentHighest
Definition: MCAsmMacro.h:60
llvm::AsmToken::EqualEqual
@ EqualEqual
Definition: MCAsmMacro.h:49
llvm::AsmToken::PercentGp_Rel
@ PercentGp_Rel
Definition: MCAsmMacro.h:59
llvm::AsmToken::Less
@ Less
Definition: MCAsmMacro.h:53
llvm::AsmToken::Comma
@ Comma
Definition: MCAsmMacro.h:49
llvm::AsmToken::PercentCall_Lo
@ PercentCall_Lo
Definition: MCAsmMacro.h:57
llvm::AsmToken::GreaterEqual
@ GreaterEqual
Definition: MCAsmMacro.h:54
llvm::AsmToken::PercentTprel_Lo
@ PercentTprel_Lo
Definition: MCAsmMacro.h:62
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AsmToken::Plus
@ Plus
Definition: MCAsmMacro.h:45
llvm::AsmToken::Space
@ Space
Definition: MCAsmMacro.h:44
llvm::AsmToken::RParen
@ RParen
Definition: MCAsmMacro.h:48
llvm::AsmToken::LessLess
@ LessLess
Definition: MCAsmMacro.h:53
llvm::AsmToken::getString
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
Definition: MCAsmMacro.h:110
llvm::AsmToken::LessGreater
@ LessGreater
Definition: MCAsmMacro.h:53
llvm::AsmToken::Pipe
@ Pipe
Definition: MCAsmMacro.h:51
llvm::MCAsmLexer::TokStart
const char * TokStart
Definition: MCAsmLexer.h:48
llvm::AsmToken::PercentGot_Ofst
@ PercentGot_Ofst
Definition: MCAsmMacro.h:59
llvm::AsmToken::Tilde
@ Tilde
Definition: MCAsmMacro.h:45
llvm::AsmToken::Real
@ Real
Definition: MCAsmMacro.h:36
llvm::AsmToken::Identifier
@ Identifier
Definition: MCAsmMacro.h:28
llvm::AsmToken::RBrac
@ RBrac
Definition: MCAsmMacro.h:48
llvm::AsmToken::PercentCall_Hi
@ PercentCall_Hi
Definition: MCAsmMacro.h:57
llvm::AsmToken::PipePipe
@ PipePipe
Definition: MCAsmMacro.h:51
llvm::AsmToken::getLocRange
SMRange getLocRange() const
Definition: MCAsmLexer.cpp:35
llvm::AsmToken::Caret
@ Caret
Definition: MCAsmMacro.h:51
llvm::SMRange
Represents a range in source code.
Definition: SMLoc.h:48
llvm::AsmToken::LessEqual
@ LessEqual
Definition: MCAsmMacro.h:53
llvm::AsmToken::LCurly
@ LCurly
Definition: MCAsmMacro.h:48
llvm::StringRef::data
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:149
llvm::SMLoc::getFromPointer
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:36
llvm::AsmToken::PercentGot
@ PercentGot
Definition: MCAsmMacro.h:58
llvm::AsmToken::String
@ String
Definition: MCAsmMacro.h:29
llvm::AsmToken::RCurly
@ RCurly
Definition: MCAsmMacro.h:48
raw_ostream.h
llvm::AsmToken::Hash
@ Hash
Definition: MCAsmMacro.h:52
llvm::StringRef::size
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
llvm::AsmToken::PercentGot_Disp
@ PercentGot_Disp
Definition: MCAsmMacro.h:58
llvm::AsmToken::getLoc
SMLoc getLoc() const
Definition: MCAsmLexer.cpp:27
llvm::AsmToken::getEndLoc
SMLoc getEndLoc() const
Definition: MCAsmLexer.cpp:31
llvm::AsmToken::PercentHigher
@ PercentHigher
Definition: MCAsmMacro.h:60
llvm::AsmToken::PercentGot_Lo
@ PercentGot_Lo
Definition: MCAsmMacro.h:58
Debug.h
llvm::AsmToken::Comment
@ Comment
Definition: MCAsmMacro.h:39