[Sparc] Use addAliasForDirective to support data directives

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

llvm-svn: 333078
This commit is contained in:
Alex Bradbury 2018-05-23 11:20:28 +00:00
parent 0a59f18951
commit 3fa69dd055
1 changed files with 6 additions and 38 deletions

View File

@ -95,7 +95,6 @@ class SparcAsmParser : public MCTargetAsmParser {
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 @@ public:
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 @@ ParseDirective(AsmToken DirectiveID)
{
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 @@ ParseDirective(AsmToken DirectiveID)
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;