LLVM  13.0.0git
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
llvm::MCAsmParser Class Referenceabstract

Generic assembler parser interface, for use by target specific assembly parsers. More...

#include "llvm/MC/MCParser/MCAsmParser.h"

Collaboration diagram for llvm::MCAsmParser:
Collaboration graph
[legend]

Classes

struct  MCPendingError
 

Public Types

using DirectiveHandler = bool(*)(MCAsmParserExtension *, StringRef, SMLoc)
 
using ExtensionDirectiveHandler = std::pair< MCAsmParserExtension *, DirectiveHandler >
 

Public Member Functions

 MCAsmParser (const MCAsmParser &)=delete
 
MCAsmParseroperator= (const MCAsmParser &)=delete
 
virtual ~MCAsmParser ()
 
virtual void addDirectiveHandler (StringRef Directive, ExtensionDirectiveHandler Handler)=0
 
virtual void addAliasForDirective (StringRef Directive, StringRef Alias)=0
 
virtual SourceMgrgetSourceManager ()=0
 
virtual MCAsmLexergetLexer ()=0
 
const MCAsmLexergetLexer () const
 
virtual MCContextgetContext ()=0
 
virtual MCStreamergetStreamer ()=0
 Return the output streamer for the assembler. More...
 
MCTargetAsmParsergetTargetParser () const
 
void setTargetParser (MCTargetAsmParser &P)
 
virtual unsigned getAssemblerDialect ()
 
virtual void setAssemblerDialect (unsigned i)
 
bool getShowParsedOperands () const
 
void setShowParsedOperands (bool Value)
 
virtual bool Run (bool NoInitialTextSection, bool NoFinalize=false)=0
 Run the parser on the input source buffer. More...
 
virtual void setParsingMSInlineAsm (bool V)=0
 
virtual bool isParsingMSInlineAsm ()=0
 
virtual bool discardLTOSymbol (StringRef) const
 
virtual bool isParsingMasm () const
 
virtual bool defineMacro (StringRef Name, StringRef Value)
 
virtual bool lookUpField (StringRef Name, AsmFieldInfo &Info) const
 
virtual bool lookUpField (StringRef Base, StringRef Member, AsmFieldInfo &Info) const
 
virtual bool lookUpType (StringRef Name, AsmTypeInfo &Info) const
 
virtual bool parseMSInlineAsm (void *AsmLoc, std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs, SmallVectorImpl< std::pair< void *, bool >> &OpDecls, SmallVectorImpl< std::string > &Constraints, SmallVectorImpl< std::string > &Clobbers, const MCInstrInfo *MII, const MCInstPrinter *IP, MCAsmParserSemaCallback &SI)=0
 Parse MS-style inline assembly. More...
 
virtual void Note (SMLoc L, const Twine &Msg, SMRange Range=None)=0
 Emit a note at the location L, with the message Msg. More...
 
virtual bool Warning (SMLoc L, const Twine &Msg, SMRange Range=None)=0
 Emit a warning at the location L, with the message Msg. More...
 
bool Error (SMLoc L, const Twine &Msg, SMRange Range=None)
 Return an error at the location L, with the message Msg. More...
 
virtual bool printError (SMLoc L, const Twine &Msg, SMRange Range=None)=0
 Emit an error at the location L, with the message Msg. More...
 
bool hasPendingError ()
 
bool printPendingErrors ()
 
void clearPendingErrors ()
 
bool addErrorSuffix (const Twine &Suffix)
 
virtual const AsmTokenLex ()=0
 Get the next AsmToken in the stream, possibly handling file inclusion first. More...
 
const AsmTokengetTok () const
 Get the current AsmToken from the stream. More...
 
bool TokError (const Twine &Msg, SMRange Range=None)
 Report an error at the current lexer location. More...
 
bool parseTokenLoc (SMLoc &Loc)
 
bool parseToken (AsmToken::TokenKind T, const Twine &Msg="unexpected token")
 
bool parseOptionalToken (AsmToken::TokenKind T)
 Attempt to parse and consume token, returning true on success. More...
 
bool parseComma ()
 
bool parseEOL ()
 
bool parseEOL (const Twine &ErrMsg)
 
bool parseMany (function_ref< bool()> parseOne, bool hasComma=true)
 
