Close list item tag, to conform with the style in this file. It's optional
[oota-llvm.git] / utils / TableGen / TGParser.cpp
index d6515e8b384ce10cb6df2430da00e8ee31c4fa71..1ea6b9816f6d34a3dac6451152a3ddb0939d6cf1 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -11,6 +11,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <algorithm>
+
 #include "TGParser.h"
 #include "Record.h"
 #include "llvm/ADT/StringExtras.h"
@@ -116,13 +118,13 @@ bool TGParser::SetValue(Record *CurRec, LocTy Loc, const std::string &ValName,
   if (RV->setValue(V))
    return Error(Loc, "Value '" + ValName + "' of type '" + 
                 RV->getType()->getAsString() + 
-                "' is incompatible with initializer ''"); // FIXME: Add init!
+                "' is incompatible with initializer '" + V->getAsString() +"'");
   return false;
 }
 
 /// AddSubClass - Add SubClass as a subclass to CurRec, resolving its template
 /// args as SubClass's template arguments.
-bool TGParser::AddSubClass(Record *CurRec, class SubClassReference &SubClass) {
+bool TGParser::AddSubClass(Record *CurRec, SubClassReference &SubClass) {
   Record *SC = SubClass.Rec;
   // Add all of the values in the subclass into the current class.
   const std::vector<RecordVal> &Vals = SC->getValues();
@@ -288,9 +290,12 @@ ParseSubClassReference(Record *CurRec, bool isDefm) {
 ///   RangePiece ::= INTVAL '-' INTVAL
 ///   RangePiece ::= INTVAL INTVAL
 bool TGParser::ParseRangePiece(std::vector<unsigned> &Ranges) {
-  assert(Lex.getCode() == tgtok::IntVal && "Invalid range");
-  int Start = Lex.getCurIntVal();
-  int End;
+  if (Lex.getCode() != tgtok::IntVal) {
+    TokError("expected integer or bitrange");
+    return true;
+  }
+  int64_t Start = Lex.getCurIntVal();
+  int64_t End;
   
   if (Start < 0)
     return TokError("invalid range, cannot be negative");
@@ -421,7 +426,7 @@ RecTy *TGParser::ParseType() {
       TokError("expected integer in bits<n> type");
       return 0;
     }
-    unsigned Val = Lex.getCurIntVal();
+    uint64_t Val = Lex.getCurIntVal();
     if (Lex.Lex() != tgtok::greater) {  // Eat count.
       TokError("expected '>' at end of bits<n> type");
       return 0;
@@ -586,9 +591,8 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) {
     for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
       Init *Bit = Vals[i]->convertInitializerTo(new BitRecTy());
       if (Bit == 0) {
-        // FIXME: Include value in error.
-        Error(BraceLoc, "Element #" + utostr(i) + " ("/* << *Vals[i]
-             <<*/ ") is not convertable to a bit");
+        Error(BraceLoc, "Element #" + utostr(i) + " (" + Vals[i]->getAsString()+
+              ") is not convertable to a bit");
         return 0;
       }
       Result->setBit(Vals.size()-i-1, Bit);
@@ -612,6 +616,11 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) {
   }
   case tgtok::l_paren: {         // Value ::= '(' IDValue DagArgList ')'
     Lex.Lex();   // eat the '('
+    if (Lex.getCode() != tgtok::Id) {
+      TokError("expected identifier in dag init");
+      return 0;
+    }
+    
     Init *Operator = ParseIDValue(CurRec);
     if (Operator == 0) return 0;
     
@@ -737,9 +746,8 @@ Init *TGParser::ParseValue(Record *CurRec) {
         return 0;
       }
       if (!Result->getFieldType(Lex.getCurStrVal())) {
-        // FIXME INCLUDE VALUE IN ERROR.
         TokError("Cannot access field '" + Lex.getCurStrVal() + "' of value '" +
-                 /*<< *$1 <<*/ "'");
+                 Result->getAsString() + "'");
         return 0;
       }
       Result = new FieldInit(Result, Lex.getCurStrVal());