]> granicus.if.org Git - llvm/commitdiff
Revert "This patch enables the usage of constant Enum identifiers within Microsoft...
authorEric Christopher <echristo@gmail.com>
Tue, 25 Jul 2017 19:22:09 +0000 (19:22 +0000)
committerEric Christopher <echristo@gmail.com>
Tue, 25 Jul 2017 19:22:09 +0000 (19:22 +0000)
This reverts commit r308966.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309005 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCParser/MCAsmParser.h
lib/Target/X86/AsmParser/X86AsmParser.cpp

index 3827904876092754cb91cc5d74a4db6cd57c5689..3a659f048ccf6f41a8158e84a0ab72c9f78c9282 100644 (file)
@@ -35,30 +35,17 @@ class MCTargetAsmParser;
 class SourceMgr;
 
 class InlineAsmIdentifierInfo {
-private:
-  enum IdDeclKind : uint8_t {
-    Default,
-    Variable,
-    ConstEnum,
-  };
-  IdDeclKind Kind;
-
 public:
   void *OpDecl;
+  bool IsVarDecl;
   unsigned Length, Size, Type;
-  APInt ConstIntValue;
-  bool isVarDecl() { return Kind == Variable; }
-  bool isConstEnum() { return Kind == ConstEnum; }
-  void setKindVariable() { Kind = Variable; }
-  void setKindConstEnum() { Kind = ConstEnum; }
+
   void clear() {
     OpDecl = nullptr;
-    Kind = Default;
+    IsVarDecl = false;
     Length = 1;
     Size = 0;
     Type = 0;
-    // On clear flush possibly old APInt value as a precaution;
-    ConstIntValue = APInt();
   }
 };
 
index 62dc948494b9c3859cd524fcc059b8bf30e2dbb2..3e2a64a21852b87901f591364b656a43313943fc 100644 (file)
@@ -777,7 +777,7 @@ private:
   std::unique_ptr<X86Operand> ParseIntelOffsetOfOperator();
   bool ParseIntelDotOperator(const MCExpr *Disp, const MCExpr *&NewDisp);
   unsigned IdentifyIntelOperator(StringRef Name);
-  unsigned ParseIntelOperator(unsigned OpKind, bool AddImmPrefix);
+  unsigned ParseIntelOperator(unsigned OpKind);
   std::unique_ptr<X86Operand>
   ParseIntelSegmentOverride(unsigned SegReg, SMLoc Start, unsigned Size);
   std::unique_ptr<X86Operand> ParseRoundingModeOp(SMLoc Start, SMLoc End);