bool parseIntToken (int64_t &V, const Twine &ErrMsg)
 
bool check (bool P, const Twine &Msg)
 
bool check (bool P, SMLoc Loc, const Twine &Msg)
 
virtual bool parseIdentifier (StringRef &Res)=0
 Parse an identifier or string (as a quoted identifier) and set Res to the identifier contents. More...
 
virtual StringRef parseStringToEndOfStatement ()=0
 Parse up to the end of statement and return the contents from the current token until the end of the statement; the current token on exit will be either the EndOfStatement or EOF. More...
 
virtual bool parseEscapedString (std::string &Data)=0
 Parse the current token as a string which may include escaped characters and return the string contents. More...
 
virtual bool parseAngleBracketString (std::string &Data)=0
 Parse an angle-bracket delimited string at the current position if one is present, returning the string contents. More...
 
virtual void eatToEndOfStatement ()=0
 Skip to the end of the current statement, for error recovery. More...
 
virtual bool parseExpression (const MCExpr *&Res, SMLoc &EndLoc)=0
 Parse an arbitrary expression. More...
 
bool parseExpression (const MCExpr *&Res)
 
virtual bool parsePrimaryExpr (const MCExpr *&Res, SMLoc &EndLoc, AsmTypeInfo *TypeInfo)=0
 Parse a primary expression. More...
 
virtual bool parseParenExpression (const MCExpr *&Res, SMLoc &EndLoc)=0
 Parse an arbitrary expression, assuming that an initial '(' has already been consumed. More...
 
virtual bool parseAbsoluteExpression (int64_t &Res)=0
 Parse an expression which must evaluate to an absolute value. More...
 
virtual bool checkForValidSection ()=0
 Ensure that we have a valid section set in the streamer. More...
 
virtual bool parseParenExprOfDepth (unsigned ParenDepth, const MCExpr *&Res, SMLoc &EndLoc)=0
 Parse an arbitrary expression of a specified parenthesis depth, assuming that the initial '(' characters have already been consumed. More...
 

Protected Member Functions

 MCAsmParser ()
 

Protected Attributes

SmallVector< MCPendingError, 0 > PendingErrors
 
bool HadError = false
 Flag tracking whether any errors have been encountered. More...
 
bool ShowParsedOperands = false
 

Detailed Description

Generic assembler parser interface, for use by target specific assembly parsers.

Definition at line 123 of file MCAsmParser.h.

Member Typedef Documentation

◆ DirectiveHandler

Definition at line 125 of file MCAsmParser.h.

◆ ExtensionDirectiveHandler

Definition at line 127 of file MCAsmParser.h.

Constructor & Destructor Documentation

◆ MCAsmParser() [1/2]

MCAsmParser::MCAsmParser ( )
protected

Definition at line 28 of file MCAsmParser.cpp.

◆ MCAsmParser() [2/2]

llvm::MCAsmParser::MCAsmParser ( const MCAsmParser )
delete

◆ ~MCAsmParser()

MCAsmParser::~MCAsmParser ( )
virtualdefault

Member Function Documentation

◆ addAliasForDirective()

virtual void llvm::MCAsmParser::addAliasForDirective ( StringRef  Directive,
StringRef  Alias 
)
pure virtual

◆ addDirectiveHandler()

virtual void llvm::MCAsmParser::addDirectiveHandler ( StringRef  Directive,
ExtensionDirectiveHandler  Handler 
)
pure virtual

◆ addErrorSuffix()

bool MCAsmParser::addErrorSuffix ( const Twine Suffix)

◆ check() [1/2]

bool MCAsmParser::check ( bool  P,
const Twine Msg 
)

Definition at line 85 of file MCAsmParser.cpp.

References getTok(), and P.

Referenced by llvm::MCAsmParserExtension::check().

◆ check() [2/2]

bool MCAsmParser::check ( bool  P,
SMLoc  Loc,
const Twine Msg 
)

Definition at line 89 of file MCAsmParser.cpp.

References Error(), and P.

◆ checkForValidSection()

virtual bool llvm::MCAsmParser::checkForValidSection ( )
pure virtual

Ensure that we have a valid section set in the streamer.

Otherwise, report an error and switch to .text.

Returns
- False on success.

◆ clearPendingErrors()

void llvm::MCAsmParser::clearPendingErrors ( )
inline

