Add a better error message when failing to assign one tablegen value to another
authorPete Cooper <peter_cooper@apple.com>
Thu, 31 Jul 2014 01:43:57 +0000 (01:43 +0000)
committerPete Cooper <peter_cooper@apple.com>
Thu, 31 Jul 2014 01:43:57 +0000 (01:43 +0000)
This is currently for assigning from one bit init to another.  It can easily be extended to other types.

Test to follow soon in another patch.

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

lib/TableGen/TGParser.cpp

index 0550692ebce7ff40f9d2c9084dd5dc42e518c7f7..54932487e8da9edf1fc4a1814f6db2ca4cdbefbe 100644 (file)
@@ -135,11 +135,18 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, Init *ValName,
     V = BitsInit::get(NewBits);
   }
 
-  if (RV->setValue(V))
+  if (RV->setValue(V)) {
+    std::string InitType = "";
+    if (BitsInit *BI = dyn_cast<BitsInit>(V)) {
+      InitType = (Twine("' of type bit initializer with length ") +
+                  Twine(BI->getNumBits())).str();
+    }
     return Error(Loc, "Value '" + ValName->getAsUnquotedString() + "' of type '"
                  + RV->getType()->getAsString() +
                  "' is incompatible with initializer '" + V->getAsString()
+                 + InitType
                  + "'");
+  }
   return false;
 }