Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
llvm::MCAsmParser Class Referenceabstract

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

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

Classes

struct  MCPendingError

Public Types

using DirectiveHandler = bool (*)(MCAsmParserExtension*, StringRef, SMLoc)
using ExtensionDirectiveHandler

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
MCContextgetContext ()
MCStreamergetStreamer ()
SourceMgrgetSourceManager ()
AsmLexergetLexer ()
const AsmLexergetLexer () const
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.
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 (std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs, SmallVectorImpl< std::pair< void *, bool > > &OpDecls, SmallVectorImpl< std::string > &Constraints, SmallVectorImpl< std::string > &Clobbers, const MCInstrInfo *MII, MCInstPrinter *IP, MCAsmParserSemaCallback &SI)=0
 Parse MS-style inline assembly.
virtual void Note (SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)=0
 Emit a note at the location L, with the message Msg.
virtual bool Warning (SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)=0
 Emit a warning at the location L, with the message Msg.
bool Error (SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)
 Return an error at the location L, with the message Msg.
virtual bool printError (SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)=0
 Emit an error at the location L, with the message Msg.
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.
const AsmTokengetTok () const
 Get the current AsmToken from the stream.
bool TokError (const Twine &Msg, SMRange Range=std::nullopt)
 Report an error at the current lexer location.
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.
bool parseComma ()
bool parseRParen ()
bool parseEOL ()
bool parseEOL (const Twine &ErrMsg)
bool parseMany (function_ref< bool()> parseOne, bool hasComma=true)
bool parseIntToken (int64_t &V, const Twine &ErrMsg="expected integer")
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.
bool parseSymbol (MCSymbol *&Res)
 Parse identifier and get or create symbol for it.
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.
virtual bool parseEscapedString (std::string &Data)=0
 Parse the current token as a string which may include escaped characters and return the string contents.
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.
virtual void eatToEndOfStatement ()=0
 Skip to the end of the current statement, for error recovery.
virtual bool parseExpression (const MCExpr *&Res, SMLoc &EndLoc)=0
 Parse an arbitrary expression.
bool parseExpression (const MCExpr *&Res)
virtual bool parsePrimaryExpr (const MCExpr *&Res, SMLoc &EndLoc, AsmTypeInfo *TypeInfo=nullptr)=0
 Parse a primary expression.
virtual bool parseParenExpression (const MCExpr *&Res, SMLoc &EndLoc)=0
 Parse an arbitrary expression, assuming that an initial '(' has already been consumed.
virtual bool parseAbsoluteExpression (int64_t &Res)=0
 Parse an expression which must evaluate to an absolute value.
virtual bool checkForValidSection ()=0
 Ensure that we have a valid section set in the streamer.
bool parseGNUAttribute (SMLoc L, int64_t &Tag, int64_t &IntegerValue)
 Parse a .gnu_attribute.
bool parseAtSpecifier (const MCExpr *&Res, SMLoc &EndLoc)
const MCExprapplySpecifier (const MCExpr *E, uint32_t Variant)

Protected Member Functions

 MCAsmParser (MCContext &, MCStreamer &, SourceMgr &, const MCAsmInfo &)

Protected Attributes

MCContextCtx
MCStreamerOut
SourceMgrSrcMgr
const MCAsmInfoMAI
AsmLexer Lexer
SmallVector< MCPendingError, 0 > PendingErrors
bool HadError = false
 Flag tracking whether any errors have been encountered.
bool ShowParsedOperands = false

Detailed Description

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

Definition at line 124 of file MCAsmParser.h.

Member Typedef Documentation

◆ DirectiveHandler

◆ ExtensionDirectiveHandler

Initial value:
std::pair<MCAsmParserExtension*, DirectiveHandler>

Definition at line 127 of file MCAsmParser.h.

Constructor & Destructor Documentation

◆ MCAsmParser() [1/2]

MCAsmParser::MCAsmParser ( MCContext & Ctx,
MCStreamer & Out,
SourceMgr & SM,
const MCAsmInfo & MAI )
protected

