[PATCH] AsmParser: add support for .end directive
Saleem Abdulrasool
compnerd at compnerd.org
Sun Dec 15 13:24:30 PST 2013
The .end directive indicates the end of the file. No further instructions are
processed after a .end directive is encountered.
One potential (glaringly obvious) optimisation that could be pursued here is to
extend MCAsmParser with a DiscardRemainder method to avoid processing lexemes to
the end of the file. It was unclear at this point if that would be worth
adding, and could easily be added in a follow on change.
http://llvm-reviews.chandlerc.com/D2414
Files:
lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/directive_end.s
Index: lib/MC/MCParser/AsmParser.cpp
===================================================================
--- lib/MC/MCParser/AsmParser.cpp
+++ lib/MC/MCParser/AsmParser.cpp
@@ -358,7 +358,8 @@
DK_CFI_RESTORE, DK_CFI_ESCAPE, DK_CFI_SIGNAL_FRAME, DK_CFI_UNDEFINED,
DK_CFI_REGISTER, DK_CFI_WINDOW_SAVE,
DK_MACROS_ON, DK_MACROS_OFF, DK_MACRO, DK_ENDM, DK_ENDMACRO, DK_PURGEM,
- DK_SLEB128, DK_ULEB128
+ DK_SLEB128, DK_ULEB128,
+ DK_END
};
/// \brief Maps directive name --> DirectiveKind enum, for
@@ -464,6 +465,9 @@
// "align"
bool parseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &Info);
+ // "end"
+ bool parseDirectiveEnd(SMLoc DirectiveLoc);
+
void initializeDirectiveKindMap();
};
}
@@ -1230,6 +1234,8 @@
return parseDirectiveElseIf(IDLoc);
case DK_ELSE:
return parseDirectiveElse(IDLoc);
+ case DK_END:
+ return parseDirectiveEnd(IDLoc);
case DK_ENDIF:
return parseDirectiveEndIf(IDLoc);
}
@@ -3746,6 +3752,20 @@
return false;
}
+/// parseDirectiveEnd
+/// ::= .end
+bool AsmParser::parseDirectiveEnd(SMLoc DirectiveLoc) {
+ if (getLexer().isNot(AsmToken::EndOfStatement))
+ return TokError("unexpected token in '.end' directive");
+
+ Lex();
+
+ while (Lexer.isNot(AsmToken::Eof))
+ Lex();
+
+ return false;
+}
+
/// parseDirectiveEndIf
/// ::= .endif
bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
@@ -3831,6 +3851,7 @@
DirectiveKindMap[".ifnotdef"] = DK_IFNOTDEF;
DirectiveKindMap[".elseif"] = DK_ELSEIF;
DirectiveKindMap[".else"] = DK_ELSE;
+ DirectiveKindMap[".end"] = DK_END;
DirectiveKindMap[".endif"] = DK_ENDIF;
DirectiveKindMap[".skip"] = DK_SKIP;
DirectiveKindMap[".space"] = DK_SPACE;
Index: test/MC/AsmParser/directive_end.s
===================================================================
--- /dev/null
+++ test/MC/AsmParser/directive_end.s
@@ -0,0 +1,11 @@
+# RUN: not llvm-mc -triple i386-unknown-unknown %s -filetype obj -o - \
+# RUN: | llvm-readobj -t | FileCheck %s
+
+ .end
+
+its_a_tarp:
+ int $0x3
+
+# CHECK: Symbol {
+# CHECK-NOT: Name: its_a_tarp
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2414.1.patch
Type: text/x-patch
Size: 2122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131215/57017bb3/attachment.bin>
More information about the llvm-commits
mailing list