[PATCH] [mips] [IAS] Implement the .asciiz directive.
Toma Tabacu
toma.tabacu at imgtec.com
Fri Apr 10 03:50:12 PDT 2015
Added a way to create aliases to directives in the target-independent AsmParser.
Add .asciiz as an alias of .asciz in MipsAsmParser.
By doing this, we can reuse the existing implementation of .asciz without enabling .asciiz for all the other supported architectures.
http://reviews.llvm.org/D7530
Files:
include/llvm/MC/MCParser/MCAsmParser.h
lib/MC/MCParser/AsmParser.cpp
lib/Target/Mips/AsmParser/MipsAsmParser.cpp
test/MC/Mips/asciiz-directive-bad.s
test/MC/Mips/asciiz-directive.s
Index: include/llvm/MC/MCParser/MCAsmParser.h
===================================================================
--- include/llvm/MC/MCParser/MCAsmParser.h
+++ include/llvm/MC/MCParser/MCAsmParser.h
@@ -84,6 +84,8 @@
virtual void addDirectiveHandler(StringRef Directive,
ExtensionDirectiveHandler Handler) = 0;
+ virtual void addAliasForDirective(StringRef Directive, StringRef Alias) = 0;
+
virtual SourceMgr &getSourceManager() = 0;
virtual MCAsmLexer &getLexer() = 0;
Index: lib/MC/MCParser/AsmParser.cpp
===================================================================
--- lib/MC/MCParser/AsmParser.cpp
+++ lib/MC/MCParser/AsmParser.cpp
@@ -184,6 +184,10 @@
ExtensionDirectiveMap[Directive] = Handler;
}
+ void addAliasForDirective(StringRef Directive, StringRef Alias) override {
+ DirectiveKindMap[Directive] = DirectiveKindMap[Alias];
+ }
+
public:
/// @name MCAsmParser Interface
/// {
Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp
===================================================================
--- lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -345,6 +345,8 @@
sti.getCPU(), Options)) {
MCAsmParserExtension::Initialize(parser);
+ parser.addAliasForDirective(".asciiz", ".asciz");
+
// Initialize the set of available features.
setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Index: test/MC/Mips/asciiz-directive-bad.s
===================================================================
--- /dev/null
+++ 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
Index: test/MC/Mips/asciiz-directive.s
===================================================================
--- /dev/null
+++ 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
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7530.23584.patch
Type: text/x-patch
Size: 2721 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150410/173f7684/attachment.bin>
More information about the llvm-commits
mailing list