[llvm] r332607 - [Hexagon] Use addAliasForDirective for data directives
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Thu May 17 06:21:18 PDT 2018
Author: asb
Date: Thu May 17 06:21:18 2018
New Revision: 332607
URL: http://llvm.org/viewvc/llvm-project?rev=332607&view=rev
Log:
[Hexagon] Use addAliasForDirective for data directives
Data directives such as .word, .half, .hword are currently parsed using
HexagonAsmParser::ParseDirectiveValue which effectively duplicates logic from
AsmParser::parseDirectiveValue. This patch deletes that duplicated logic in
favour of using addAliasForDirective.
Differential Revision: https://reviews.llvm.org/D46999
Added:
llvm/trunk/test/MC/Hexagon/data-directives-invalid.s
llvm/trunk/test/MC/Hexagon/data-directives-valid.s
Modified:
llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp
Modified: llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp?rev=332607&r1=332606&r2=332607&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp Thu May 17 06:21:18 2018
@@ -118,7 +118,6 @@ class HexagonAsmParser : public MCTarget
bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
bool ParseDirectiveSubsection(SMLoc L);
- bool ParseDirectiveValue(unsigned Size, SMLoc L);
bool ParseDirectiveComm(bool IsLocal, SMLoc L);
bool RegisterMatchesArch(unsigned MatchNum) const;
@@ -165,6 +164,10 @@ public:
MCB.setOpcode(Hexagon::BUNDLE);
setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
+ Parser.addAliasForDirective(".half", ".2byte");
+ Parser.addAliasForDirective(".hword", ".2byte");
+ Parser.addAliasForDirective(".word", ".4byte");
+
MCAsmParserExtension::Initialize(_Parser);
}
@@ -651,11 +654,6 @@ bool HexagonAsmParser::MatchAndEmitInstr
/// ParseDirective parses the Hexagon specific directives
bool HexagonAsmParser::ParseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getIdentifier();
- if ((IDVal.lower() == ".word") || (IDVal.lower() == ".4byte"))
- return ParseDirectiveValue(4, DirectiveID.getLoc());
- if (IDVal.lower() == ".short" || IDVal.lower() == ".hword" ||
- IDVal.lower() == ".half")
- return ParseDirectiveValue(2, DirectiveID.getLoc());
if (IDVal.lower() == ".falign")
return ParseDirectiveFalign(256, DirectiveID.getLoc());
if ((IDVal.lower() == ".lcomm") || (IDVal.lower() == ".lcommon"))
@@ -723,39 +721,6 @@ bool HexagonAsmParser::ParseDirectiveFal
return false;
}
-/// ::= .word [ expression (, expression)* ]
-bool HexagonAsmParser::ParseDirectiveValue(unsigned Size, SMLoc L) {
- if (getLexer().isNot(AsmToken::EndOfStatement)) {
- while (true) {
- const MCExpr *Value;
- SMLoc ExprLoc = L;
- if (getParser().parseExpression(Value))
- return true;
-
- // Special case constant expressions to match code generator.
- if (const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value)) {
- assert(Size <= 8 && "Invalid size");
- uint64_t IntValue = MCE->getValue();
- if (!isUIntN(8 * Size, IntValue) && !isIntN(8 * Size, IntValue))
- return Error(ExprLoc, "literal value out of range for directive");
- getStreamer().EmitIntValue(IntValue, Size);
- } else
- getStreamer().EmitValue(Value, Size);
-
- if (getLexer().is(AsmToken::EndOfStatement))
- break;
-
- // FIXME: Improve diagnostic.
- if (getLexer().isNot(AsmToken::Comma))
- return TokError("unexpected token in directive");
- Lex();
- }
- }
-
- Lex();
- return false;
-}
-
// This is largely a copy of AsmParser's ParseDirectiveComm extended to
// accept a 3rd argument, AccessAlignment which indicates the smallest
// memory access made to the symbol, expressed in bytes. If no
Added: llvm/trunk/test/MC/Hexagon/data-directives-invalid.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Hexagon/data-directives-invalid.s?rev=332607&view=auto
==============================================================================
--- llvm/trunk/test/MC/Hexagon/data-directives-invalid.s (added)
+++ llvm/trunk/test/MC/Hexagon/data-directives-invalid.s Thu May 17 06:21:18 2018
@@ -0,0 +1,20 @@
+# RUN: not llvm-mc -triple hexagon < %s 2>&1 | FileCheck %s
+
+# CHECK: [[@LINE+1]]:7: error: out of range literal value in '.byte' directive
+.byte 0xffa
+# CHECK: [[@LINE+1]]:7: error: out of range literal value in '.half' directive
+.half 0xffffa
+# CHECK: [[@LINE+1]]:8: error: out of range literal value in '.short' directive
+.short 0xffffa
+# CHECK: [[@LINE+1]]:8: error: out of range literal value in '.hword' directive
+.hword 0xffffa
+# CHECK: [[@LINE+1]]:8: error: out of range literal value in '.2byte' directive
+.2byte 0xffffa
+# CHECK: [[@LINE+1]]:7: error: out of range literal value in '.word' directive
+.word 0xffffffffa
+# CHECK: [[@LINE+1]]:7: error: out of range literal value in '.long' directive
+.long 0xffffffffa
+# CHECK: [[@LINE+1]]:8: error: out of range literal value in '.4byte' directive
+.4byte 0xffffffffa
+# CHECK: [[@LINE+1]]:8: error: literal value out of range for directive in '.8byte' directive
+.8byte 0xffffffffffffffffa
Added: llvm/trunk/test/MC/Hexagon/data-directives-valid.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Hexagon/data-directives-valid.s?rev=332607&view=auto
==============================================================================
--- llvm/trunk/test/MC/Hexagon/data-directives-valid.s (added)
+++ llvm/trunk/test/MC/Hexagon/data-directives-valid.s Thu May 17 06:21:18 2018
@@ -0,0 +1,25 @@
+# RUN: llvm-mc -filetype=obj -triple hexagon < %s \
+# RUN: | llvm-objdump -s - | FileCheck %s
+
+.data
+
+# CHECK: Contents of section .data:
+# CHECK-NEXT: 0000 deadbeef badcaf11 22334455 66778800
+.byte 0xde
+.half 0xbead
+.word 0xafdcbaef
+.8byte 0x8877665544332211
+.byte 0
+
+# CHECK-NEXT: 0010 deadbeef badcaf11 22334455 66778800
+.byte 0xde
+.2byte 0xbead
+.4byte 0xafdcbaef
+.8byte 0x8877665544332211
+.byte 0
+
+# CHECK-NEXT: 0020 deadbeef badcaf11 22
+.byte 0xde
+.short 0xbead
+.long 0xafdcbaef
+.hword 0x2211
More information about the llvm-commits
mailing list