Use INT64_C to emit constant values, to avoid problems with
[oota-llvm.git] / utils / TableGen / TGParser.cpp
index 2f0533a18dbfce308c97ae9edc076477b7685c1e..4ff108d2603a40ffc8f9e78b279b72b54e6d5c91 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"
@@ -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;
@@ -611,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;