Definition at line 31 of file MCAsmParser.cpp.

References Ctx, Lexer, MAI, Out, and SrcMgr.

Referenced by MCAsmParser(), and operator=().

◆ MCAsmParser() [2/2]

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

References MCAsmParser().

◆ ~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)

◆ applySpecifier()

◆ check() [1/2]

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

Definition at line 90 of file MCAsmParser.cpp.

References check(), getTok(), and P.

Referenced by check().

◆ check() [2/2]

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

Definition at line 94 of file MCAsmParser.cpp.

References llvm::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.

References applySpecifier(), E(), parseAtSpecifier(), parseGNUAttribute(), and llvm::Tag.

◆ clearPendingErrors()

void llvm::MCAsmParser::clearPendingErrors ( )
inline

Definition at line 246 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 = std::nullopt )

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 104 of file MCAsmParser.cpp.

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

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

◆ getAssemblerDialect()

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

Definition at line 173 of file MCAsmParser.h.

◆ getContext()

MCContext & llvm::MCAsmParser::getContext ( )
inline

Definition at line 164 of file MCAsmParser.h.

References Ctx.

Referenced by applySpecifier(), llvm::MCParserUtils::parseAssignmentExpression(), and parseSymbol().

◆ getLexer() [1/2]

AsmLexer & llvm::MCAsmParser::getLexer ( )
inline

Definition at line 167 of file MCAsmParser.h.

References Lexer.

Referenced by Error(), expectAbsExpression(), getTok(), parseAtSpecifier(), parseExpr(), and TokError().

◆ getLexer() [2/2]

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

Definition at line 168 of file MCAsmParser.h.

References Lexer.

◆ getShowParsedOperands()

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

Definition at line 176 of file MCAsmParser.h.

References ShowParsedOperands.

◆ getSourceManager()

SourceMgr & llvm::MCAsmParser::getSourceManager ( )
inline

Definition at line 166 of file MCAsmParser.h.

References SrcMgr.

◆ getStreamer()

MCStreamer & llvm::MCAsmParser::getStreamer ( )
inline

Definition at line 165 of file MCAsmParser.h.

References Out.

Referenced by llvm::MCParserUtils::parseAssignmentExpression().

◆ getTargetParser()

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

Definition at line 170 of file MCAsmParser.h.

Referenced by applySpecifier().

◆ getTok()

◆ hasPendingError()

bool llvm::MCAsmParser::hasPendingError ( )
inline

Definition at line 235 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.

References getTok(), parseOptionalToken(), parseToken(), parseTokenLoc(), Range, T, and TokError().

Referenced by addErrorSuffix(), parseAtSpecifier(), parseEOL(), parseEOL(), parseGNUAttribute(), 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.

References llvm::sampleprof::Base, and Info.

◆ lookUpField() [2/2]

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

Definition at line 191 of file MCAsmParser.h.

References Info.

◆ lookUpType()

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

Definition at line 199 of file MCAsmParser.h.

References Info.

◆ Note()

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

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

References Range.

◆ operator=()

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

References MCAsmParser().

◆ 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.

Referenced by expectAbsExpression().

◆ 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.

References llvm::Data.

◆ parseAtSpecifier()

bool MCAsmParser::parseAtSpecifier ( const MCExpr *& Res,
SMLoc & EndLoc )

◆ parseComma()

bool llvm::MCAsmParser::parseComma ( )
inline

Definition at line 266 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 59 of file MCAsmParser.cpp.

References llvm::AsmToken::EndOfStatement, llvm::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.

References llvm::Data.

◆ parseExpression() [1/2]

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

Definition at line 142 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.

References parseExpression().

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

◆ parseGNUAttribute()

bool MCAsmParser::parseGNUAttribute ( SMLoc L,
int64_t & Tag,
int64_t & IntegerValue )

◆ 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.

References parseSymbol().

Referenced by parseSymbol().

