[PATCH] D57061: [X86] Support 'offset' when parsing intel syntax through llvm-mc or gcc inline assembly

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 11:35:20 PST 2019


craig.topper created this revision.
craig.topper added reviewers: rnk, echristo, efriedma.

Currently we only support the "offset" keyword during the first pass on MS style inline assembly. This means its unvailable to gcc inline assembly or just using llvm-mc. gas seems to support this when parsing intel syntax.

This patch adds support outside of the first pass of MS inline assembly. I left the first pass MS inline assembly code alone for now and added a fixme. I'm not sure if its correct or not. It looks to delete the 'offset' keyword as part of its rewrite, but that seems wrong.


https://reviews.llvm.org/D57061

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


Index: test/MC/X86/intel-syntax-var-offset.s
===================================================================
--- /dev/null
+++ test/MC/X86/intel-syntax-var-offset.s
@@ -0,0 +1,12 @@
+// RUN: llvm-mc %s -triple x86_64-unknown-unknown -show-encoding | FileCheck %s
+
+.intel_syntax noprefix
+// CHECK: movq $X, %rax
+// CHECK: encoding: [0x48,0xc7,0xc0,A,A,A,A]
+// CHECK: fixup A - offset: 3, value: X, kind: reloc_signed_4byte
+mov rax, offset X
+
+// CHECK: movq $X+1, %rax
+// CHECK: encoding: [0x48,0xc7,0xc0,A,A,A,A]
+// CHECK: fixup A - offset: 3, value: X+1, kind: reloc_signed_4byte
+mov rax, offset X + 1
Index: lib/Target/X86/AsmParser/X86AsmParser.cpp
===================================================================
--- lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1834,10 +1834,25 @@
   // FIXME: Offset operator
   // Should be handled as part of immediate expression, as other operators
   // Currently, only supported as a stand-alone operand
-  if (isParsingInlineAsm())
-    if (IdentifyIntelInlineAsmOperator(Tok.getString()) == IOK_OFFSET)
+  if (IdentifyIntelInlineAsmOperator(Tok.getString()) == IOK_OFFSET) {
+    // FIXME: Should MS inline assembly parsing really be handling this
+    // differently?
+    if (isParsingInlineAsm())
       return ParseIntelOffsetOfOperator();
 
+    // Not parsing MS inline assembly. Parse this like '$' in AT&T.
+    Parser.Lex();
+    const MCExpr *Val;
+    // This is an immediate, so we should not parse a register. Do a precheck
+    // for '%' to supercede intra-register parse errors.
+    SMLoc L = Parser.getTok().getLoc();
+    if (getParser().parseExpression(Val, End) ||
+        check(isa<X86MCExpr>(Val), L, "expected immediate expression"))
+      return nullptr;
+    return X86Operand::CreateImm(Val, Start, End);
+  }
+
+
   // Parse optional Size directive.
   unsigned Size;
   if (ParseIntelMemoryOperandSize(Size))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57061.182950.patch
Type: text/x-patch
Size: 1950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190122/a165e374/attachment.bin>


More information about the llvm-commits mailing list