Definition at line 243 of file MCAsmParser.h.

References PendingErrors.

◆ defineMacro()

virtual bool llvm::MCAsmParser::defineMacro ( StringRef  Name,
StringRef  Value 
)
inlinevirtual

Definition at line 189 of file MCAsmParser.h.

◆ discardLTOSymbol()

virtual bool llvm::MCAsmParser::discardLTOSymbol ( StringRef  ) const
inlinevirtual

Definition at line 185 of file MCAsmParser.h.

◆ eatToEndOfStatement()

virtual void llvm::MCAsmParser::eatToEndOfStatement ( )
pure virtual

Skip to the end of the current statement, for error recovery.

◆ Error()

bool MCAsmParser::Error ( SMLoc  L,
const Twine Msg,
SMRange  Range = None 
)

Return an error at the location L, with the message Msg.

This may be modified before being emitted.

Returns
The return value is always true, as an idiomatic convenience to clients.

Definition at line 99 of file MCAsmParser.cpp.

References llvm::AsmToken::Error, getLexer(), getTok(), is, llvm::MCAsmLexer::Lex(), llvm::MCAsmParser::MCPendingError::Loc, llvm::MCAsmParser::MCPendingError::Msg, PendingErrors, llvm::MCAsmParser::MCPendingError::Range, and llvm::Twine::toVector().

Referenced by check(), llvm::MCAsmParserExtension::Error(), llvm::MCParserUtils::parseAssignmentExpression(), parseEOL(), parseToken(), and TokError().

◆ getAssemblerDialect()

virtual unsigned llvm::MCAsmParser::getAssemblerDialect ( )
inlinevirtual

Definition at line 173 of file MCAsmParser.h.

◆ getContext()

virtual MCContext& llvm::MCAsmParser::getContext ( )
pure virtual

◆ getLexer() [1/2]

const MCAsmLexer& llvm::MCAsmParser::getLexer ( ) const
inline

Definition at line 161 of file MCAsmParser.h.

References getLexer().

◆ getLexer() [2/2]

virtual MCAsmLexer& llvm::MCAsmParser::getLexer ( )
pure virtual

◆ getShowParsedOperands()

bool llvm::MCAsmParser::getShowParsedOperands ( ) const
inline

Definition at line 176 of file MCAsmParser.h.

References ShowParsedOperands.

◆ getSourceManager()

virtual SourceMgr& llvm::MCAsmParser::getSourceManager ( )
pure virtual

◆ getStreamer()

virtual MCStreamer& llvm::MCAsmParser::getStreamer ( )
pure virtual

Return the output streamer for the assembler.

Referenced by llvm::MCAsmParserExtension::getStreamer(), and llvm::MCParserUtils::parseAssignmentExpression().

◆ getTargetParser()

MCTargetAsmParser& llvm::MCAsmParser::getTargetParser ( ) const
inline

Definition at line 170 of file MCAsmParser.h.

◆ getTok()

const AsmToken & MCAsmParser::getTok ( ) const

◆ hasPendingError()

bool llvm::MCAsmParser::hasPendingError ( )
inline

Definition at line 232 of file MCAsmParser.h.

References PendingErrors.

◆ isParsingMasm()

virtual bool llvm::MCAsmParser::isParsingMasm ( ) const
inlinevirtual

Definition at line 187 of file MCAsmParser.h.

◆ isParsingMSInlineAsm()

virtual bool llvm::MCAsmParser::isParsingMSInlineAsm ( )
pure virtual

◆ Lex()

virtual const AsmToken& llvm::MCAsmParser::Lex ( )
pure virtual

Get the next AsmToken in the stream, possibly handling file inclusion first.

Referenced by addErrorSuffix(), llvm::MCAsmParserExtension::Lex(), parseEOL(), parseIntToken(), and parseToken().

◆ lookUpField() [1/2]

virtual bool llvm::MCAsmParser::lookUpField ( StringRef  Base,
StringRef  Member,
AsmFieldInfo Info 
) const
inlinevirtual

Definition at line 194 of file MCAsmParser.h.

◆ lookUpField() [2/2]

virtual bool llvm::MCAsmParser::lookUpField ( StringRef  Name,
AsmFieldInfo Info 
) const
inlinevirtual

Definition at line 191 of file MCAsmParser.h.

