The CodeEmitterGenerator used to consider ANY uninitialized field as being an
[oota-llvm.git] / utils / TableGen / FileParser.y
index 0c5b240d3079293c0ebff80b5c8de4fefebf15d3..0ab3e5bde0cbd19bf3c3983bd5efb76b6eaecfd0 100644 (file)
@@ -18,18 +18,18 @@ static Record *CurRec = 0;
 
 typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
 
-struct SetRecord {
+struct LetRecord {
   std::string Name;
   std::vector<unsigned> Bits;
   Init *Value;
   bool HasBits;
-  SetRecord(const std::string &N, std::vector<unsigned> *B, Init *V)
+  LetRecord(const std::string &N, std::vector<unsigned> *B, Init *V)
     : Name(N), Value(V), HasBits(B != 0) {
     if (HasBits) Bits = *B;
   }
 };
 
-static std::vector<std::vector<SetRecord> > SetStack;
+static std::vector<std::vector<LetRecord> > LetStack;
 
 
 extern std::ostream &err();
@@ -161,6 +161,7 @@ static void addSubClass(Record *SC, const std::vector<Init*> &TemplateArgs) {
   int                   IntVal;
   RecTy                *Ty;
   Init                 *Initializer;
+  std::vector<Init*>   *DagValueList;
   std::vector<Init*>   *FieldList;
   std::vector<unsigned>*BitList;
   Record               *Rec;
@@ -168,7 +169,7 @@ static void addSubClass(Record *SC, const std::vector<Init*> &TemplateArgs) {
   std::vector<SubClassRefTy> *SubClassList;
 };
 
-%token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD SET IN
+%token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD LET IN
 %token <IntVal>      INTVAL
 %token <StrVal>      ID STRVAL CODEFRAGMENT
 
@@ -179,6 +180,7 @@ static void addSubClass(Record *SC, const std::vector<Init*> &TemplateArgs) {
 %type <SubClassList> ClassList ClassListNE
 %type <IntVal>       OptPrefix
 %type <Initializer>  Value OptValue
+%type <DagValueList> DagArgList DagArgListNE
 %type <FieldList>    ValueList ValueListNE
 %type <BitList>      BitList OptBitList RBitList
 %type <StrVal>       Declaration OptID
@@ -270,8 +272,30 @@ Value : INTVAL {
     }
     $$ = new FieldInit($1, *$3);
     delete $3;
+  } | '(' ID DagArgList ')' {
+    Record *D = Records.getDef(*$2);
+    if (D == 0) {
+      err() << "Invalid def '" << *$2 << "'!\n";
+      abort();
+    }
+    $$ = new DagInit(D, *$3);
+    delete $2; delete $3;
   };
 
+DagArgListNE : Value {
+    $$ = new std::vector<Init*>();
+    $$->push_back($1);
+  }
+  | DagArgListNE ',' Value {
+    $1->push_back($3);
+  };
+
+DagArgList : /*empty*/ {
+    $$ = new std::vector<Init*>();
+  }
+  | DagArgListNE { $$ = $1; };
+
+
 RBitList : INTVAL {
     $$ = new std::vector<unsigned>();
     $$->push_back($1);
@@ -340,7 +364,7 @@ Declaration : OptPrefix Type ID OptValue {
 
 BodyItem : Declaration ';' {
   delete $1;
-} | SET ID OptBitList '=' Value ';' {
+} | LET ID OptBitList '=' Value ';' {
   setValue(*$2, $3, $5);
   delete $2;
   delete $3;
@@ -399,11 +423,11 @@ ObjectBody : OptID {
            }
 
           // Process any variables on the set stack...
-          for (unsigned i = 0, e = SetStack.size(); i != e; ++i)
-             for (unsigned j = 0, e = SetStack[i].size(); j != e; ++j)
-               setValue(SetStack[i][j].Name,
-                        SetStack[i][j].HasBits ? &SetStack[i][j].Bits : 0,
-                        SetStack[i][j].Value);
+          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);
          } Body {
   CurRec->resolveReferences();
 
@@ -446,22 +470,22 @@ DefInst : DEF ObjectBody {
 
 Object : ClassInst | DefInst;
 
-SETItem : ID OptBitList '=' Value {
-  SetStack.back().push_back(SetRecord(*$1, $2, $4));
+LETItem : ID OptBitList '=' Value {
+  LetStack.back().push_back(LetRecord(*$1, $2, $4));
   delete $1; delete $2;
 };
 
-SETList : SETItem | SETList ',' SETItem;
+LETList : LETItem | LETList ',' LETItem;
 
-// SETCommand - A 'SET' statement start...
-SETCommand : SET { SetStack.push_back(std::vector<SetRecord>()); } SETList IN;
+// LETCommand - A 'LET' statement start...
+LETCommand : LET { LetStack.push_back(std::vector<LetRecord>()); } LETList IN;
 
 // Support Set commands wrapping objects... both with and without braces.
-Object : SETCommand '{' ObjectList '}' {
-    SetStack.pop_back();
+Object : LETCommand '{' ObjectList '}' {
+    LetStack.pop_back();
   }
-  | SETCommand Object {
-    SetStack.pop_back();
+  | LETCommand Object {
+    LetStack.pop_back();
   };
 
 ObjectList : Object {} | ObjectList Object {};