[llvm] r283761 - Add return type for checkForValidSection parsing function. NFC Intended.
Nirav Dave via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 10 08:24:55 PDT 2016
Author: niravd
Date: Mon Oct 10 10:24:54 2016
New Revision: 283761
URL: http://llvm.org/viewvc/llvm-project?rev=283761&view=rev
Log:
Add return type for checkForValidSection parsing function. NFC Intended.
Modified:
llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
llvm/trunk/lib/MC/MCParser/AsmParser.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=283761&r1=283760&r2=283761&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h Mon Oct 10 10:24:54 2016
@@ -235,7 +235,8 @@ public:
/// \brief Ensure that we have a valid section set in the streamer. Otherwise,
/// report an error and switch to .text.
- virtual void checkForValidSection() = 0;
+ /// \return - False on success.
+ virtual bool checkForValidSection() = 0;
/// \brief Parse an arbitrary expression of a specified parenthesis depth,
/// assuming that the initial '(' characters have already been consumed.
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=283761&r1=283760&r2=283761&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Mon Oct 10 10:24:54 2016
@@ -281,7 +281,7 @@ public:
bool parseIdentifier(StringRef &Res) override;
void eatToEndOfStatement() override;
- void checkForValidSection() override;
+ bool checkForValidSection() override;
/// }
@@ -828,12 +828,13 @@ bool AsmParser::Run(bool NoInitialTextSe
return HadError || getContext().hadError();
}
-void AsmParser::checkForValidSection() {
+bool AsmParser::checkForValidSection() {
if (!ParsingInlineAsm && !getStreamer().getCurrentSection().first) {
- printError(getTok().getLoc(),
- "expected section directive before assembly directive");
Out.InitSections(false);
+ return Error(getTok().getLoc(),
+ "expected section directive before assembly directive");
}
+ return false;
}
/// \brief Throw away the rest of the line for testing purposes.
@@ -1589,7 +1590,8 @@ bool AsmParser::parseStatement(ParseStat
case AsmToken::Colon: {
if (!getTargetParser().isLabel(ID))
break;
- checkForValidSection();
+ if (checkForValidSection())
+ return true;
// identifier ':' -> Label.
Lex();
@@ -1977,7 +1979,8 @@ bool AsmParser::parseStatement(ParseStat
if (ParsingInlineAsm && (IDVal == "even"))
Info.AsmRewrites->emplace_back(AOK_EVEN, IDLoc, 4);
- checkForValidSection();
+ if (checkForValidSection())
+ return true;
// Canonicalize the opcode to lower case.
std::string OpcodeStr = IDVal.lower();
@@ -2707,7 +2710,8 @@ bool AsmParser::parseEscapedString(std::
/// ::= ( .ascii | .asciz | .string ) [ "string" ( , "string" )* ]
bool AsmParser::parseDirectiveAscii(StringRef IDVal, bool ZeroTerminated) {
if (getLexer().isNot(AsmToken::EndOfStatement)) {
- checkForValidSection();
+ if (checkForValidSection())
+ return true;
while (true) {
std::string Data;
@@ -2781,7 +2785,8 @@ bool AsmParser::parseDirectiveReloc(SMLo
/// ::= (.byte | .short | ... ) [ expression (, expression)* ]
bool AsmParser::parseDirectiveValue(unsigned Size) {
if (getLexer().isNot(AsmToken::EndOfStatement)) {
- checkForValidSection();
+ if (checkForValidSection())
+ return true;
while (true) {
const MCExpr *Value;
@@ -2816,7 +2821,8 @@ bool AsmParser::parseDirectiveValue(unsi
/// ::= .octa [ hexconstant (, hexconstant)* ]
bool AsmParser::parseDirectiveOctaValue() {
if (getLexer().isNot(AsmToken::EndOfStatement)) {
- checkForValidSection();
+ if (checkForValidSection())
+ return true;
while (true) {
if (getTok().is(AsmToken::Error))
@@ -2904,7 +2910,8 @@ bool AsmParser::parseRealValue(const flt
/// ::= (.single | .double) [ expression (, expression)* ]
bool AsmParser::parseDirectiveRealValue(const fltSemantics &Semantics) {
if (getLexer().isNot(AsmToken::EndOfStatement)) {
- checkForValidSection();
+ if (checkForValidSection())
+ return true;
while (true) {
APInt AsInt;
@@ -2929,11 +2936,9 @@ bool AsmParser::parseDirectiveRealValue(
/// parseDirectiveZero
/// ::= .zero expression
bool AsmParser::parseDirectiveZero() {
- checkForValidSection();
-
SMLoc NumBytesLoc = Lexer.getLoc();
const MCExpr *NumBytes;
- if (parseExpression(NumBytes))
+ if (checkForValidSection() || parseExpression(NumBytes))
return true;
int64_t Val = 0;
@@ -2954,11 +2959,9 @@ bool AsmParser::parseDirectiveZero() {
/// parseDirectiveFill
/// ::= .fill expression [ , expression [ , expression ] ]
bool AsmParser::parseDirectiveFill() {
- checkForValidSection();
-
SMLoc NumValuesLoc = Lexer.getLoc();
const MCExpr *NumValues;
- if (parseExpression(NumValues))
+ if (checkForValidSection() || parseExpression(NumValues))
return true;
int64_t FillSize = 1;
@@ -3001,10 +3004,8 @@ bool AsmParser::parseDirectiveFill() {
/// parseDirectiveOrg
/// ::= .org expression [ , expression ]
bool AsmParser::parseDirectiveOrg() {
- checkForValidSection();
-
const MCExpr *Offset;
- if (parseExpression(Offset))
+ if (checkForValidSection() || parseExpression(Offset))
return true;
// Parse optional fill expression.
@@ -3026,11 +3027,9 @@ bool AsmParser::parseDirectiveOrg() {
/// parseDirectiveAlign
/// ::= {.align, ...} expression [ , expression [ , expression ]]
bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
- checkForValidSection();
-
SMLoc AlignmentLoc = getLexer().getLoc();
int64_t Alignment;
- if (parseAbsoluteExpression(Alignment))
+ if (checkForValidSection() || parseAbsoluteExpression(Alignment))
return true;
SMLoc MaxBytesLoc;
@@ -4183,13 +4182,11 @@ bool AsmParser::parseDirectivePurgeMacro
/// parseDirectiveBundleAlignMode
/// ::= {.bundle_align_mode} expression
bool AsmParser::parseDirectiveBundleAlignMode() {
- checkForValidSection();
-
// Expect a single argument: an expression that evaluates to a constant
// in the inclusive range 0-30.
SMLoc ExprLoc = getLexer().getLoc();
int64_t AlignSizePow2;
- if (parseAbsoluteExpression(AlignSizePow2) ||
+ if (checkForValidSection() || parseAbsoluteExpression(AlignSizePow2) ||
parseToken(AsmToken::EndOfStatement, "unexpected token after expression "
"in '.bundle_align_mode' "
"directive") ||
@@ -4206,7 +4203,8 @@ bool AsmParser::parseDirectiveBundleAlig
/// parseDirectiveBundleLock
/// ::= {.bundle_lock} [align_to_end]
bool AsmParser::parseDirectiveBundleLock() {
- checkForValidSection();
+ if (checkForValidSection())
+ return true;
bool AlignToEnd = false;
if (getLexer().isNot(AsmToken::EndOfStatement)) {
@@ -4232,9 +4230,8 @@ bool AsmParser::parseDirectiveBundleLock
/// parseDirectiveBundleLock
/// ::= {.bundle_lock}
bool AsmParser::parseDirectiveBundleUnlock() {
- checkForValidSection();
-
- if (parseToken(AsmToken::EndOfStatement,
+ if (checkForValidSection() ||
+ parseToken(AsmToken::EndOfStatement,
"unexpected token in '.bundle_unlock' directive"))
return true;
@@ -4245,11 +4242,10 @@ bool AsmParser::parseDirectiveBundleUnlo
/// parseDirectiveSpace
/// ::= (.skip | .space) expression [ , expression ]
bool AsmParser::parseDirectiveSpace(StringRef IDVal) {
- checkForValidSection();
SMLoc NumBytesLoc = Lexer.getLoc();
const MCExpr *NumBytes;
- if (parseExpression(NumBytes))
+ if (checkForValidSection() || parseExpression(NumBytes))
return true;
int64_t FillExpr = 0;
@@ -4274,11 +4270,9 @@ bool AsmParser::parseDirectiveSpace(Stri
/// parseDirectiveDCB
/// ::= .dcb.{b, l, w} expression, expression
bool AsmParser::parseDirectiveDCB(StringRef IDVal, unsigned Size) {
- checkForValidSection();
-
SMLoc NumValuesLoc = Lexer.getLoc();
int64_t NumValues;
- if (parseAbsoluteExpression(NumValues))
+ if (checkForValidSection() || parseAbsoluteExpression(NumValues))
return true;
if (NumValues < 0) {
@@ -4318,11 +4312,9 @@ bool AsmParser::parseDirectiveDCB(String
/// parseDirectiveRealDCB
/// ::= .dcb.{d, s} expression, expression
bool AsmParser::parseDirectiveRealDCB(StringRef IDVal, const fltSemantics &Semantics) {
- checkForValidSection();
-
SMLoc NumValuesLoc = Lexer.getLoc();
int64_t NumValues;
- if (parseAbsoluteExpression(NumValues))
+ if (checkForValidSection() || parseAbsoluteExpression(NumValues))
return true;
if (NumValues < 0) {
@@ -4352,11 +4344,10 @@ bool AsmParser::parseDirectiveRealDCB(St
/// parseDirectiveDS
/// ::= .ds.{b, d, l, p, s, w, x} expression
bool AsmParser::parseDirectiveDS(StringRef IDVal, unsigned Size) {
- checkForValidSection();
SMLoc NumValuesLoc = Lexer.getLoc();
int64_t NumValues;
- if (parseAbsoluteExpression(NumValues))
+ if (checkForValidSection() || parseAbsoluteExpression(NumValues))
return true;
if (NumValues < 0) {
@@ -4377,7 +4368,9 @@ bool AsmParser::parseDirectiveDS(StringR
/// parseDirectiveLEB128
/// ::= (.sleb128 | .uleb128) [ expression (, expression)* ]
bool AsmParser::parseDirectiveLEB128(bool Signed) {
- checkForValidSection();
+ if (checkForValidSection())
+ return true;
+
const MCExpr *Value;
while (true) {
@@ -4435,7 +4428,8 @@ bool AsmParser::parseDirectiveSymbolAttr
/// parseDirectiveComm
/// ::= ( .comm | .lcomm ) identifier , size_expression [ , align_expression ]
bool AsmParser::parseDirectiveComm(bool IsLocal) {
- checkForValidSection();
+ if (checkForValidSection())
+ return true;
SMLoc IDLoc = getLexer().getLoc();
StringRef Name;
More information about the llvm-commits
mailing list