use escape string.
[oota-llvm.git] / utils / TableGen / Record.cpp
index 06d9bf236d35b1b9f6e61361696b5f54d8ebf30f..e2d9657c4d24c03130f1f28d8f1db88403f11d6e 100644 (file)
@@ -35,7 +35,7 @@ bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const {
 }
 
 Init *BitRecTy::convertValue(IntInit *II) {
-  int Val = II->getValue();
+  int64_t Val = II->getValue();
   if (Val != 0 && Val != 1) return 0;  // Only accept 0 or 1 for a bit!
 
   return new BitInit(Val != 0);
@@ -116,7 +116,7 @@ Init *IntRecTy::convertValue(BitInit *BI) {
 }
 
 Init *IntRecTy::convertValue(BitsInit *BI) {
-  int Result = 0;
+  int64_t Result = 0;
   for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
     if (BitInit *Bit = dynamic_cast<BitInit*>(BI->getBit(i))) {
       Result |= Bit->getValue() << i;
@@ -262,7 +262,7 @@ std::string BitsInit::getAsString() const {
 
 bool BitsInit::printInHex(std::ostream &OS) const {
   // First, attempt to convert the value into an integer value...
-  int Result = 0;
+  int64_t Result = 0;
   for (unsigned i = 0, e = getNumBits(); i != e; ++i)
     if (BitInit *Bit = dynamic_cast<BitInit*>(getBit(i))) {
       Result |= Bit->getValue() << i;
@@ -338,11 +338,11 @@ Init *IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
   BitsInit *BI = new BitsInit(Bits.size());
 
   for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
-    if (Bits[i] >= 32) {
+    if (Bits[i] >= 64) {
       delete BI;
       return 0;
     }
-    BI->setBit(i, new BitInit(Value & (1 << Bits[i])));
+    BI->setBit(i, new BitInit(Value & (INT64_C(1) << Bits[i])));
   }
   return BI;
 }
@@ -426,7 +426,7 @@ Init *BinOpInit::Fold() {
         Args.push_back(RHSs->getArg(i));
         ArgNames.push_back(RHSs->getArgName(i));
       }
-      return new DagInit(LHSs->getOperator(), Args, ArgNames);
+      return new DagInit(LHSs->getOperator(), "", Args, ArgNames);
     }
     break;
   }
@@ -443,13 +443,13 @@ Init *BinOpInit::Fold() {
     IntInit *LHSi = dynamic_cast<IntInit*>(LHS);
     IntInit *RHSi = dynamic_cast<IntInit*>(RHS);
     if (LHSi && RHSi) {
-      int LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
-      int Result;
+      int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
+      int64_t Result;
       switch (getOpcode()) {
       default: assert(0 && "Bad opcode!");
       case SHL: Result = LHSv << RHSv; break;
       case SRA: Result = LHSv >> RHSv; break;
-      case SRL: Result = (unsigned)LHSv >> (unsigned)RHSv; break;
+      case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
       }
       return new IntInit(Result);
     }
@@ -679,7 +679,7 @@ Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
   Init *Op = Val->resolveReferences(R, RV);
   
   if (Args != NewArgs || Op != Val)
-    return new DagInit(Op, NewArgs, ArgNames);
+    return new DagInit(Op, "", NewArgs, ArgNames);
     
   return this;
 }
@@ -687,6 +687,8 @@ Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
 
 std::string DagInit::getAsString() const {
   std::string Result = "(" + Val->getAsString();
+  if (!ValName.empty())
+    Result += ":" + ValName;
   if (Args.size()) {
     Result += " " + Args[0]->getAsString();
     if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0];
@@ -861,10 +863,10 @@ Record::getValueAsListOfDefs(const std::string &FieldName) const {
 }
 
 /// getValueAsInt - This method looks up the specified field and returns its
-/// value as an int, throwing an exception if the field does not exist or if
+/// value as an int64_t, throwing an exception if the field does not exist or if
 /// the value is not the right type.
 ///
-int Record::getValueAsInt(const std::string &FieldName) const {
+int64_t Record::getValueAsInt(const std::string &FieldName) const {
   const RecordVal *R = getValue(FieldName);
   if (R == 0 || R->getValue() == 0)
     throw "Record `" + getName() + "' does not have a field named `" +
@@ -880,10 +882,10 @@ int Record::getValueAsInt(const std::string &FieldName) const {
 /// its value as a vector of integers, throwing an exception if the field does
 /// not exist or if the value is not the right type.
 ///
-std::vector<int> 
+std::vector<int64_t
 Record::getValueAsListOfInts(const std::string &FieldName) const {
   ListInit *List = getValueAsListInit(FieldName);
-  std::vector<int> Ints;
+  std::vector<int64_t> Ints;
   for (unsigned i = 0; i < List->getSize(); i++) {
     if (IntInit *II = dynamic_cast<IntInit*>(List->getElement(i))) {
       Ints.push_back(II->getValue());