[llvm] r332574 - [RISCV] Add support for .half, .hword, .word, .dword directives

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Wed May 16 22:58:08 PDT 2018


Author: asb
Date: Wed May 16 22:58:08 2018
New Revision: 332574

URL: http://llvm.org/viewvc/llvm-project?rev=332574&view=rev
Log:
[RISCV] Add support for .half, .hword, .word, .dword directives

These directives are recognised by gas. Support is added through the use of 
addAliasForDirective.

Also match RISC-V gcc in preferring .half and .word for 16-bit and 32-bit data 
directives.

Added:
    llvm/trunk/test/MC/RISCV/data-directives-invalid.s
    llvm/trunk/test/MC/RISCV/data-directives-valid.s
Modified:
    llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
    llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp

Modified: llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp?rev=332574&r1=332573&r2=332574&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp Wed May 16 22:58:08 2018
@@ -105,6 +105,10 @@ public:
   RISCVAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser,
                  const MCInstrInfo &MII, const MCTargetOptions &Options)
       : MCTargetAsmParser(Options, STI, MII) {
+    Parser.addAliasForDirective(".half", ".2byte");
+    Parser.addAliasForDirective(".hword", ".2byte");
+    Parser.addAliasForDirective(".word", ".4byte");
+    Parser.addAliasForDirective(".dword", ".8byte");
     setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
   }
 };

Modified: llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp?rev=332574&r1=332573&r2=332574&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp Wed May 16 22:58:08 2018
@@ -22,4 +22,6 @@ RISCVMCAsmInfo::RISCVMCAsmInfo(const Tri
   CommentString = "#";
   AlignmentIsInBytes = false;
   SupportsDebugInformation = true;
+  Data16bitsDirective = "\t.half\t";
+  Data32bitsDirective = "\t.word\t";
 }

Added: llvm/trunk/test/MC/RISCV/data-directives-invalid.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/RISCV/data-directives-invalid.s?rev=332574&view=auto
==============================================================================
--- llvm/trunk/test/MC/RISCV/data-directives-invalid.s (added)
+++ llvm/trunk/test/MC/RISCV/data-directives-invalid.s Wed May 16 22:58:08 2018
@@ -0,0 +1,23 @@
+# RUN: not llvm-mc -triple riscv32 < %s 2>&1 | FileCheck %s
+# RUN: not llvm-mc -triple riscv64 < %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 '.dword' directive
+.dword 0xffffffffffffffffa
+# CHECK: [[@LINE+1]]:8: error: literal value out of range for directive in '.8byte' directive
+.8byte 0xffffffffffffffffa

Added: llvm/trunk/test/MC/RISCV/data-directives-valid.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/RISCV/data-directives-valid.s?rev=332574&view=auto
==============================================================================
--- llvm/trunk/test/MC/RISCV/data-directives-valid.s (added)
+++ llvm/trunk/test/MC/RISCV/data-directives-valid.s Wed May 16 22:58:08 2018
@@ -0,0 +1,32 @@
+# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
+# RUN:     | llvm-objdump -s - | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
+# RUN:     | llvm-objdump -s - | FileCheck %s
+
+# Check that data directives supported by gas are also supported by LLVM MC.
+# As there was some confusion about whether .half/.word/.dword imply
+# alignment (see <https://github.com/riscv/riscv-asm-manual/issues/12>), we
+# are sure to check this.
+
+.data
+
+# CHECK: Contents of section .data:
+# CHECK-NEXT: 0000 deadbeef badcaf11 22334455 66778800
+.byte 0xde
+.half 0xbead
+.word 0xafdcbaef
+.dword 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