[llvm] r280092 - [MC] Move parser helper functions from Asmparser to MCAsmParser
Nirav Dave via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 30 07:15:43 PDT 2016
Author: niravd
Date: Tue Aug 30 09:15:43 2016
New Revision: 280092
URL: http://llvm.org/viewvc/llvm-project?rev=280092&view=rev
Log:
[MC] Move parser helper functions from Asmparser to MCAsmParser
NFC Intended.
Modified:
llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp
Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h?rev=280092&r1=280091&r2=280092&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h Tue Aug 30 09:15:43 2016
@@ -148,6 +148,17 @@ public:
/// \brief Report an error at the current lexer location.
bool TokError(const Twine &Msg, ArrayRef<SMRange> Ranges = None);
+ bool parseTokenLoc(SMLoc &Loc);
+ bool parseToken(AsmToken::TokenKind T, const Twine &Msg);
+ bool parseOptionalToken(AsmToken::TokenKind T, bool &Present);
+
+ bool parseEOL(const Twine &ErrMsg);
+
+ bool parseIntToken(int64_t &V, const Twine &ErrMsg);
+
+ bool check(bool P, const llvm::Twine &Msg);
+ bool check(bool P, SMLoc Loc, const llvm::Twine &Msg);
+
/// \brief Parse an identifier or string (as a quoted identifier) and set \p
/// Res to the identifier contents.
virtual bool parseIdentifier(StringRef &Res) = 0;
Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h?rev=280092&r1=280091&r2=280092&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParserExtension.h Tue Aug 30 09:15:43 2016
@@ -79,8 +79,10 @@ public:
}
const AsmToken &Lex() { return getParser().Lex(); }
-
const AsmToken &getTok() { return getParser().getTok(); }
+ bool parseToken(AsmToken::TokenKind T, const Twine &Msg) {
+ return getParser().parseToken(T, Msg);
+ }
bool HasBracketExpressions() const { return BracketExpressionsSupported; }
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=280092&r1=280091&r2=280092&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Aug 30 09:15:43 2016
@@ -282,42 +282,6 @@ public:
void checkForValidSection() override;
- bool getTokenLoc(SMLoc &Loc) {
- Loc = getTok().getLoc();
- return false;
- }
-
- bool parseEOL(const Twine &ErrMsg) {
- if (getTok().getKind() == AsmToken::Hash) {
- StringRef CommentStr = parseStringToEndOfStatement();
- Lexer.Lex();
- Lexer.UnLex(AsmToken(AsmToken::EndOfStatement, CommentStr));
- }
- if (getTok().getKind() != AsmToken::EndOfStatement)
- return TokError(ErrMsg);
- Lex();
- return false;
- }
-
- /// parseToken - If current token has the specified kind, eat it and
- /// return success. Otherwise, emit the specified error and return failure.
- bool parseToken(AsmToken::TokenKind T, const Twine &ErrMsg) {
- if (T == AsmToken::EndOfStatement)
- return parseEOL(ErrMsg);
- if (getTok().getKind() != T)
- return TokError(ErrMsg);
- Lex();
- return false;
- }
-
- bool parseIntToken(int64_t &V, const Twine &ErrMsg) {
- if (getTok().getKind() != AsmToken::Integer)
- return TokError(ErrMsg);
- V = getTok().getIntVal();
- Lex();
- return false;
- }
-
/// }
private:
@@ -375,18 +339,6 @@ private:
}
static void DiagHandler(const SMDiagnostic &Diag, void *Context);
- bool check(bool P, SMLoc Loc, const Twine &Msg) {
- if (P)
- return Error(Loc, Msg);
- return false;
- }
-
- bool check(bool P, const Twine &Msg) {
- if (P)
- return TokError(Msg);
- return false;
- }
-
/// \brief Enter the specified file. This returns true on failure.
bool enterIncludeFile(const std::string &Filename);
@@ -2932,13 +2884,13 @@ bool AsmParser::parseDirectiveFill() {
if (getLexer().isNot(AsmToken::EndOfStatement)) {
if (parseToken(AsmToken::Comma, "unexpected token in '.fill' directive") ||
- getTokenLoc(SizeLoc) || parseAbsoluteExpression(FillSize))
+ parseTokenLoc(SizeLoc) || parseAbsoluteExpression(FillSize))
return true;
if (getLexer().isNot(AsmToken::EndOfStatement)) {
if (parseToken(AsmToken::Comma,
"unexpected token in '.fill' directive") ||
- getTokenLoc(ExprLoc) || parseAbsoluteExpression(FillExpr) ||
+ parseTokenLoc(ExprLoc) || parseAbsoluteExpression(FillExpr) ||
parseToken(AsmToken::EndOfStatement,
"unexpected token in '.fill' directive"))
return true;
@@ -3016,7 +2968,7 @@ bool AsmParser::parseDirectiveAlign(bool
if (getTok().isNot(AsmToken::EndOfStatement)) {
if (parseToken(AsmToken::Comma, "unexpected token in directive") ||
- getTokenLoc(MaxBytesLoc) || parseAbsoluteExpression(MaxBytesToFill))
+ parseTokenLoc(MaxBytesLoc) || parseAbsoluteExpression(MaxBytesToFill))
return true;
}
}
@@ -3295,11 +3247,11 @@ bool AsmParser::parseDirectiveCVFile() {
bool AsmParser::parseDirectiveCVLoc() {
SMLoc Loc;
int64_t FunctionId, FileNumber;
- if (getTokenLoc(Loc) ||
+ if (parseTokenLoc(Loc) ||
parseIntToken(FunctionId, "unexpected token in '.cv_loc' directive") ||
check(FunctionId < 0, Loc,
"function id less than zero in '.cv_loc' directive") ||
- getTokenLoc(Loc) ||
+ parseTokenLoc(Loc) ||
parseIntToken(FileNumber, "expected integer in '.cv_loc' directive") ||
check(FileNumber < 1, Loc,
"file number less than one in '.cv_loc' directive") ||
@@ -3368,12 +3320,12 @@ bool AsmParser::parseDirectiveCVLinetabl
"function id less than zero in '.cv_linetable' directive") ||
parseToken(AsmToken::Comma,
"unexpected token in '.cv_linetable' directive") ||
- getTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
- "expected identifier in directive") ||
+ parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
+ "expected identifier in directive") ||
parseToken(AsmToken::Comma,
"unexpected token in '.cv_linetable' directive") ||
- getTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
- "expected identifier in directive"))
+ parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
+ "expected identifier in directive"))
return true;
MCSymbol *FnStartSym = getContext().getOrCreateSymbol(FnStartName);
@@ -3395,22 +3347,22 @@ bool AsmParser::parseDirectiveCVInlineLi
"expected PrimaryFunctionId in '.cv_inline_linetable' directive") ||
check(PrimaryFunctionId < 0, Loc,
"function id less than zero in '.cv_inline_linetable' directive") ||
- getTokenLoc(Loc) ||
+ parseTokenLoc(Loc) ||
parseIntToken(
SourceFileId,
"expected SourceField in '.cv_inline_linetable' directive") ||
check(SourceFileId <= 0, Loc,
"File id less than zero in '.cv_inline_linetable' directive") ||
- getTokenLoc(Loc) ||
+ parseTokenLoc(Loc) ||
parseIntToken(
SourceLineNum,
"expected SourceLineNum in '.cv_inline_linetable' directive") ||
check(SourceLineNum < 0, Loc,
"Line number less than zero in '.cv_inline_linetable' directive") ||
- getTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
- "expected identifier in directive") ||
- getTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
- "expected identifier in directive"))
+ parseTokenLoc(Loc) || check(parseIdentifier(FnStartName), Loc,
+ "expected identifier in directive") ||
+ parseTokenLoc(Loc) || check(parseIdentifier(FnEndName), Loc,
+ "expected identifier in directive"))
return true;
SmallVector<unsigned, 8> SecondaryFunctionIds;
@@ -4057,8 +4009,9 @@ bool AsmParser::parseDirectiveEndMacro(S
bool AsmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
StringRef Name;
SMLoc Loc;
- if (getTokenLoc(Loc) || check(parseIdentifier(Name), Loc,
- "expected identifier in '.purgem' directive") ||
+ if (parseTokenLoc(Loc) ||
+ check(parseIdentifier(Name), Loc,
+ "expected identifier in '.purgem' directive") ||
parseToken(AsmToken::EndOfStatement,
"unexpected token in '.purgem' directive"))
return true;
Modified: llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp?rev=280092&r1=280091&r2=280092&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/MCAsmParser.cpp Tue Aug 30 09:15:43 2016
@@ -33,6 +33,57 @@ const AsmToken &MCAsmParser::getTok() co
return getLexer().getTok();
}
+bool MCAsmParser::parseTokenLoc(SMLoc &Loc) {
+ Loc = getTok().getLoc();
+ return false;
+}
+
+bool MCAsmParser::parseEOL(const Twine &Msg) {
+ if (getTok().getKind() == AsmToken::Hash) {
+ StringRef CommentStr = parseStringToEndOfStatement();
+ getLexer().Lex();
+ getLexer().UnLex(AsmToken(AsmToken::EndOfStatement, CommentStr));
+ }
+ if (getTok().getKind() != AsmToken::EndOfStatement)
+ return Error(getTok().getLoc(), Msg);
+ Lex();
+ return false;
+}
+
+bool MCAsmParser::parseToken(AsmToken::TokenKind T, const Twine &Msg) {
+ if (T == AsmToken::EndOfStatement)
+ return parseEOL(Msg);
+ if (getTok().getKind() != T)
+ return Error(getTok().getLoc(), Msg);
+ Lex();
+ return false;
+}
+
+bool MCAsmParser::parseIntToken(int64_t &V, const Twine &Msg) {
+ if (getTok().getKind() != AsmToken::Integer)
+ return TokError(Msg);
+ V = getTok().getIntVal();
+ Lex();
+ return false;
+}
+
+bool MCAsmParser::parseOptionalToken(AsmToken::TokenKind T, bool &Present) {
+ Present = (getTok().getKind() == T);
+ if (Present)
+ Lex();
+ return false;
+}
+
+bool MCAsmParser::check(bool P, const Twine &Msg) {
+ return check(P, getTok().getLoc(), Msg);
+}
+
+bool MCAsmParser::check(bool P, SMLoc Loc, const Twine &Msg) {
+ if (P)
+ return Error(Loc, Msg);
+ return false;
+}
+
bool MCAsmParser::TokError(const Twine &Msg, ArrayRef<SMRange> Ranges) {
Error(getLexer().getLoc(), Msg, Ranges);
return true;
More information about the llvm-commits
mailing list