[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.

llvm-svn: 332574
This commit is contained in:
Alex Bradbury 2018-05-17 05:58:08 +00:00
parent a2c5264718
commit cea6db0480
4 changed files with 61 additions and 0 deletions

View File

@ -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()));
}
};

View File

@ -22,4 +22,6 @@ RISCVMCAsmInfo::RISCVMCAsmInfo(const Triple &TT) {
CommentString = "#";
AlignmentIsInBytes = false;
SupportsDebugInformation = true;
Data16bitsDirective = "\t.half\t";
Data32bitsDirective = "\t.word\t";
}

View File

@ -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

View File

@ -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