[ms-inline asm] Split the parsing of IR asm strings into GCC and MS variants.
[oota-llvm.git] / lib / TableGen / TGParser.cpp
index b9c7ff694d7f417912fa2a0d6944cbcfb2cc7784..aee93e7696b99f074291e78d9c0f1ca28a7e3aa6 100644 (file)
@@ -1044,35 +1044,28 @@ Init *TGParser::ParseOperation(Record *CurRec) {
     switch (LexCode) {
     default: llvm_unreachable("Unhandled code!");
     case tgtok::XIf: {
-      // FIXME: The `!if' operator doesn't handle non-TypedInit well at
-      // all. This can be made much more robust.
-      TypedInit *MHSt = dynamic_cast<TypedInit*>(MHS);
-      TypedInit *RHSt = dynamic_cast<TypedInit*>(RHS);
-
       RecTy *MHSTy = 0;
       RecTy *RHSTy = 0;
 
-      if (MHSt == 0 && RHSt == 0) {
-        BitsInit *MHSbits = dynamic_cast<BitsInit*>(MHS);
-        BitsInit *RHSbits = dynamic_cast<BitsInit*>(RHS);
-
-        if (MHSbits && RHSbits &&
-            MHSbits->getNumBits() == RHSbits->getNumBits()) {
-          Type = BitRecTy::get();
-          break;
-        } else {
-          BitInit *MHSbit = dynamic_cast<BitInit*>(MHS);
-          BitInit *RHSbit = dynamic_cast<BitInit*>(RHS);
-
-          if (MHSbit && RHSbit) {
-            Type = BitRecTy::get();
-            break;
-          }
-        }
-      } else if (MHSt != 0 && RHSt != 0) {
+      if (TypedInit *MHSt = dynamic_cast<TypedInit*>(MHS))
         MHSTy = MHSt->getType();
+      if (BitsInit *MHSbits = dynamic_cast<BitsInit*>(MHS))
+        MHSTy = BitsRecTy::get(MHSbits->getNumBits());
+      if (dynamic_cast<BitInit*>(MHS))
+        MHSTy = BitRecTy::get();
+
+      if (TypedInit *RHSt = dynamic_cast<TypedInit*>(RHS))
         RHSTy = RHSt->getType();
-      }
+      if (BitsInit *RHSbits = dynamic_cast<BitsInit*>(RHS))
+        RHSTy = BitsRecTy::get(RHSbits->getNumBits());
+      if (dynamic_cast<BitInit*>(RHS))
+        RHSTy = BitRecTy::get();
+
+      // For UnsetInit, it's typed from the other hand.
+      if (dynamic_cast<UnsetInit*>(MHS))
+        MHSTy = RHSTy;
+      if (dynamic_cast<UnsetInit*>(RHS))
+        RHSTy = MHSTy;
 
       if (!MHSTy || !RHSTy) {
         TokError("could not get type for !if");
@@ -2277,7 +2270,10 @@ InstantiateMulticlassDef(MultiClass &MC,
                      DefName, StringRecTy::get())->Fold(DefProto, &MC);
   }
 
-  Record *CurRec = new Record(DefName, DefmPrefixLoc, Records);
+  // Make a trail of SMLocs from the multiclass instantiations.
+  SmallVector<SMLoc, 4> Locs(1, DefmPrefixLoc);
+  Locs.append(DefProto->getLoc().begin(), DefProto->getLoc().end());
+  Record *CurRec = new Record(DefName, Locs, Records);
 
   SubClassReference Ref;
   Ref.RefLoc = DefmPrefixLoc;