[llvm] r202564 - [Sparc] Add support for parsing directives in SparcAsmParser.

Venkatraman Govindaraju venkatra at cs.wisc.edu
Fri Feb 28 18:18:05 PST 2014


Author: venkatra
Date: Fri Feb 28 20:18:04 2014
New Revision: 202564

URL: http://llvm.org/viewvc/llvm-project?rev=202564&view=rev
Log:
[Sparc] Add support for parsing directives in SparcAsmParser.

Added:
    llvm/trunk/test/MC/Sparc/sparc-directive-xword.s
    llvm/trunk/test/MC/Sparc/sparc-directives.s
Modified:
    llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
    llvm/trunk/test/CodeGen/SPARC/mature-mc-support.ll

Modified: llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp?rev=202564&r1=202563&r2=202564&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp Fri Feb 28 20:18:04 2014
@@ -73,7 +73,9 @@ class SparcAsmParser : public MCTargetAs
                          unsigned &RegKind);
 
   bool matchSparcAsmModifiers(const MCExpr *&EVal, SMLoc &EndLoc);
+  bool parseDirectiveWord(unsigned Size, SMLoc L);
 
+  bool is64Bit() const { return STI.getTargetTriple().startswith("sparcv9"); }
 public:
   SparcAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser,
                 const MCInstrInfo &MII)
@@ -482,8 +484,52 @@ ParseInstruction(ParseInstructionInfo &I
 bool SparcAsmParser::
 ParseDirective(AsmToken DirectiveID)
 {
-  // Ignore all directives for now.
-  Parser.eatToEndOfStatement();
+  StringRef IDVal = DirectiveID.getString();
+
+  if (IDVal == ".byte")
+    return parseDirectiveWord(1, DirectiveID.getLoc());
+
+  if (IDVal == ".half")
+    return parseDirectiveWord(2, DirectiveID.getLoc());
+
+  if (IDVal == ".word")
+    return parseDirectiveWord(4, DirectiveID.getLoc());
+
+  if (IDVal == ".nword")
+    return parseDirectiveWord(is64Bit() ? 8 : 4, DirectiveID.getLoc());
+
+  if (is64Bit() && IDVal == ".xword")
+    return parseDirectiveWord(8, DirectiveID.getLoc());
+
+  if (IDVal == ".register") {
+    // For now, ignore .register directive.
+    Parser.eatToEndOfStatement();
+    return false;
+  }
+
+  // Let the MC layer to handle other directives.
+  return true;
+}
+
+bool SparcAsmParser:: parseDirectiveWord(unsigned Size, SMLoc L) {
+  if (getLexer().isNot(AsmToken::EndOfStatement)) {
+    for (;;) {
+      const MCExpr *Value;
+      if (getParser().parseExpression(Value))
+        return true;
+
+      getParser().getStreamer().EmitValue(Value, Size);
+
+      if (getLexer().is(AsmToken::EndOfStatement))
+        break;
+
+      // FIXME: Improve diagnostic.
+      if (getLexer().isNot(AsmToken::Comma))
+        return Error(L, "unexpected token in directive");
+      Parser.Lex();
+    }
+  }
+  Parser.Lex();
   return false;
 }
 

Modified: llvm/trunk/test/CodeGen/SPARC/mature-mc-support.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SPARC/mature-mc-support.ll?rev=202564&r1=202563&r2=202564&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SPARC/mature-mc-support.ll (original)
+++ llvm/trunk/test/CodeGen/SPARC/mature-mc-support.ll Fri Feb 28 20:18:04 2014
@@ -2,8 +2,6 @@
 ; (even when the output is assembly).
 ; FIXME: SPARC doesn't use the integrated assembler by default in all cases
 ; so we only test that -filetype=obj tries to parse the assembly.
-; FIXME: SPARC seems to accept directives that don't exist
-; XFAIL: *
 
 ; SKIP: not llc -march=sparc < %s > /dev/null 2> %t1
 ; SKIP: FileCheck %s < %t1

Added: llvm/trunk/test/MC/Sparc/sparc-directive-xword.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Sparc/sparc-directive-xword.s?rev=202564&view=auto
==============================================================================
--- llvm/trunk/test/MC/Sparc/sparc-directive-xword.s (added)
+++ llvm/trunk/test/MC/Sparc/sparc-directive-xword.s Fri Feb 28 20:18:04 2014
@@ -0,0 +1,10 @@
+! RUN: not llvm-mc %s -arch=sparc   -show-encoding 2>&1 | FileCheck %s --check-prefix=SPARC32
+! RUN: llvm-mc %s -arch=sparcv9 -show-encoding | FileCheck %s --check-prefix=SPARC64
+
+        ! SPARC32:       error: unknown directive
+        ! SPARC32-NEXT:  .xword 65536
+        ! SPARC32-NEXT:  ^
+
+        ! SPARC64:  .xword 65536
+        .xword 65536
+

Added: llvm/trunk/test/MC/Sparc/sparc-directives.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Sparc/sparc-directives.s?rev=202564&view=auto
==============================================================================
--- llvm/trunk/test/MC/Sparc/sparc-directives.s (added)
+++ llvm/trunk/test/MC/Sparc/sparc-directives.s Fri Feb 28 20:18:04 2014
@@ -0,0 +1,19 @@
+! RUN: llvm-mc %s -arch=sparc   -show-encoding | FileCheck %s --check-prefix=SPARC32
+! RUN: llvm-mc %s -arch=sparcv9 -show-encoding | FileCheck %s --check-prefix=SPARC64
+
+        ! SPARC32: .byte 24
+        ! SPARC64: .byte 24
+        .byte 24
+
+        ! SPARC32: .half 1024
+        ! SPARC64: .half 1024
+        .half 1024
+
+        ! SPARC32: .word 65536
+        ! SPARC64: .word 65536
+        .word 65536
+
+        ! SPARC32: .word 65536
+        ! SPARC64: .xword 65536
+        .nword 65536
+





More information about the llvm-commits mailing list