◆ parseIntToken()

bool MCAsmParser::parseIntToken ( int64_t & V,
const Twine & ErrMsg = "expected integer" )

◆ parseMany()

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

◆ parseMSInlineAsm()

virtual bool llvm::MCAsmParser::parseMSInlineAsm ( std::string & AsmString,
unsigned & NumOutputs,
unsigned & NumInputs,
SmallVectorImpl< std::pair< void *, bool > > & OpDecls,
SmallVectorImpl< std::string > & Constraints,
SmallVectorImpl< std::string > & Clobbers,
const MCInstrInfo * MII,
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 83 of file MCAsmParser.cpp.

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

Referenced by Lex(), parseAtSpecifier(), and parseMany().

◆ 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.

◆ parsePrimaryExpr()

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

Parse a primary expression.

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

◆ parseRParen()

bool llvm::MCAsmParser::parseRParen ( )
inline

Definition at line 267 of file MCAsmParser.h.

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

◆ 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.

◆ parseSymbol()

bool MCAsmParser::parseSymbol ( MCSymbol *& Res)

Parse identifier and get or create symbol for it.

Definition at line 166 of file MCAsmParser.cpp.

References getContext(), parseIdentifier(), and llvm::MCContext::parseSymbol().

Referenced by parseIdentifier().

◆ parseToken()

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

◆ parseTokenLoc()

bool MCAsmParser::parseTokenLoc ( SMLoc & Loc)

Definition at line 47 of file MCAsmParser.cpp.

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

Referenced by Lex().

◆ printError()

virtual bool llvm::MCAsmParser::printError ( SMLoc L,
const Twine & Msg,
SMRange Range = std::nullopt )
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.

References Range.

Referenced by printPendingErrors().

◆ printPendingErrors()

bool llvm::MCAsmParser::printPendingErrors ( )
inline

Definition at line 237 of file MCAsmParser.h.

References PendingErrors, and printError().

◆ 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 37 of file MCAsmParser.cpp.

References assert(), and P.

◆ TokError()

bool MCAsmParser::TokError ( const Twine & Msg,
SMRange Range = std::nullopt )

Report an error at the current lexer location.

Definition at line 100 of file MCAsmParser.cpp.

References llvm::Error, getLexer(), and Range.

Referenced by applySpecifier(), Lex(), llvm::MCParserUtils::parseAssignmentExpression(), parseAtSpecifier(), and parseIntToken().

◆ Warning()

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

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

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

References Error(), and Range.

Member Data Documentation

◆ Ctx

MCContext& llvm::MCAsmParser::Ctx
protected

Definition at line 142 of file MCAsmParser.h.

Referenced by applySpecifier(), getContext(), and MCAsmParser().

◆ HadError

bool llvm::MCAsmParser::HadError = false
protected

Flag tracking whether any errors have been encountered.

Definition at line 150 of file MCAsmParser.h.

◆ Lexer

AsmLexer llvm::MCAsmParser::Lexer
protected

Definition at line 146 of file MCAsmParser.h.

Referenced by getLexer(), getLexer(), and MCAsmParser().

◆ MAI

const MCAsmInfo& llvm::MCAsmParser::MAI
protected

Definition at line 145 of file MCAsmParser.h.

Referenced by MCAsmParser(), and parseAtSpecifier().

◆ Out

MCStreamer& llvm::MCAsmParser::Out
protected

Definition at line 143 of file MCAsmParser.h.

Referenced by getStreamer(), and MCAsmParser().

◆ PendingErrors

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

◆ ShowParsedOperands

bool llvm::MCAsmParser::ShowParsedOperands = false
protected

Definition at line 152 of file MCAsmParser.h.

Referenced by getShowParsedOperands(), and setShowParsedOperands().

◆ SrcMgr

SourceMgr& llvm::MCAsmParser::SrcMgr
protected

Definition at line 144 of file MCAsmParser.h.

Referenced by getSourceManager(), and MCAsmParser().


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