Skip to content

Commit

Permalink
[mips] [IAS] Implement the .asciiz directive.
Browse files Browse the repository at this point in the history
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

llvm-svn: 235382
  • Loading branch information
Toma Tabacu committed Apr 21, 2015
1 parent 654af8f commit 11e14a9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions llvm/include/llvm/MC/MCParser/MCAsmParser.h
Expand Up @@ -84,6 +84,8 @@ class MCAsmParser {
virtual void addDirectiveHandler(StringRef Directive,
ExtensionDirectiveHandler Handler) = 0;

virtual void addAliasForDirective(StringRef Directive, StringRef Alias) = 0;

virtual SourceMgr &getSourceManager() = 0;

virtual MCAsmLexer &getLexer() = 0;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/MC/MCParser/AsmParser.cpp
Expand Up @@ -184,6 +184,10 @@ class AsmParser : public MCAsmParser {
ExtensionDirectiveMap[Directive] = Handler;
}

void addAliasForDirective(StringRef Directive, StringRef Alias) override {
DirectiveKindMap[Directive] = DirectiveKindMap[Alias];
}

public:
/// @name MCAsmParser Interface
/// {
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
Expand Up @@ -349,6 +349,8 @@ class MipsAsmParser : public MCTargetAsmParser {
sti.getCPU(), Options)) {
MCAsmParserExtension::Initialize(parser);

parser.addAliasForDirective(".asciiz", ".asciz");

// Initialize the set of available features.
setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));

Expand Down
8 changes: 8 additions & 0 deletions llvm/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
28 changes: 28 additions & 0 deletions llvm/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

0 comments on commit 11e14a9

Please sign in to comment.