[PATCH] D31277: [X86][MS-compatability]Allow named synonymous for MS-assembly operators

coby via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 22 23:09:29 PDT 2017


coby created this revision.

This patch enhances X86AsmParser's immediate expression parsing abilities, to include a named synonymous for selected binary/unary bitwise operators: {and,shl,shr,or,xor,not}, ultimately achieving better MS-compatability
MASM reference:
https://msdn.microsoft.com/en-us/library/94b6khh4.aspx


Repository:
  rL LLVM

https://reviews.llvm.org/D31277

Files:
  lib/Target/X86/AsmParser/X86AsmParser.cpp
  test/MC/X86/intel-syntax-bitwise-ops.s


Index: lib/Target/X86/AsmParser/X86AsmParser.cpp
===================================================================
--- lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -679,6 +679,29 @@
         break;
       }
     }
+    // Some binary bitwise operators have a named synonymous
+    // Query a candidate string for being such a named operator
+    // and if so - invoke the appropriate handler
+    bool onNamedOperator(StringRef Name) {
+      // A named operator should be either lower or upper case, but not a mix
+      if (Name.compare(Name.lower()) && Name.compare(Name.upper()))
+        return false;
+      if (Name.equals_lower("not"))
+        onNot();
+      else if (Name.equals_lower("or"))
+        onOr();
+      else if (Name.equals_lower("shl"))
+        onLShift();
+      else if (Name.equals_lower("shr"))
+        onRShift();
+      else if (Name.equals_lower("xor"))
+        onXor();
+      else if (Name.equals_lower("and"))
+        onAnd();
+      else
+        return false;
+      return true;
+    }
   };
 
   bool Error(SMLoc L, const Twine &Msg, SMRange Range = None,
@@ -1339,6 +1362,8 @@
       UpdateLocLex = false;
       if (TK != AsmToken::String && !ParseRegister(TmpReg, IdentLoc, End)) {
         SM.onRegister(TmpReg);
+      } else if (SM.onNamedOperator(Identifier)) {
+        UpdateLocLex = true;
       } else if (!isParsingInlineAsm()) {
         if (getParser().parsePrimaryExpr(Val, End))
           return Error(Tok.getLoc(), "Unexpected identifier!");
Index: test/MC/X86/intel-syntax-bitwise-ops.s
===================================================================
--- test/MC/X86/intel-syntax-bitwise-ops.s
+++ test/MC/X86/intel-syntax-bitwise-ops.s
@@ -6,19 +6,37 @@
     and ecx, 1+2
 // CHECK: andl	$3, %ecx
     and ecx, 1|2
-// CHECK: andl	$3, %ecx
+// CHECK: andl $3, %ecx
+    and ecx, 1 or 2
+// CHECK: andl $3, %ecx
     and ecx, 1*3
 // CHECK: andl	$1, %ecx
     and ecx, 1&3
-// CHECK: andl	$0, %ecx
+// CHECK: andl $1, %ecx
+    and ecx, 1 and 3
+// CHECK: andl $0, %ecx
     and ecx, (1&2)
-// CHECK: andl	$3, %ecx
+// CHECK: andl $0, %ecx
+    and ecx, (1 and 2)
+// CHECK: andl $3, %ecx
     and ecx, ((1)|2)
-// CHECK: andl	$1, %ecx
+// CHECK: andl $3, %ecx
+    and ecx, ((1) or 2)
+// CHECK: andl $1, %ecx
     and ecx, 1&2+3
-// CHECK: addl	$4938, %eax
+// CHECK: andl $1, %ecx
+    and ecx, 1 and 2+3
+// CHECK: addl $4938, %eax
     add eax, 9876 >> 1
-// CHECK: addl	$19752, %eax
+// CHECK: addl $4938, %eax
+    add eax, 9876 shr 1
+// CHECK: addl $19752, %eax
     add eax, 9876 << 1
-// CHECK: addl	$5, %eax
+// CHECK: addl $19752, %eax
+    add eax, 9876 shl 1
+// CHECK: addl $5, %eax
     add eax, 6 ^ 3
+// CHECK: addl $5, %eax
+    add eax, 6 xor 3
+// CHECK: addl $-9, %eax
+    add eax, not 8


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31277.92760.patch
Type: text/x-patch
Size: 2907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170323/111004ac/attachment.bin>


More information about the llvm-commits mailing list