[PATCH] D47003: [Sparc] Use addAliasForDirective to support data directives
Alex Bradbury via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 17 00:49:02 PDT 2018
asb created this revision.
asb added reviewers: venkatra, jyknight.
Herald added a subscriber: fedor.sergeev.
The Sparc asm parser currently has custom parsing logic for .half, .word, .nword and .xword. Rather than use this custom logic, we can just use addAliasForDirective to enable the reuse of AsmParser::parseDirectiveValue.
https://reviews.llvm.org/D47003
Files:
lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
Index: lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
===================================================================
--- lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -95,7 +95,6 @@
unsigned &RegKind);
bool matchSparcAsmModifiers(const MCExpr *&EVal, SMLoc &EndLoc);
- bool parseDirectiveWord(unsigned Size, SMLoc L);
bool is64Bit() const {
return getSTI().getTargetTriple().getArch() == Triple::sparcv9;
@@ -109,6 +108,12 @@
const MCInstrInfo &MII,
const MCTargetOptions &Options)
: MCTargetAsmParser(Options, sti, MII), Parser(parser) {
+ Parser.addAliasForDirective(".half", ".2byte");
+ Parser.addAliasForDirective(".word", ".4byte");
+ Parser.addAliasForDirective(".nword", is64Bit() ? ".8byte" : ".4byte");
+ if (is64Bit())
+ Parser.addAliasForDirective(".xword", ".8byte");
+
// Initialize the set of available features.
setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
}
@@ -682,21 +687,6 @@
{
StringRef IDVal = DirectiveID.getString();
- if (IDVal == ".byte")
- return parseDirectiveWord(1, DirectiveID.getLoc());
-
- if (IDVal == ".half")
- return parseDirectiveWord(2, DirectiveID.getLoc());
-
- if (IDVal == ".word")
- return parseDirectiveWord(4, DirectiveID.getLoc());
-
- if (IDVal == ".nword")
- return parseDirectiveWord(is64Bit() ? 8 : 4, DirectiveID.getLoc());
-
- if (is64Bit() && IDVal == ".xword")
- return parseDirectiveWord(8, DirectiveID.getLoc());
-
if (IDVal == ".register") {
// For now, ignore .register directive.
Parser.eatToEndOfStatement();
@@ -713,28 +703,6 @@
return true;
}
-bool SparcAsmParser:: parseDirectiveWord(unsigned Size, SMLoc L) {
- if (getLexer().isNot(AsmToken::EndOfStatement)) {
- while (true) {
- const MCExpr *Value;
- if (getParser().parseExpression(Value))
- return true;
-
- getParser().getStreamer().EmitValue(Value, Size);
-
- if (getLexer().is(AsmToken::EndOfStatement))
- break;
-
- // FIXME: Improve diagnostic.
- if (getLexer().isNot(AsmToken::Comma))
- return Error(L, "unexpected token in directive");
- Parser.Lex();
- }
- }
- Parser.Lex();
- return false;
-}
-
OperandMatchResultTy
SparcAsmParser::parseMEMOperand(OperandVector &Operands) {
SMLoc S, E;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47003.147255.patch
Type: text/x-patch
Size: 2431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180517/29e0a499/attachment.bin>
More information about the llvm-commits
mailing list