[PATCH] D47004: [X86] Use addAliasForDirective to support the .word directive

Alex Bradbury via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 17 00:54:15 PDT 2018


asb created this revision.
asb added a reviewer: craig.topper.

The X86 asm parser currently has custom parsing logic for .word. Rather than use this custom logic, we can just use addAliasForDirective to enable the reuse of AsmParser::parseDirectiveValue.


https://reviews.llvm.org/D47004

Files:
  lib/Target/X86/AsmParser/X86AsmParser.cpp


Index: lib/Target/X86/AsmParser/X86AsmParser.cpp
===================================================================
--- lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -844,7 +844,6 @@
                         const InlineAsmIdentifierInfo &Info);
 
   bool parseDirectiveEven(SMLoc L);
-  bool ParseDirectiveWord(unsigned Size, SMLoc L);
   bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
 
   /// CodeView FPO data directives.
@@ -943,6 +942,8 @@
       : MCTargetAsmParser(Options, sti, mii),  InstInfo(nullptr),
         Code16GCC(false) {
 
+    Parser.addAliasForDirective(".word", ".4byte");
+
     // Initialize the set of available features.
     setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
     Instrumentation.reset(
@@ -3155,9 +3156,7 @@
 bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
   MCAsmParser &Parser = getParser();
   StringRef IDVal = DirectiveID.getIdentifier();
-  if (IDVal == ".word")
-    return ParseDirectiveWord(2, DirectiveID.getLoc());
-  else if (IDVal.startswith(".code"))
+  if (IDVal.startswith(".code"))
     return ParseDirectiveCode(IDVal, DirectiveID.getLoc());
   else if (IDVal.startswith(".att_syntax")) {
     getParser().setParsingInlineAsm(false);
@@ -3218,27 +3217,6 @@
     getStreamer().EmitValueToAlignment(2, 0, 1, 0);
   return false;
 }
-/// ParseDirectiveWord
-///  ::= .word [ expression (, expression)* ]
-bool X86AsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
-  auto parseOp = [&]() -> bool {
-    const MCExpr *Value;
-    SMLoc ExprLoc = getLexer().getLoc();
-    if (getParser().parseExpression(Value))
-      return true;
-    if (const auto *MCE = dyn_cast<MCConstantExpr>(Value)) {
-      assert(Size <= 8 && "Invalid size");
-      uint64_t IntValue = MCE->getValue();
-      if (!isUIntN(8 * Size, IntValue) && !isIntN(8 * Size, IntValue))
-        return Error(ExprLoc, "literal value out of range for directive");
-      getStreamer().EmitIntValue(IntValue, Size);
-    } else
-      getStreamer().EmitValue(Value, Size, ExprLoc);
-    return false;
-  };
-  parseMany(parseOp);
-  return false;
-}
 
 /// ParseDirectiveCode
 ///  ::= .code16 | .code32 | .code64


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47004.147257.patch
Type: text/x-patch
Size: 2229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180517/a6e5ee67/attachment.bin>


More information about the llvm-commits mailing list