[llvm] r333078 - [Sparc] Use addAliasForDirective to support data directives
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Wed May 23 04:20:28 PDT 2018
Author: asb
Date: Wed May 23 04:20:28 2018
New Revision: 333078
URL: http://llvm.org/viewvc/llvm-project?rev=333078&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
Modified: llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp?rev=333078&r1=333077&r2=333078&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp Wed May 23 04:20:28 2018
@@ -95,7 +95,6 @@ class SparcAsmParser : public MCTargetAs
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;
More information about the llvm-commits
mailing list