[llvm] r337893 - [mips] Replace custom parsing logic for data directives by the `addAliasForDirective`
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 25 00:07:44 PDT 2018
Author: atanasyan
Date: Wed Jul 25 00:07:43 2018
New Revision: 337893
URL: http://llvm.org/viewvc/llvm-project?rev=337893&view=rev
Log:
[mips] Replace custom parsing logic for data directives by the `addAliasForDirective`
The target independent AsmParser doesn't recognise .hword, .word, .dword
which are required for Mips. Currently MipsAsmParser recognises these
through dispatch to MipsAsmParser::parseDataDirective. This contains
equivalent logic to AsmParser::parseDirectiveValue. This patch allows
reuse of AsmParser::parseDirectiveValue by making use of
addAliasForDirective to support .hword, .word and .dword.
Original patch provided by Alex Bradbury at D47001 was modified to fix
handling of microMIPS symbols. The `AsmParser::parseDirectiveValue`
calls either `EmitIntValue` or `EmitValue`. In this patch we override
`EmitIntValue` in the `MipsELFStreamer` to clear a pending set of
microMIPS symbols.
Differential revision: https://reviews.llvm.org/D49539
Modified:
llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
llvm/trunk/test/MC/Mips/micromips-label-test.s
Modified: llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp?rev=337893&r1=337892&r2=337893&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Mips/AsmParser/MipsAsmParser.cpp Wed Jul 25 00:07:43 2018
@@ -355,7 +355,6 @@ class MipsAsmParser : public MCTargetAsm
bool parseSetAssignment();
- bool parseDataDirective(unsigned Size, SMLoc L);
bool parseDirectiveGpWord();
bool parseDirectiveGpDWord();
bool parseDirectiveDtpRelWord();
@@ -487,6 +486,9 @@ public:
MCAsmParserExtension::Initialize(parser);
parser.addAliasForDirective(".asciiz", ".asciz");
+ parser.addAliasForDirective(".hword", ".2byte");
+ parser.addAliasForDirective(".word", ".4byte");
+ parser.addAliasForDirective(".dword", ".8byte");
// Initialize the set of available features.
setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
@@ -7357,31 +7359,6 @@ bool MipsAsmParser::parseDirectiveSet()
return parseSetAssignment();
}
-/// parseDataDirective
-/// ::= .word [ expression (, expression)* ]
-bool MipsAsmParser::parseDataDirective(unsigned Size, SMLoc L) {
- MCAsmParser &Parser = getParser();
- 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;
-
- if (getLexer().isNot(AsmToken::Comma))
- return Error(L, "unexpected token, expected comma");
- Parser.Lex();
- }
- }
-
- Parser.Lex();
- return false;
-}
-
/// parseDirectiveGpWord
/// ::= .gpword local_sym
bool MipsAsmParser::parseDirectiveGpWord() {
@@ -7961,10 +7938,6 @@ bool MipsAsmParser::ParseDirective(AsmTo
parseDirectiveCpRestore(DirectiveID.getLoc());
return false;
}
- if (IDVal == ".dword") {
- parseDataDirective(8, DirectiveID.getLoc());
- return false;
- }
if (IDVal == ".ent") {
StringRef SymbolName;
@@ -8212,16 +8185,6 @@ bool MipsAsmParser::ParseDirective(AsmTo
return false;
}
- if (IDVal == ".word") {
- parseDataDirective(4, DirectiveID.getLoc());
- return false;
- }
-
- if (IDVal == ".hword") {
- parseDataDirective(2, DirectiveID.getLoc());
- return false;
- }
-
if (IDVal == ".option") {
parseDirectiveOption();
return false;
Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp?rev=337893&r1=337892&r2=337893&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp Wed Jul 25 00:07:43 2018
@@ -86,6 +86,11 @@ void MipsELFStreamer::EmitValueImpl(cons
Labels.clear();
}
+void MipsELFStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
+ MCELFStreamer::EmitIntValue(Value, Size);
+ Labels.clear();
+}
+
void MipsELFStreamer::EmitMipsOptionRecords() {
for (const auto &I : MipsOptionRecords)
I->EmitMipsOptionRecord();
Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h?rev=337893&r1=337892&r2=337893&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h (original)
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h Wed Jul 25 00:07:43 2018
@@ -54,9 +54,11 @@ public:
void SwitchSection(MCSection *Section,
const MCExpr *Subsection = nullptr) override;
- /// Overriding this function allows us to dismiss all labels that are
- /// candidates for marking as microMIPS when .word directive is emitted.
+ /// Overriding these functions allows us to dismiss all labels that are
+ /// candidates for marking as microMIPS when .word/.long/.4byte etc
+ /// directives are emitted.
void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
+ void EmitIntValue(uint64_t Value, unsigned Size) override;
/// Emits all the option records stored up until the point it's called.
void EmitMipsOptionRecords();
Modified: llvm/trunk/test/MC/Mips/micromips-label-test.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/micromips-label-test.s?rev=337893&r1=337892&r2=337893&view=diff
==============================================================================
--- llvm/trunk/test/MC/Mips/micromips-label-test.s (original)
+++ llvm/trunk/test/MC/Mips/micromips-label-test.s Wed Jul 25 00:07:43 2018
@@ -9,6 +9,16 @@ g:
nop
h:
.word 0
+k:
+ .long 0
+l:
+ .hword 0
+m:
+ .2byte 0
+n:
+ .4byte 0
+o:
+ .8byte 0
i:
nop
j:
@@ -54,5 +64,39 @@ j:
# CHECK: Other: 0
# CHECK: Section: .text
# CHECK: }
+# CHECK: Symbol {
+# CHECK: Name: k
+# CHECK: Binding: Local
+# CHECK: Type: None
+# CHECK: Other: 0
+# CHECK: Section: .text
+# CHECK: }
+# CHECK: Symbol {
+# CHECK: Name: l
+# CHECK: Binding: Local
+# CHECK: Type: None
+# CHECK: Other: 0
+# CHECK: Section: .text
+# CHECK: }
+# CHECK: Symbol {
+# CHECK: Name: m
+# CHECK: Binding: Local
+# CHECK: Type: None
+# CHECK: Other: 0
+# CHECK: Section: .text
+# CHECK: }
+# CHECK: Symbol {
+# CHECK: Name: n
+# CHECK: Binding: Local
+# CHECK: Type: None
+# CHECK: Other: 0
+# CHECK: Section: .text
+# CHECK: }
+# CHECK: Symbol {
+# CHECK: Name: o
+# CHECK: Binding: Local
+# CHECK: Type: None
+# CHECK: Other: 0
+# CHECK: Section: .text
+# CHECK: }
# CHECK: ]
-
More information about the llvm-commits
mailing list