Add carat diagnostics to tblgen lexer errors.
[oota-llvm.git] / utils / TableGen / FileParser.y.cvs
index 8ae2ef9ff1b2fbf9fef144e0fcd1385498554e8f..0612f56ca0135cc3211ed586113102230b925e9e 100644 (file)
@@ -14,6 +14,7 @@
 %{
 #include "Record.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Streams.h"
 #include <algorithm>
 #include <cstdio>
 #define YYERROR_VERBOSE 1
@@ -90,7 +91,8 @@ static void setValue(const std::string &ValName,
                      std::vector<unsigned> *BitList, Init *V) {
   if (!V) return;
 
-  RecordVal *RV = CurRec->getValue(ValName);
+  Record *TheRec = getActiveRec();
+  RecordVal *RV = TheRec->getValue(ValName);
   if (RV == 0) {
     err() << "Value '" << ValName << "' unknown!\n";
     exit(1);
@@ -123,7 +125,7 @@ static void setValue(const std::string &ValName,
     }
 
     // We should have a BitsInit type now...
-    assert(dynamic_cast<BitsInit*>(BI) != 0 || &(std::cerr << *BI) == 0);
+    assert(dynamic_cast<BitsInit*>(BI) != 0 || (cerr << *BI).stream() == 0);
     BitsInit *BInit = (BitsInit*)BI;
 
     BitsInit *NewVal = new BitsInit(CurVal->getNumBits());
@@ -220,7 +222,7 @@ using namespace llvm;
 };
 
 %token INT BIT STRING BITS LIST CODE DAG CLASS DEF MULTICLASS DEFM FIELD LET IN
-%token SHLTOK SRATOK SRLTOK STRCONCATTOK
+%token CONCATTOK SHLTOK SRATOK SRLTOK STRCONCATTOK
 %token <IntVal>      INTVAL
 %token <StrVal>      ID VARNAME STRVAL CODEFRAGMENT
 
@@ -389,6 +391,8 @@ Value : IDValue {
       exit(1);
     }
     delete $3;
+  } | CONCATTOK '(' Value ',' Value ')' {
+    $$ = (new BinOpInit(BinOpInit::CONCAT, $3, $5))->Fold();
   } | SHLTOK '(' Value ',' Value ')' {
     $$ = (new BinOpInit(BinOpInit::SHL, $3, $5))->Fold();
   } | SRATOK '(' Value ',' Value ')' {
@@ -623,9 +627,9 @@ ObjectBody : ClassList {
              // Delete the template arg values for the class
              delete (*$1)[i].second;
            }
-           delete $1;   // Delete the class list...
+           delete $1;   // Delete the class list.
   
-           // Process any variables on the set stack...
+           // Process any variables on the let stack.
            for (unsigned i = 0, e = LetStack.size(); i != e; ++i)
              for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
                setValue(LetStack[i][j].Name,
@@ -645,7 +649,8 @@ ClassInst : CLASS ClassName {
      };
 
 DefInst : DEF DefName ObjectBody {
-  $3->resolveReferences();
+  if (CurMultiClass == 0)  // Def's in multiclasses aren't really defs.
+    $3->resolveReferences();
 
   // If ObjectBody has template arguments, it's an error.
   assert($3->getTemplateArgs().empty() && "How'd this get template args?");
@@ -741,6 +746,14 @@ DefMInst : DEFM ID { CurDefmPrefix = $2; } ':' SubClassRef ';' {
       }
     }
     
+    // If the mdef is inside a 'let' expression, add to each def.
+    for (unsigned i = 0, e = LetStack.size(); i != e; ++i)
+      for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
+        setValue(LetStack[i][j].Name,
+                 LetStack[i][j].HasBits ? &LetStack[i][j].Bits : 0,
+                 LetStack[i][j].Value);
+    
+    
     // Ensure redefinition doesn't happen.
     if (Records.getDef(CurRec->getName())) {
       err() << "def '" << CurRec->getName() << "' already defined, "
@@ -749,11 +762,15 @@ DefMInst : DEFM ID { CurDefmPrefix = $2; } ':' SubClassRef ';' {
       exit(1);
     }
     Records.addDef(CurRec);
+    
+    CurRec->resolveReferences();
+
     CurRec = 0;
   }
   
   delete &TemplateVals;
   delete $2;
+  CurDefmPrefix = 0;
 };
 
 Object : ClassInst {} | DefInst {};