[PATCH] D12261: [Sparc] Accept %0 through %31 as registers in assembly code.

Douglas Katzman via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 19:34:08 PDT 2015


dougk created this revision.
dougk added a reviewer: jyknight.
dougk added a subscriber: llvm-commits.

This syntax appears in actual code in the wild, and is valid according to gnu as.

http://reviews.llvm.org/D12261

Files:
  lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
  test/MC/Sparc/sparc-alu-instructions.s

Index: test/MC/Sparc/sparc-alu-instructions.s
===================================================================
--- test/MC/Sparc/sparc-alu-instructions.s
+++ test/MC/Sparc/sparc-alu-instructions.s
@@ -126,3 +126,7 @@
 
         ! CHECK:  tsubcctv %g2, %g1, %g3          ! encoding: [0x87,0x18,0x80,0x01]
         tsubcctv %g2, %g1, %g3
+
+        ! "%0" is a synonym for "%g0" and so on
+        ! CHECK:   mov	 %g0, %i7                 ! encoding: [0xbe,0x10,0x00,0x00]
+        mov %0, %31
Index: lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
===================================================================
--- lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
+++ lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
@@ -1023,6 +1023,19 @@
       return true;
     }
   }
+  // For compatibility with other assemblers, %0 through %31 refer to integer
+  // registers without subdividing them into globals,locals,outs,ins.
+  // Strictly speaking, the valid spellings exclude alternative ways of
+  // writing the decimal integers, but the lexer doesn't know that.
+  if (Tok.is(AsmToken::Integer)) {
+    intVal = Tok.getIntVal();
+    // The size() check rejects "%001", "%0b1", "%0x1" as putative spellings.
+    if (intVal >= 0 && intVal < 32 && Tok.getString().size()<= 2) {
+        RegNo = IntRegs[intVal];
+        RegKind = SparcOperand::rk_IntReg;
+        return true;
+    }
+  }
   return false;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12261.32893.patch
Type: text/x-patch
Size: 1412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150822/59bd39ec/attachment.bin>


More information about the llvm-commits mailing list