Added LLVM copyright notice.
[oota-llvm.git] / utils / TableGen / FileParser.y
index 4025d4e2315dea5f6686c0b0fff22cc121dbec2e..491cca310d066dbff5647996c70084f006c6fb10 100644 (file)
@@ -1,8 +1,15 @@
 //===-- FileParser.y - Parser for TableGen files ----------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 //  This file implements the bison parser for Table Generator files...
 //
-//===------------------------------------------------------------------------=//
+//===----------------------------------------------------------------------===//
 
 %{
 #include "Record.h"
@@ -18,18 +25,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();
@@ -130,7 +137,7 @@ static void addSubClass(Record *SC, const std::vector<Init*> &TemplateArgs) {
     abort();
   } else {    // This class expects template arguments...
     // Loop over all of the template arguments, setting them to the specified
-    // value or leaving them as the default as neccesary.
+    // value or leaving them as the default as necessary.
     for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
       if (i < TemplateArgs.size()) {  // A value is specified for this temp-arg?
        // Set it now.
@@ -166,11 +173,12 @@ static void addSubClass(Record *SC, const std::vector<Init*> &TemplateArgs) {
   Record               *Rec;
   SubClassRefTy        *SubClassRef;
   std::vector<SubClassRefTy> *SubClassList;
+  std::vector<std::pair<Init*, std::string> > *DagValueList;
 };
 
-%token INT BIT STRING BITS LIST CODE 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
+%token <StrVal>      ID VARNAME STRVAL CODEFRAGMENT
 
 %type <Ty>           Type
 %type <Rec>          ClassInst DefInst Object ObjectBody ClassID
@@ -179,9 +187,10 @@ 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
+%type <StrVal>       Declaration OptID OptVarName
 
 %start File
 %%
@@ -209,6 +218,8 @@ Type : STRING {                       // string type
     $$ = new ListRecTy($3);
   } | CODE {                          // code type
     $$ = new CodeRecTy();
+  } | DAG {                           // dag type
+    $$ = new DagRecTy();
   } | ClassID {                       // Record Type
     $$ = new RecordRecTy($1);
   };
@@ -268,8 +279,40 @@ 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;
+  };
+
+OptVarName : /* empty */ {
+    $$ = new std::string();
+  }
+  | ':' VARNAME {
+    $$ = $2;
   };
 
+DagArgListNE : Value OptVarName {
+    $$ = new std::vector<std::pair<Init*, std::string> >();
+    $$->push_back(std::make_pair($1, *$2));
+    delete $2;
+  }
+  | DagArgListNE ',' Value OptVarName {
+    $1->push_back(std::make_pair($3, *$4));
+    delete $4;
+    $$ = $1;
+  };
+
+DagArgList : /*empty*/ {
+    $$ = new std::vector<std::pair<Init*, std::string> >();
+  }
+  | DagArgListNE { $$ = $1; };
+
+
 RBitList : INTVAL {
     $$ = new std::vector<unsigned>();
     $$->push_back($1);
@@ -338,7 +381,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;
@@ -397,11 +440,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();
 
@@ -444,22 +487,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 {};