@@ -1251,7 +1251,7 @@ std::unique_ptr<X86Operand> X86AsmParser::CreateMemForInlineAsm(
     InlineAsmIdentifierInfo &Info, bool AllowBetterSizeMatch) {
   // If we found a decl other than a VarDecl, then assume it is a FuncDecl or
   // some other label reference.
-  if (isa<MCSymbolRefExpr>(Disp) && Info.OpDecl && !Info.isVarDecl()) {
+  if (isa<MCSymbolRefExpr>(Disp) && Info.OpDecl && !Info.IsVarDecl) {
     // Insert an explicit size if the user didn't have one.
     if (!Size) {
       Size = getPointerWidth();
@@ -1427,7 +1427,7 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
         if (OpKind == IOK_OFFSET) 
           return Error(IdentLoc, "Dealing OFFSET operator as part of"
             "a compound immediate expression is yet to be supported");
-        int64_t Val = ParseIntelOperator(OpKind,SM.getAddImmPrefix());
+        int64_t Val = ParseIntelOperator(OpKind);
         if (!Val)
           return true;
         if (SM.onInteger(Val, ErrMsg))
@@ -1436,38 +1436,11 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
             PrevTK == AsmToken::RBrac) {
           return false;
       } else {
-        InlineAsmIdentifierInfo Info;
-        if (ParseIntelIdentifier(Val, Identifier, Info,\r
+        InlineAsmIdentifierInfo &Info = SM.getIdentifierInfo();
+        if (ParseIntelIdentifier(Val, Identifier, Info,
                                  /*Unevaluated=*/false, End))
-          return true;\r
-        // Check if the parsed identifier was a constant Integer. Here we\r
-        // assume Val is of type MCConstantExpr only when it is safe to replace\r
-        // the identifier with its constant value.\r
-        if (const MCConstantExpr *CE =\r
-                dyn_cast_or_null<const MCConstantExpr>(Val)) {\r
-          StringRef ErrMsg;\r
-          // Pass the enum identifier integer value to the SM calculator.\r
-          if (SM.onInteger(CE->getValue(), ErrMsg))\r
-            return Error(IdentLoc, ErrMsg);\r
-          // Match the behavior of integer tokens when getAddImmPrefix flag is\r
-          // set.\r
-          if (SM.getAddImmPrefix()) {\r
-            assert(isParsingInlineAsm() &&\r
-                   "Expected to be parsing inline assembly.");\r
-            // A single rewrite of the integer value is preformed for each enum\r
-            // identifier. This is only done when we are inside a bracketed\r
-            // expression.\r
-            size_t Len = End.getPointer() - IdentLoc.getPointer();\r
-            InstInfo->AsmRewrites->emplace_back(AOK_Imm, IdentLoc, Len,\r
-                                                CE->getValue());\r
-            break;\r
-          }\r
-        } else {\r
-          // Notify the SM a variable identifier was found.\r
-          InlineAsmIdentifierInfo &SMInfo = SM.getIdentifierInfo();\r
-          SMInfo = Info;\r
-          SM.onIdentifierExpr(Val, Identifier);\r
-        }\r
+          return true;
+        SM.onIdentifierExpr(Val, Identifier);
       }
       break;
     }
@@ -1660,14 +1633,6 @@ bool X86AsmParser::ParseIntelIdentifier(const MCExpr *&Val,
   assert((End.getPointer() == EndPtr || !Result) &&
          "frontend claimed part of a token?");
 
-  // Check if the search yielded a constant integer (enum identifier).
-  if (Result && Info.isConstEnum()) {
-    // By creating MCConstantExpr we let the user of Val know it is safe
-    // to use as an explicit constant with value = ConstVal.
-    Val = MCConstantExpr::create(Info.ConstIntValue.getSExtValue(),
-                                 getParser().getContext());
-    return false;
-  }
   // If the identifier lookup was unsuccessful, assume that we are dealing with
   // a label.
   if (!Result) {
@@ -1865,7 +1830,7 @@ unsigned X86AsmParser::IdentifyIntelOperator(StringRef Name) {
 /// variable.  A variable's size is the product of its LENGTH and TYPE.  The
 /// TYPE operator returns the size of a C or C++ type or variable. If the
 /// variable is an array, TYPE returns the size of a single element.
-unsigned X86AsmParser::ParseIntelOperator(unsigned OpKind, bool AddImmPrefix) {
+unsigned X86AsmParser::ParseIntelOperator(unsigned OpKind) {
   MCAsmParser &Parser = getParser();
   const AsmToken &Tok = Parser.getTok();
   SMLoc TypeLoc = Tok.getLoc();
@@ -1891,17 +1856,12 @@ unsigned X86AsmParser::ParseIntelOperator(unsigned OpKind, bool AddImmPrefix) {
   case IOK_SIZE: CVal = Info.Size; break;
   case IOK_TYPE: CVal = Info.Type; break;
   }
-  
-  // Only when in bracketed mode, preform explicit rewrite. This is requierd to
-  // avoid rewrite collision.
-  if (AddImmPrefix) {
-    // Rewrite the type operator and the C or C++ type or variable in terms of
-    // an immediate. e.g. mov eax, [eax + SIZE _foo * $$4] ->
-    // mov eax, [eax + $$1 * $$4].
-    unsigned Len = End.getPointer() - TypeLoc.getPointer();
-    InstInfo->AsmRewrites->emplace_back(AOK_Imm, TypeLoc, Len, CVal);
-  }
-  
+
+  // Rewrite the type operator and the C or C++ type or variable in terms of an
+  // immediate.  E.g. TYPE foo -> $$4
+  unsigned Len = End.getPointer() - TypeLoc.getPointer();
+  InstInfo->AsmRewrites->emplace_back(AOK_Imm, TypeLoc, Len, CVal);
+
   return CVal;
 }
 
@@ -1972,8 +1932,14 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseIntelOperand() {
   if (SM.getSym() && SM.getSym()->getKind() == MCExpr::Constant)
     SM.getSym()->evaluateAsAbsolute(Imm);
 
-  if (isParsingInlineAsm() && !isSymbol) {
+  if (StartTok.isNot(AsmToken::Identifier) &&
+      StartTok.isNot(AsmToken::String) && isParsingInlineAsm()) {
     unsigned Len = Tok.getLoc().getPointer() - Start.getPointer();
+    if (StartTok.getString().size() == Len)
+      // Just add a prefix if this wasn't a complex immediate expression.
+      InstInfo->AsmRewrites->emplace_back(AOK_ImmPrefix, Start);
+    else
+      // Otherwise, rewrite the complex expression as a single immediate.
       InstInfo->AsmRewrites->emplace_back(AOK_Imm, Start, Len, Imm);
   }