Skip to content

Commit 6f2e08c

Browse files
committed
[Sparc] Add support for parsing directives in SparcAsmParser.
llvm-svn: 202564
1 parent f7eecf8 commit 6f2e08c

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class SparcAsmParser : public MCTargetAsmParser {
7373
unsigned &RegKind);
7474

7575
bool matchSparcAsmModifiers(const MCExpr *&EVal, SMLoc &EndLoc);
76+
bool parseDirectiveWord(unsigned Size, SMLoc L);
7677

78+
bool is64Bit() const { return STI.getTargetTriple().startswith("sparcv9"); }
7779
public:
7880
SparcAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
7981
const MCInstrInfo &MII)
@@ -482,8 +484,52 @@ ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
482484
bool SparcAsmParser::
483485
ParseDirective(AsmToken DirectiveID)
484486
{
485-
// Ignore all directives for now.
486-
Parser.eatToEndOfStatement();
487+
StringRef IDVal = DirectiveID.getString();
488+
489+
if (IDVal == ".byte")
490+
return parseDirectiveWord(1, DirectiveID.getLoc());
491+
492+
if (IDVal == ".half")
493+
return parseDirectiveWord(2, DirectiveID.getLoc());
494+
495+
if (IDVal == ".word")
496+
return parseDirectiveWord(4, DirectiveID.getLoc());
497+
498+
if (IDVal == ".nword")
499+
return parseDirectiveWord(is64Bit() ? 8 : 4, DirectiveID.getLoc());
500+
501+
if (is64Bit() && IDVal == ".xword")
502+
return parseDirectiveWord(8, DirectiveID.getLoc());
503+
504+
if (IDVal == ".register") {
505+
// For now, ignore .register directive.
506+
Parser.eatToEndOfStatement();
507+
return false;
508+
}
509+
510+
// Let the MC layer to handle other directives.
511+
return true;
512+
}
513+
514+
bool SparcAsmParser:: parseDirectiveWord(unsigned Size, SMLoc L) {
515+
if (getLexer().isNot(AsmToken::EndOfStatement)) {
516+
for (;;) {
517+
const MCExpr *Value;
518+
if (getParser().parseExpression(Value))
519+
return true;
520+
521+
getParser().getStreamer().EmitValue(Value, Size);
522+
523+
if (getLexer().is(AsmToken::EndOfStatement))
524+
break;
525+
526+
// FIXME: Improve diagnostic.
527+
if (getLexer().isNot(AsmToken::Comma))
528+
return Error(L, "unexpected token in directive");
529+
Parser.Lex();
530+
}
531+
}
532+
Parser.Lex();
487533
return false;
488534
}
489535

llvm/test/CodeGen/SPARC/mature-mc-support.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
; (even when the output is assembly).
33
; FIXME: SPARC doesn't use the integrated assembler by default in all cases
44
; so we only test that -filetype=obj tries to parse the assembly.
5-
; FIXME: SPARC seems to accept directives that don't exist
6-
; XFAIL: *
75

86
; SKIP: not llc -march=sparc < %s > /dev/null 2> %t1
97
; SKIP: FileCheck %s < %t1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! RUN: not llvm-mc %s -arch=sparc -show-encoding 2>&1 | FileCheck %s --check-prefix=SPARC32
2+
! RUN: llvm-mc %s -arch=sparcv9 -show-encoding | FileCheck %s --check-prefix=SPARC64
3+
4+
! SPARC32: error: unknown directive
5+
! SPARC32-NEXT: .xword 65536
6+
! SPARC32-NEXT: ^
7+
8+
! SPARC64: .xword 65536
9+
.xword 65536
10+

llvm/test/MC/Sparc/sparc-directives.s

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! RUN: llvm-mc %s -arch=sparc -show-encoding | FileCheck %s --check-prefix=SPARC32
2+
! RUN: llvm-mc %s -arch=sparcv9 -show-encoding | FileCheck %s --check-prefix=SPARC64
3+
4+
! SPARC32: .byte 24
5+
! SPARC64: .byte 24
6+
.byte 24
7+
8+
! SPARC32: .half 1024
9+
! SPARC64: .half 1024
10+
.half 1024
11+
12+
! SPARC32: .word 65536
13+
! SPARC64: .word 65536
14+
.word 65536
15+
16+
! SPARC32: .word 65536
17+
! SPARC64: .xword 65536
18+
.nword 65536
19+

0 commit comments

Comments
 (0)