mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
refactor .if handling code a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101659 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f84755b836
commit
7834facff9
@ -102,8 +102,6 @@ private:
|
||||
/// EnterIncludeFile - Enter the specified file. This returns true on failure.
|
||||
bool EnterIncludeFile(const std::string &Filename);
|
||||
|
||||
bool ParseConditionalAssemblyDirectives(StringRef Directive,
|
||||
SMLoc DirectiveLoc);
|
||||
void EatToEndOfStatement();
|
||||
|
||||
bool ParseAssignment(const StringRef &Name);
|
||||
|
@ -117,29 +117,6 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
|
||||
|
||||
// While we have input, parse each statement.
|
||||
while (Lexer.isNot(AsmToken::Eof)) {
|
||||
// Handle conditional assembly here before calling ParseStatement()
|
||||
if (Lexer.getKind() == AsmToken::Identifier) {
|
||||
// If we have an identifier, handle it as the key symbol.
|
||||
AsmToken ID = getTok();
|
||||
SMLoc IDLoc = ID.getLoc();
|
||||
StringRef IDVal = ID.getString();
|
||||
|
||||
if (IDVal == ".if" ||
|
||||
IDVal == ".elseif" ||
|
||||
IDVal == ".else" ||
|
||||
IDVal == ".endif") {
|
||||
if (!ParseConditionalAssemblyDirectives(IDVal, IDLoc))
|
||||
continue;
|
||||
HadError = true;
|
||||
EatToEndOfStatement();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (TheCondState.Ignore) {
|
||||
EatToEndOfStatement();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ParseStatement()) continue;
|
||||
|
||||
// We had an error, remember it and recover by skipping to the next line.
|
||||
@ -159,21 +136,6 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
|
||||
return HadError;
|
||||
}
|
||||
|
||||
/// ParseConditionalAssemblyDirectives - parse the conditional assembly
|
||||
/// directives
|
||||
bool AsmParser::ParseConditionalAssemblyDirectives(StringRef Directive,
|
||||
SMLoc DirectiveLoc) {
|
||||
if (Directive == ".if")
|
||||
return ParseDirectiveIf(DirectiveLoc);
|
||||
if (Directive == ".elseif")
|
||||
return ParseDirectiveElseIf(DirectiveLoc);
|
||||
if (Directive == ".else")
|
||||
return ParseDirectiveElse(DirectiveLoc);
|
||||
if (Directive == ".endif")
|
||||
return ParseDirectiveEndIf(DirectiveLoc);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// EatToEndOfStatement - Throw away the rest of the line for testing purposes.
|
||||
void AsmParser::EatToEndOfStatement() {
|
||||
while (Lexer.isNot(AsmToken::EndOfStatement) &&
|
||||
@ -457,9 +419,30 @@ bool AsmParser::ParseStatement() {
|
||||
AsmToken ID = getTok();
|
||||
SMLoc IDLoc = ID.getLoc();
|
||||
StringRef IDVal;
|
||||
if (ParseIdentifier(IDVal))
|
||||
return TokError("unexpected token at start of statement");
|
||||
if (ParseIdentifier(IDVal)) {
|
||||
if (!TheCondState.Ignore)
|
||||
return TokError("unexpected token at start of statement");
|
||||
IDVal = "";
|
||||
}
|
||||
|
||||
// Handle conditional assembly here before checking for skipping. We
|
||||
// have to do this so that .endif isn't skipped in a ".if 0" block for
|
||||
// example.
|
||||
if (IDVal == ".if")
|
||||
return ParseDirectiveIf(IDLoc);
|
||||
if (IDVal == ".elseif")
|
||||
return ParseDirectiveElseIf(IDLoc);
|
||||
if (IDVal == ".else")
|
||||
return ParseDirectiveElse(IDLoc);
|
||||
if (IDVal == ".endif")
|
||||
return ParseDirectiveEndIf(IDLoc);
|
||||
|
||||
// If we are in a ".if 0" block, ignore this statement.
|
||||
if (TheCondState.Ignore) {
|
||||
EatToEndOfStatement();
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME: Recurse on local labels?
|
||||
|
||||
// See what kind of statement we have.
|
||||
@ -1577,9 +1560,6 @@ bool AsmParser::ParseDirectiveDarwinDumpOrLoad(SMLoc IDLoc, bool IsDump) {
|
||||
/// ParseDirectiveIf
|
||||
/// ::= .if expression
|
||||
bool AsmParser::ParseDirectiveIf(SMLoc DirectiveLoc) {
|
||||
// Consume the identifier that was the .if directive
|
||||
Lex();
|
||||
|
||||
TheCondStack.push_back(TheCondState);
|
||||
TheCondState.TheCond = AsmCond::IfCond;
|
||||
if(TheCondState.Ignore) {
|
||||
@ -1611,9 +1591,6 @@ bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) {
|
||||
" an .elseif");
|
||||
TheCondState.TheCond = AsmCond::ElseIfCond;
|
||||
|
||||
// Consume the identifier that was the .elseif directive
|
||||
Lex();
|
||||
|
||||
bool LastIgnoreState = false;
|
||||
if (!TheCondStack.empty())
|
||||
LastIgnoreState = TheCondStack.back().Ignore;
|
||||
@ -1640,9 +1617,6 @@ bool AsmParser::ParseDirectiveElseIf(SMLoc DirectiveLoc) {
|
||||
/// ParseDirectiveElse
|
||||
/// ::= .else
|
||||
bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) {
|
||||
// Consume the identifier that was the .else directive
|
||||
Lex();
|
||||
|
||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||
return TokError("unexpected token in '.else' directive");
|
||||
|
||||
@ -1667,9 +1641,6 @@ bool AsmParser::ParseDirectiveElse(SMLoc DirectiveLoc) {
|
||||
/// ParseDirectiveEndIf
|
||||
/// ::= .endif
|
||||
bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) {
|
||||
// Consume the identifier that was the .endif directive
|
||||
Lex();
|
||||
|
||||
if (Lexer.isNot(AsmToken::EndOfStatement))
|
||||
return TokError("unexpected token in '.endif' directive");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user