LLVM  14.0.0git
MCAsmParser.cpp
Go to the documentation of this file.
1 //===-- MCAsmParser.cpp - Abstract Asm Parser 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/ADT/Twine.h"
12 #include "llvm/Config/llvm-config.h"
17 #include "llvm/Support/Debug.h"
18 #include "llvm/Support/SMLoc.h"
20 #include <cassert>
21 
22 using namespace llvm;
23 
25  "asm-macro-max-nesting-depth", cl::init(20), cl::Hidden,
26  cl::desc("The maximum nesting depth allowed for assembly macros."));
27 
29 
30 MCAsmParser::~MCAsmParser() = default;
31 
33  assert(!TargetParser && "Target parser is already initialized!");
34  TargetParser = &P;
35  TargetParser->Initialize(*this);
36 }
37 
38 const AsmToken &MCAsmParser::getTok() const {
39  return getLexer().getTok();
40 }
41 
43  Loc = getTok().getLoc();
44  return false;
45 }
46 
48  if (getTok().getKind() != AsmToken::EndOfStatement)
49  return Error(getTok().getLoc(), "expected newline");
50  Lex();
51  return false;
52 }
53 
54 bool MCAsmParser::parseEOL(const Twine &Msg) {
55  if (getTok().getKind() != AsmToken::EndOfStatement)
56  return Error(getTok().getLoc(), Msg);
57  Lex();
58  return false;
59 }
60 
63  return parseEOL(Msg);
64  if (getTok().getKind() != T)
65  return Error(getTok().getLoc(), Msg);
66  Lex();
67  return false;
68 }
69 
70 bool MCAsmParser::parseIntToken(int64_t &V, const Twine &Msg) {
71  if (getTok().getKind() != AsmToken::Integer)
72  return TokError(Msg);
73  V = getTok().getIntVal();
74  Lex();
75  return false;
76 }
77 
79  bool Present = (getTok().getKind() == T);
80  if (Present)
81  parseToken(T);
82  return Present;
83 }
84 
85 bool MCAsmParser::check(bool P, const Twine &Msg) {
86  return check(P, getTok().getLoc(), Msg);
87 }
88 
89 bool MCAsmParser::check(bool P, SMLoc Loc, const Twine &Msg) {
90  if (P)
91  return Error(Loc, Msg);
92  return false;
93 }
94 
95 bool MCAsmParser::TokError(const Twine &Msg, SMRange Range) {
96  return Error(getLexer().getLoc(), Msg, Range);
97 }
98 
99 bool MCAsmParser::Error(SMLoc L, const Twine &Msg, SMRange Range) {
100 
101  MCPendingError PErr;
102  PErr.Loc = L;
103  Msg.toVector(PErr.Msg);
104  PErr.Range = Range;
105  PendingErrors.push_back(PErr);
106 
107  // If we threw this parsing error after a lexing error, this should
108  // supercede the lexing error and so we remove it from the Lexer
109  // before it can propagate
110  if (getTok().is(AsmToken::Error))
111  getLexer().Lex();
112  return true;
113 }
114 
115 bool MCAsmParser::addErrorSuffix(const Twine &Suffix) {
116  // Make sure lexing errors have propagated to the parser.
117  if (getTok().is(AsmToken::Error))
118  Lex();
119  for (auto &PErr : PendingErrors)
120  Suffix.toVector(PErr.Msg);
121  return true;
122 }
123 
124 bool MCAsmParser::parseMany(function_ref<bool()> parseOne, bool hasComma) {
126  return false;
127  while (true) {
128  if (parseOne())
129  return true;
131  return false;
132  if (hasComma && parseToken(AsmToken::Comma))
133  return true;
134  }
135  return false;
136 }
137 
139  SMLoc L;
140  return parseExpression(Res, L);
141 }
142 
144  int64_t &IntegerValue) {
145  // Parse a .gnu_attribute with numerical tag and value.
146  StringRef S(L.getPointer());
147  SMLoc TagLoc;
148  TagLoc = getTok().getLoc();
149  const AsmToken &Tok = getTok();
150  if (Tok.isNot(AsmToken::Integer))
151  return false;
152  Tag = Tok.getIntVal();
153  Lex(); // Eat the Tag
154  Lex(); // Eat the comma
155  if (Tok.isNot(AsmToken::Integer))
156  return false;
157  IntegerValue = Tok.getIntVal();
158  Lex(); // Eat the IntegerValue
159  return true;
160 }
161 
163  // Cannot completely remove virtual function even in release mode.
164 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
165  dbgs() << " " << *this;
166 #endif
167 }
is
should just be implemented with a CLZ instruction Since there are other e that share this it would be best to implement this in a target independent as zero is the default value for the binary encoder e add r0 add r5 Register operands should be distinct That is
Definition: README.txt:725
llvm::MCAsmParser::Error
bool Error(SMLoc L, const Twine &Msg, SMRange Range=None)
Return an error at the location L, with the message Msg.
Definition: MCAsmParser.cpp:99
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
AsmMacroMaxNestingDepth
cl::opt< unsigned > AsmMacroMaxNestingDepth("asm-macro-max-nesting-depth", cl::init(20), cl::Hidden, cl::desc("The maximum nesting depth allowed for assembly macros."))
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::AsmToken::EndOfStatement
@ EndOfStatement
Definition: MCAsmMacro.h:42
llvm::MCAsmParser::parseEOL
bool parseEOL()
Definition: MCAsmParser.cpp:47
llvm::AsmToken::getIntVal
int64_t getIntVal() const
Definition: MCAsmMacro.h:115
MCParsedAsmOperand.h
llvm::MCAsmLexer::getTok
const AsmToken & getTok() const
Get the current (last) lexed token.
Definition: MCAsmLexer.h:108
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::AsmToken::Integer
@ Integer
Definition: MCAsmMacro.h:32
llvm::MCAsmParser::parseOptionalToken
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
Definition: MCAsmParser.cpp:78
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::MCAsmParser::~MCAsmParser
virtual ~MCAsmParser()
llvm::MCAsmLexer::Lex
const AsmToken & Lex()
Consume the next token from the input stream and return it.
Definition: MCAsmLexer.h:81
MCAsmParser.h
llvm::MCAsmParser::MCPendingError
Definition: MCAsmParser.h:130
MCTargetAsmParser.h
llvm::MCParsedAsmOperand::dump
virtual void dump() const
dump - Print to the debug stream.
Definition: MCAsmParser.cpp:162
llvm::AsmToken
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:21
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
CommandLine.h
llvm::MCAsmParser::Lex
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
llvm::MCAsmParser::parseExpression
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
Twine.h
llvm::MCAsmParser::parseIntToken
bool parseIntToken(int64_t &V, const Twine &ErrMsg)
Definition: MCAsmParser.cpp:70
llvm::MCAsmParser::PendingErrors
SmallVector< MCPendingError, 0 > PendingErrors
Definition: MCAsmParser.h:142
SMLoc.h
llvm::AsmToken::getKind
TokenKind getKind() const
Definition: MCAsmMacro.h:81
llvm::MCAsmParser::MCPendingError::Range
SMRange Range
Definition: MCAsmParser.h:133
llvm::AsmToken::Error
@ Error
Definition: MCAsmMacro.h:25
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
llvm::cl::opt
Definition: CommandLine.h:1422
MCAsmLexer.h
llvm::MCAsmParser::addErrorSuffix
bool addErrorSuffix(const Twine &Suffix)
Definition: MCAsmParser.cpp:115
llvm::MCAsmParser::parseMany
bool parseMany(function_ref< bool()> parseOne, bool hasComma=true)
Definition: MCAsmParser.cpp:124
llvm::MCAsmParserExtension::Initialize
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
Definition: MCAsmParserExtension.cpp:19
llvm::Twine::toVector
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Definition: Twine.cpp:32
llvm::MCAsmParser::check
bool check(bool P, const Twine &Msg)
Definition: MCAsmParser.cpp:85
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::MCAsmParser::MCPendingError::Loc
SMLoc Loc
Definition: MCAsmParser.h:131
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AsmToken::Comma
@ Comma
Definition: MCAsmMacro.h:49
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCAsmParser::getTok
const AsmToken & getTok() const
Get the current AsmToken from the stream.
Definition: MCAsmParser.cpp:38
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::AsmToken::isNot
bool isNot(TokenKind K) const
Definition: MCAsmMacro.h:83
llvm::SMLoc::getPointer
const char * getPointer() const
Definition: SMLoc.h:34
llvm::MCAsmParser::TokError
bool TokError(const Twine &Msg, SMRange Range=None)
Report an error at the current lexer location.
Definition: MCAsmParser.cpp:95
llvm::MCAsmParser::MCPendingError::Msg
SmallString< 64 > Msg
Definition: MCAsmParser.h:132
llvm::MCTargetAsmParser
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Definition: MCTargetAsmParser.h:309
llvm::AsmToken::TokenKind
TokenKind
Definition: MCAsmMacro.h:23
llvm::MCAsmParser::parseGNUAttribute
bool parseGNUAttribute(SMLoc L, int64_t &Tag, int64_t &IntegerValue)
Parse a .gnu_attribute.
Definition: MCAsmParser.cpp:143
llvm::MCAsmParser::getLexer
virtual MCAsmLexer & getLexer()=0
llvm::SMRange
Represents a range in source code.
Definition: SMLoc.h:48
llvm::cl::desc
Definition: CommandLine.h:414
raw_ostream.h
llvm::AsmToken::getLoc
SMLoc getLoc() const
Definition: MCAsmLexer.cpp:27
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Debug.h
llvm::MCAsmParser::MCAsmParser
MCAsmParser()
Definition: MCAsmParser.cpp:28
llvm::MCAsmParser::parseToken
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
Definition: MCAsmParser.cpp:61
llvm::MCAsmParser::setTargetParser
void setTargetParser(MCTargetAsmParser &P)
Definition: MCAsmParser.cpp:32
llvm::MCAsmParser::parseTokenLoc
bool parseTokenLoc(SMLoc &Loc)
Definition: MCAsmParser.cpp:42