◆ lookUpType()

virtual bool llvm::MCAsmParser::lookUpType ( StringRef  Name,
AsmTypeInfo Info 
) const
inlinevirtual

Definition at line 199 of file MCAsmParser.h.

◆ Note()

virtual void llvm::MCAsmParser::Note ( SMLoc  L,
const Twine Msg,
SMRange  Range = None 
)
pure virtual

Emit a note at the location L, with the message Msg.

Referenced by llvm::MCAsmParserExtension::Note().

◆ operator=()

MCAsmParser& llvm::MCAsmParser::operator= ( const MCAsmParser )
delete

◆ parseAbsoluteExpression()

virtual bool llvm::MCAsmParser::parseAbsoluteExpression ( int64_t &  Res)
pure virtual

Parse an expression which must evaluate to an absolute value.

Parameters
Res- The value of the absolute expression. The result is undefined on error.
Returns
- False on success.

◆ parseAngleBracketString()

virtual bool llvm::MCAsmParser::parseAngleBracketString ( std::string &  Data)
pure virtual

Parse an angle-bracket delimited string at the current position if one is present, returning the string contents.

◆ parseComma()

bool llvm::MCAsmParser::parseComma ( )
inline

Definition at line 263 of file MCAsmParser.h.

References llvm::AsmToken::Comma, and parseToken().

◆ parseEOL() [1/2]

bool MCAsmParser::parseEOL ( )

◆ parseEOL() [2/2]

bool MCAsmParser::parseEOL ( const Twine ErrMsg)

Definition at line 54 of file MCAsmParser.cpp.

References llvm::AsmToken::EndOfStatement, Error(), getTok(), and Lex().

◆ parseEscapedString()

virtual bool llvm::MCAsmParser::parseEscapedString ( std::string &  Data)
pure virtual

Parse the current token as a string which may include escaped characters and return the string contents.

◆ parseExpression() [1/2]

bool MCAsmParser::parseExpression ( const MCExpr *&  Res)

Definition at line 138 of file MCAsmParser.cpp.

References parseExpression().

◆ parseExpression() [2/2]

virtual bool llvm::MCAsmParser::parseExpression ( const MCExpr *&  Res,
SMLoc EndLoc 
)
pure virtual

Parse an arbitrary expression.

Parameters
Res- The value of the expression. The result is undefined on error.
Returns
- False on success.

Referenced by llvm::MCParserUtils::parseAssignmentExpression(), and parseExpression().

◆ parseIdentifier()

virtual bool llvm::MCAsmParser::parseIdentifier ( StringRef Res)
pure virtual

Parse an identifier or string (as a quoted identifier) and set Res to the identifier contents.

◆ parseIntToken()

bool MCAsmParser::parseIntToken ( int64_t &  V,
const Twine ErrMsg 
)

◆ parseMany()

bool MCAsmParser::parseMany ( function_ref< bool()>  parseOne,
bool  hasComma = true 
)

◆ parseMSInlineAsm()

virtual bool llvm::MCAsmParser::parseMSInlineAsm ( void *  AsmLoc,
std::string &  AsmString,
unsigned &  NumOutputs,
unsigned &  NumInputs,
SmallVectorImpl< std::pair< void *, bool >> &  OpDecls,
SmallVectorImpl< std::string > &  Constraints,
SmallVectorImpl< std::string > &  Clobbers,
const MCInstrInfo MII,
const MCInstPrinter IP,
MCAsmParserSemaCallback SI 
)
pure virtual

Parse MS-style inline assembly.

◆ parseOptionalToken()

bool MCAsmParser::parseOptionalToken ( AsmToken::TokenKind  T)

Attempt to parse and consume token, returning true on success.

Definition at line 78 of file MCAsmParser.cpp.

References llvm::AsmToken::getKind(), getTok(), parseToken(), and T.

Referenced by parseMany(), and llvm::MCAsmParserExtension::parseOptionalToken().

◆ parseParenExpression()

virtual bool llvm::MCAsmParser::parseParenExpression ( const MCExpr *&  Res,
SMLoc EndLoc 
)
pure virtual

Parse an arbitrary expression, assuming that an initial '(' has already been consumed.

Parameters
Res- The value of the expression. The result is undefined on error.
Returns
- False on success.

◆ parseParenExprOfDepth()

