Skip to content

Commit

Permalink
[MCAsmParser] Move AltMacroMode tracking out of MCAsmLexer
Browse files Browse the repository at this point in the history
The Lexer doesn't use this state itself. It is only set and used by AsmParser so it seems like it should just be part of AsmParser.

Differential Revision: https://reviews.llvm.org/D52515

llvm-svn: 343027
  • Loading branch information
topperc committed Sep 25, 2018
1 parent 96335dd commit c81aff7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
9 changes: 0 additions & 9 deletions llvm/include/llvm/MC/MCParser/MCAsmLexer.h
Expand Up @@ -52,7 +52,6 @@ class MCAsmLexer {
bool IsAtStartOfStatement = true;
AsmCommentConsumer *CommentConsumer = nullptr;

bool AltMacroMode;
MCAsmLexer();

virtual AsmToken LexToken() = 0;
Expand All @@ -67,14 +66,6 @@ class MCAsmLexer {
MCAsmLexer &operator=(const MCAsmLexer &) = delete;
virtual ~MCAsmLexer();

bool IsaAltMacroMode() {
return AltMacroMode;
}

void SetAltMacroMode(bool AltMacroSet) {
AltMacroMode = AltMacroSet;
}

/// Consume the next token from the input stream and return it.
///
/// The lexer will continuously return the end-of-file token once the end of
Expand Down
17 changes: 8 additions & 9 deletions llvm/lib/MC/MCParser/AsmParser.cpp
Expand Up @@ -180,6 +180,9 @@ class AsmParser : public MCAsmParser {
/// Did we already inform the user about inconsistent MD5 usage?
bool ReportedInconsistentMD5 = false;

// Is alt macro mode enabled.
bool AltMacroMode = false;

public:
AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
const MCAsmInfo &MAI, unsigned CB);
Expand Down Expand Up @@ -2443,14 +2446,13 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
// Here, we identify the integer token which is the result of the
// absolute expression evaluation and replace it with its string
// representation.
if (Lexer.IsaAltMacroMode() && Token.getString().front() == '%' &&
if (AltMacroMode && Token.getString().front() == '%' &&
Token.is(AsmToken::Integer))
// Emit an integer value to the buffer.
OS << Token.getIntVal();
// Only Token that was validated as a string and begins with '<'
// is considered altMacroString!!!
else if (Lexer.IsaAltMacroMode() &&
Token.getString().front() == '<' &&
else if (AltMacroMode && Token.getString().front() == '<' &&
Token.is(AsmToken::String)) {
OS << altMacroString(Token.getStringContents());
}
Expand Down Expand Up @@ -2634,7 +2636,7 @@ bool AsmParser::parseMacroArguments(const MCAsmMacro *M,

SMLoc StrLoc = Lexer.getLoc();
SMLoc EndLoc;
if (Lexer.IsaAltMacroMode() && Lexer.is(AsmToken::Percent)) {
if (AltMacroMode && Lexer.is(AsmToken::Percent)) {
const MCExpr *AbsoluteExp;
int64_t Value;
/// Eat '%'
Expand All @@ -2649,7 +2651,7 @@ bool AsmParser::parseMacroArguments(const MCAsmMacro *M,
AsmToken newToken(AsmToken::Integer,
StringRef(StrChar, EndChar - StrChar), Value);
FA.Value.push_back(newToken);
} else if (Lexer.IsaAltMacroMode() && Lexer.is(AsmToken::Less) &&
} else if (AltMacroMode && Lexer.is(AsmToken::Less) &&
isAltmacroString(StrLoc, EndLoc)) {
const char *StrChar = StrLoc.getPointer();
const char *EndChar = EndLoc.getPointer();
Expand Down Expand Up @@ -4186,10 +4188,7 @@ bool AsmParser::parseDirectiveCFIUndefined(SMLoc DirectiveLoc) {
bool AsmParser::parseDirectiveAltmacro(StringRef Directive) {
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '" + Directive + "' directive");
if (Directive == ".altmacro")
getLexer().SetAltMacroMode(true);
else
getLexer().SetAltMacroMode(false);
AltMacroMode = (Directive == ".altmacro");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCParser/MCAsmLexer.cpp
Expand Up @@ -15,7 +15,7 @@

using namespace llvm;

MCAsmLexer::MCAsmLexer() : AltMacroMode(false) {
MCAsmLexer::MCAsmLexer() {
CurTok.emplace_back(AsmToken::Space, StringRef());
}

Expand Down

0 comments on commit c81aff7

Please sign in to comment.