From 203a9224ffb75cb50e6583303f705bf7173b9d99 Mon Sep 17 00:00:00 2001 From: Toma Tabacu Date: Tue, 21 Apr 2015 11:50:52 +0000 Subject: [PATCH] [mips] [IAS] Implement the .asciiz directive. Summary: This directive is exactly the same as .asciz, except it's only used by MIPS. It is used to store null terminated strings in object files. Reviewers: rafael, dsanders, echristo Reviewed By: dsanders, echristo Subscribers: echristo, llvm-commits Differential Revision: http://reviews.llvm.org/D7530 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235382 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCParser/MCAsmParser.h | 2 ++ lib/MC/MCParser/AsmParser.cpp | 4 ++++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 2 ++ test/MC/Mips/asciiz-directive-bad.s | 8 ++++++++ test/MC/Mips/asciiz-directive.s | 28 ++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+) create mode 100644 test/MC/Mips/asciiz-directive-bad.s create mode 100644 test/MC/Mips/asciiz-directive.s diff --git a/include/llvm/MC/MCParser/MCAsmParser.h b/include/llvm/MC/MCParser/MCAsmParser.h index 83ffbb5044d..7dcefdb9892 100644 --- a/include/llvm/MC/MCParser/MCAsmParser.h +++ b/include/llvm/MC/MCParser/MCAsmParser.h @@ -84,6 +84,8 @@ public: virtual void addDirectiveHandler(StringRef Directive, ExtensionDirectiveHandler Handler) = 0; + virtual void addAliasForDirective(StringRef Directive, StringRef Alias) = 0; + virtual SourceMgr &getSourceManager() = 0; virtual MCAsmLexer &getLexer() = 0; diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 92a75074ab5..12b9cf561a8 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -184,6 +184,10 @@ public: ExtensionDirectiveMap[Directive] = Handler; } + void addAliasForDirective(StringRef Directive, StringRef Alias) override { + DirectiveKindMap[Directive] = DirectiveKindMap[Alias]; + } + public: /// @name MCAsmParser Interface /// { diff --git a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 6f7e3c16a9b..7615f87f721 100644 --- a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -349,6 +349,8 @@ public: sti.getCPU(), Options)) { MCAsmParserExtension::Initialize(parser); + parser.addAliasForDirective(".asciiz", ".asciz"); + // Initialize the set of available features. setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); diff --git a/test/MC/Mips/asciiz-directive-bad.s b/test/MC/Mips/asciiz-directive-bad.s new file mode 100644 index 00000000000..0f30cfbee63 --- /dev/null +++ b/test/MC/Mips/asciiz-directive-bad.s @@ -0,0 +1,8 @@ +# RUN: not llvm-mc -triple mips-unknown-linux %s 2>&1 | FileCheck %s + + .asciiz 12 +# CHECK: :[[@LINE-1]]:11: error: expected string in '.asciiz' directive + .asciiz "a"3 +# CHECK: :[[@LINE-1]]:14: error: unexpected token in '.asciiz' directive + .asciiz "a", +# CHECK: :[[@LINE-1]]:15: error: expected string in '.asciiz' directive diff --git a/test/MC/Mips/asciiz-directive.s b/test/MC/Mips/asciiz-directive.s new file mode 100644 index 00000000000..0e582145c71 --- /dev/null +++ b/test/MC/Mips/asciiz-directive.s @@ -0,0 +1,28 @@ +# RUN: llvm-mc -triple mips-unknown-linux %s | FileCheck %s +# .asciiz is exactly the same as .asciz, except it's MIPS-specific. + +t1: + .asciiz +# CHECK-LABEL: t1 + +t2: + .asciiz "a" +# CHECK-LABEL: t2 +# CHECK: .byte 97 +# CHECK: .byte 0 + +t3: + .asciiz "a", "b", "c" +# CHECK-LABEL: t3 +# CHECK: .byte 97 +# CHECK: .byte 0 +# CHECK: .byte 98 +# CHECK: .byte 0 +# CHECK: .byte 99 +# CHECK: .byte 0 + +t4: + .asciiz "abcdefghijklmnop" +# CHECK-LABEL: t4 +# CHECK: .ascii "abcdefghijklmnop" +# CHECK: .byte 0 -- 2.11.0