virtual bool llvm::MCAsmParser::parseParenExprOfDepth ( unsigned  ParenDepth,
const MCExpr *&  Res,
SMLoc EndLoc 
)
pure virtual

Parse an arbitrary expression of a specified parenthesis depth, assuming that the initial '(' characters have already been consumed.

Parameters
ParenDepth- Specifies how many trailing expressions outside the current parentheses we have to parse.
Res- The value of the expression. The result is undefined on error.
Returns
- False on success.

◆ parsePrimaryExpr()

virtual bool llvm::MCAsmParser::parsePrimaryExpr ( const MCExpr *&  Res,
SMLoc EndLoc,
AsmTypeInfo TypeInfo 
)
pure virtual

Parse a primary expression.

Parameters
Res- The value of the expression. The result is undefined on error.
Returns
- False on success.

Referenced by llvm::MCTargetAsmParser::parsePrimaryExpr().

◆ parseStringToEndOfStatement()

virtual StringRef llvm::MCAsmParser::parseStringToEndOfStatement ( )
pure virtual

Parse up to the end of statement and return the contents from the current token until the end of the statement; the current token on exit will be either the EndOfStatement or EOF.

◆ parseToken()

bool MCAsmParser::parseToken ( AsmToken::TokenKind  T,
const Twine Msg = "unexpected token" 
)

◆ parseTokenLoc()

bool MCAsmParser::parseTokenLoc ( SMLoc Loc)

Definition at line 42 of file MCAsmParser.cpp.

References llvm::AsmToken::getLoc(), and getTok().

◆ printError()

virtual bool llvm::MCAsmParser::printError ( SMLoc  L,
const Twine Msg,
SMRange  Range = None 
)
pure virtual

Emit an error at the location L, with the message Msg.

Returns
The return value is always true, as an idiomatic convenience to clients.

◆ printPendingErrors()

bool llvm::MCAsmParser::printPendingErrors ( )
inline

Definition at line 234 of file MCAsmParser.h.

References PendingErrors.

◆ Run()

virtual bool llvm::MCAsmParser::Run ( bool  NoInitialTextSection,
bool  NoFinalize = false 
)
pure virtual

Run the parser on the input source buffer.

◆ setAssemblerDialect()

virtual void llvm::MCAsmParser::setAssemblerDialect ( unsigned  i)
inlinevirtual

Definition at line 174 of file MCAsmParser.h.

◆ setParsingMSInlineAsm()

virtual void llvm::MCAsmParser::setParsingMSInlineAsm ( bool  V)
pure virtual

◆ setShowParsedOperands()

void llvm::MCAsmParser::setShowParsedOperands ( bool  Value)
inline

Definition at line 177 of file MCAsmParser.h.

References ShowParsedOperands.

◆ setTargetParser()

void MCAsmParser::setTargetParser ( MCTargetAsmParser P)

Definition at line 32 of file MCAsmParser.cpp.

References assert(), llvm::MCAsmParserExtension::Initialize(), and P.

◆ TokError()

bool MCAsmParser::TokError ( const Twine Msg,
SMRange  Range = None 
)

Report an error at the current lexer location.

Definition at line 95 of file MCAsmParser.cpp.

References Error(), and getLexer().

Referenced by llvm::MCParserUtils::parseAssignmentExpression(), parseIntToken(), and llvm::MCAsmParserExtension::TokError().

◆ Warning()

virtual bool llvm::MCAsmParser::Warning ( SMLoc  L,
const Twine Msg,
SMRange  Range = None 
)
pure virtual

Emit a warning at the location L, with the message Msg.

Returns
The return value is true, if warnings are fatal.

Referenced by llvm::MCAsmParserExtension::Warning().

Member Data Documentation

◆ HadError

bool llvm::MCAsmParser::HadError = false
protected

Flag tracking whether any errors have been encountered.

Definition at line 144 of file MCAsmParser.h.

◆ PendingErrors

SmallVector<MCPendingError, 0> llvm::MCAsmParser::PendingErrors
protected

◆ ShowParsedOperands

bool llvm::MCAsmParser::ShowParsedOperands = false
protected

Definition at line 146 of file MCAsmParser.h.

Referenced by getShowParsedOperands(), and setShowParsedOperands().


The documentation for this class was generated from the following files: