Add support to tablegen for naming the nodes themselves, not just the operands,
[oota-llvm.git] / utils / TableGen / Record.h
index 9f300041671738624b3c7f9b16fb49bbc852014a..32172ef12ae6cf5b8afb76a8bb49489cfa901493 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     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 is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #ifndef RECORD_H
 #define RECORD_H
 
-#include <string>
-#include <vector>
+#include "TGSourceMgr.h"
+#include "llvm/Support/DataTypes.h"
 #include <map>
-#include <iostream>
-#include <cassert>
+#include <ostream>
 
 namespace llvm {
-
+  
 // RecTy subclasses.
 class BitRecTy;
 class BitsRecTy;
@@ -42,6 +41,7 @@ class IntInit;
 class StringInit;
 class CodeInit;
 class ListInit;
+class BinOpInit;
 class DefInit;
 class DagInit;
 class TypedInit;
@@ -61,7 +61,8 @@ class RecordVal;
 struct RecTy {
   virtual ~RecTy() {}
 
-  virtual void print(std::ostream &OS) const = 0;
+  virtual std::string getAsString() const = 0;
+  void print(std::ostream &OS) const { OS << getAsString(); }
   void dump() const;
 
   /// typeIsConvertibleTo - Return true if all values of 'this' type can be
@@ -75,6 +76,7 @@ public:   // These methods should only be called from subclasses of Init
   virtual Init *convertValue(   IntInit *II) { return 0; }
   virtual Init *convertValue(StringInit *SI) { return 0; }
   virtual Init *convertValue(  ListInit *LI) { return 0; }
+  virtual Init *convertValue( BinOpInit *UI) { return 0; }
   virtual Init *convertValue(  CodeInit *CI) { return 0; }
   virtual Init *convertValue(VarBitInit *VB) { return 0; }
   virtual Init *convertValue(   DefInit *DI) { return 0; }
@@ -120,11 +122,12 @@ public:
   virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; }
   virtual Init *convertValue(   DefInit *DI) { return 0; }
   virtual Init *convertValue(   DagInit *DI) { return 0; }
+  virtual Init *convertValue( BinOpInit *UI) { return 0; }
   virtual Init *convertValue( TypedInit *TI);
   virtual Init *convertValue(   VarInit *VI) { return RecTy::convertValue(VI);}
   virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
 
-  void print(std::ostream &OS) const { OS << "bit"; }
+  std::string getAsString() const { return "bit"; }
 
   bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
@@ -147,7 +150,7 @@ public:
 class BitsRecTy : public RecTy {
   unsigned Size;
 public:
-  BitsRecTy(unsigned Sz) : Size(Sz) {}
+  explicit BitsRecTy(unsigned Sz) : Size(Sz) {}
 
   unsigned getNumBits() const { return Size; }
 
@@ -161,12 +164,12 @@ public:
   virtual Init *convertValue(VarBitInit *VB) { return 0; }
   virtual Init *convertValue(   DefInit *DI) { return 0; }
   virtual Init *convertValue(   DagInit *DI) { return 0; }
+  virtual Init *convertValue( BinOpInit *UI) { return 0; }
   virtual Init *convertValue( TypedInit *TI);
   virtual Init *convertValue(   VarInit *VI) { return RecTy::convertValue(VI);}
   virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
 
-
-  void print(std::ostream &OS) const { OS << "bits<" << Size << ">"; }
+  std::string getAsString() const;
 
   bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
@@ -199,12 +202,12 @@ public:
   virtual Init *convertValue(VarBitInit *VB) { return 0; }
   virtual Init *convertValue(   DefInit *DI) { return 0; }
   virtual Init *convertValue(   DagInit *DI) { return 0; }
+  virtual Init *convertValue( BinOpInit *UI) { return 0; }
   virtual Init *convertValue( TypedInit *TI);
   virtual Init *convertValue(   VarInit *VI) { return RecTy::convertValue(VI);}
   virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
 
-
-  void print(std::ostream &OS) const { OS << "int"; }
+  std::string getAsString() const { return "int"; }
 
   bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
@@ -231,6 +234,7 @@ public:
   virtual Init *convertValue(   IntInit *II) { return 0; }
   virtual Init *convertValue(StringInit *SI) { return (Init*)SI; }
   virtual Init *convertValue(  ListInit *LI) { return 0; }
+  virtual Init *convertValue( BinOpInit *BO);
   virtual Init *convertValue(  CodeInit *CI) { return 0; }
   virtual Init *convertValue(VarBitInit *VB) { return 0; }
   virtual Init *convertValue(   DefInit *DI) { return 0; }
@@ -239,7 +243,7 @@ public:
   virtual Init *convertValue(   VarInit *VI) { return RecTy::convertValue(VI);}
   virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
 
-  void print(std::ostream &OS) const { OS << "string"; }
+  std::string getAsString() const { return "string"; }
 
   bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
@@ -263,7 +267,7 @@ public:
 class ListRecTy : public RecTy {
   RecTy *Ty;
 public:
-  ListRecTy(RecTy *T) : Ty(T) {}
+  explicit ListRecTy(RecTy *T) : Ty(T) {}
 
   RecTy *getElementType() const { return Ty; }
 
@@ -277,11 +281,12 @@ public:
   virtual Init *convertValue(VarBitInit *VB) { return 0; }
   virtual Init *convertValue(   DefInit *DI) { return 0; }
   virtual Init *convertValue(   DagInit *DI) { return 0; }
+  virtual Init *convertValue( BinOpInit *UI) { return 0; }
   virtual Init *convertValue( TypedInit *TI);
   virtual Init *convertValue(   VarInit *VI) { return RecTy::convertValue(VI);}
   virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
 
-  void print(std::ostream &OS) const;
+  std::string getAsString() const;
 
   bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
@@ -313,12 +318,12 @@ public:
   virtual Init *convertValue(VarBitInit *VB) { return 0; }
   virtual Init *convertValue(   DefInit *DI) { return 0; }
   virtual Init *convertValue(   DagInit *DI) { return 0; }
+  virtual Init *convertValue( BinOpInit *UI) { return 0; }
   virtual Init *convertValue( TypedInit *TI);
   virtual Init *convertValue(   VarInit *VI) { return RecTy::convertValue(VI);}
   virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
 
-
-  void print(std::ostream &OS) const { OS << "code"; }
+  std::string getAsString() const { return "code"; }
 
   bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
@@ -346,12 +351,13 @@ public:
   virtual Init *convertValue(  CodeInit *CI) { return 0; }
   virtual Init *convertValue(VarBitInit *VB) { return 0; }
   virtual Init *convertValue(   DefInit *DI) { return 0; }
+  virtual Init *convertValue( BinOpInit *BO);
   virtual Init *convertValue(   DagInit *CI) { return (Init*)CI; }
   virtual Init *convertValue( TypedInit *TI);
   virtual Init *convertValue(   VarInit *VI) { return RecTy::convertValue(VI);}
   virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
 
-  void print(std::ostream &OS) const { OS << "dag"; }
+  std::string getAsString() const { return "dag"; }
 
   bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
@@ -374,7 +380,7 @@ public:
 class RecordRecTy : public RecTy {
   Record *Rec;
 public:
-  RecordRecTy(Record *R) : Rec(R) {}
+  explicit RecordRecTy(Record *R) : Rec(R) {}
 
   Record *getRecord() const { return Rec; }
 
@@ -386,13 +392,14 @@ public:
   virtual Init *convertValue(  ListInit *LI) { return 0; }
   virtual Init *convertValue(  CodeInit *CI) { return 0; }
   virtual Init *convertValue(VarBitInit *VB) { return 0; }
+  virtual Init *convertValue( BinOpInit *UI) { return 0; }
   virtual Init *convertValue(   DefInit *DI);
   virtual Init *convertValue(   DagInit *DI) { return 0; }
   virtual Init *convertValue( TypedInit *VI);
   virtual Init *convertValue(   VarInit *VI) { return RecTy::convertValue(VI);}
   virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
 
-  void print(std::ostream &OS) const;
+  std::string getAsString() const;
 
   bool typeIsConvertibleTo(const RecTy *RHS) const {
     return RHS->baseClassOf(this);
@@ -421,7 +428,10 @@ struct Init {
   virtual bool isComplete() const { return true; }
 
   /// print - Print out this value.
-  virtual void print(std::ostream &OS) const = 0;
+  void print(std::ostream &OS) const { OS << getAsString(); }
+
+  /// getAsString - Convert this value to a string form.
+  virtual std::string getAsString() const = 0;
 
   /// dump - Debugging method that may be called through a debugger, just
   /// invokes print on cerr.
@@ -465,11 +475,6 @@ struct Init {
     return 0;
   }
 
-  enum BinaryOp { SHL, SRA, SRL };
-  virtual Init *getBinaryOp(BinaryOp Op, Init *RHS) {
-    return 0;
-  }
-
   /// resolveReferences - This method is used by classes that refer to other
   /// variables which may not be defined at the time they expression is formed.
   /// If a value is set for the variable later, this method will be called on
@@ -494,7 +499,7 @@ public:
   }
 
   virtual bool isComplete() const { return false; }
-  virtual void print(std::ostream &OS) const { OS << "?"; }
+  virtual std::string getAsString() const { return "?"; }
 };
 
 
@@ -503,7 +508,7 @@ public:
 class BitInit : public Init {
   bool Value;
 public:
-  BitInit(bool V) : Value(V) {}
+  explicit BitInit(bool V) : Value(V) {}
 
   bool getValue() const { return Value; }
 
@@ -511,7 +516,7 @@ public:
     return Ty->convertValue(this);
   }
 
-  virtual void print(std::ostream &OS) const { OS << (Value ? "1" : "0"); }
+  virtual std::string getAsString() const { return Value ? "1" : "0"; }
 };
 
 /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
@@ -520,7 +525,7 @@ public:
 class BitsInit : public Init {
   std::vector<Init*> Bits;
 public:
-  BitsInit(unsigned Size) : Bits(Size) {}
+  explicit BitsInit(unsigned Size) : Bits(Size) {}
 
   unsigned getNumBits() const { return Bits.size(); }
 
@@ -544,7 +549,7 @@ public:
       if (!getBit(i)->isComplete()) return false;
     return true;
   }
-  virtual void print(std::ostream &OS) const;
+  virtual std::string getAsString() const;
 
   virtual Init *resolveReferences(Record &R, const RecordVal *RV);
 
@@ -559,20 +564,18 @@ public:
 /// IntInit - 7 - Represent an initalization by a literal integer value.
 ///
 class IntInit : public Init {
-  int Value;
+  int64_t Value;
 public:
-  IntInit(int V) : Value(V) {}
+  explicit IntInit(int64_t V) : Value(V) {}
 
-  int getValue() const { return Value; }
+  int64_t getValue() const { return Value; }
 
   virtual Init *convertInitializerTo(RecTy *Ty) {
     return Ty->convertValue(this);
   }
   virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
 
-  virtual Init *getBinaryOp(BinaryOp Op, Init *RHS);
-
-  virtual void print(std::ostream &OS) const { OS << Value; }
+  virtual std::string getAsString() const;
 };
 
 
@@ -581,7 +584,7 @@ public:
 class StringInit : public Init {
   std::string Value;
 public:
-  StringInit(const std::string &V) : Value(V) {}
+  explicit StringInit(const std::string &V) : Value(V) {}
 
   const std::string &getValue() const { return Value; }
 
@@ -589,7 +592,7 @@ public:
     return Ty->convertValue(this);
   }
 
-  virtual void print(std::ostream &OS) const { OS << "\"" << Value << "\""; }
+  virtual std::string getAsString() const { return "\"" + Value + "\""; }
 };
 
 /// CodeInit - "[{...}]" - Represent a code fragment.
@@ -597,7 +600,7 @@ public:
 class CodeInit : public Init {
   std::string Value;
 public:
-  CodeInit(const std::string &V) : Value(V) {}
+  explicit CodeInit(const std::string &V) : Value(V) {}
 
   const std::string getValue() const { return Value; }
 
@@ -605,7 +608,7 @@ public:
     return Ty->convertValue(this);
   }
 
-  virtual void print(std::ostream &OS) const { OS << "[{" << Value << "}]"; }
+  virtual std::string getAsString() const { return "[{" + Value + "}]"; }
 };
 
 /// ListInit - [AL, AH, CL] - Represent a list of defs
@@ -613,7 +616,7 @@ public:
 class ListInit : public Init {
   std::vector<Init*> Values;
 public:
-  ListInit(std::vector<Init*> &Vs) {
+  explicit ListInit(std::vector<Init*> &Vs) {
     Values.swap(Vs);
   }
 
@@ -623,6 +626,8 @@ public:
     return Values[i];
   }
 
+  Record *getElementAsRecord(unsigned i) const;
+  
   Init *convertInitListSlice(const std::vector<unsigned> &Elements);
 
   virtual Init *convertInitializerTo(RecTy *Ty) {
@@ -636,17 +641,58 @@ public:
   ///
   virtual Init *resolveReferences(Record &R, const RecordVal *RV);
 
-  virtual void print(std::ostream &OS) const;
+  virtual std::string getAsString() const;
+
+  typedef std::vector<Init*>::iterator       iterator;
+  typedef std::vector<Init*>::const_iterator const_iterator;
+
+  inline iterator       begin()       { return Values.begin(); }
+  inline const_iterator begin() const { return Values.begin(); }
+  inline iterator       end  ()       { return Values.end();   }
+  inline const_iterator end  () const { return Values.end();   }
+
+  inline size_t         size () const { return Values.size();  }
+  inline bool           empty() const { return Values.empty(); }
+};
+
+/// BinOpInit - !op (X, Y) - Combine two inits.
+///
+class BinOpInit : public Init {
+public:
+  enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT };
+private:
+  BinaryOp Opc;
+  Init *LHS, *RHS;
+public:
+  BinOpInit(BinaryOp opc, Init *lhs, Init *rhs) : Opc(opc), LHS(lhs), RHS(rhs) {
+  }
+  
+  BinaryOp getOpcode() const { return Opc; }
+  Init *getLHS() const { return LHS; }
+  Init *getRHS() const { return RHS; }
+
+  // Fold - If possible, fold this to a simpler init.  Return this if not
+  // possible to fold.
+  Init *Fold();
+
+  virtual Init *convertInitializerTo(RecTy *Ty) {
+    return Ty->convertValue(this);
+  }
+  
+  virtual Init *resolveReferences(Record &R, const RecordVal *RV);
+  
+  virtual std::string getAsString() const;
 };
 
 
+
 /// TypedInit - This is the common super-class of types that have a specific,
 /// explicit, type.
 ///
 class TypedInit : public Init {
   RecTy *Ty;
 public:
-  TypedInit(RecTy *T) : Ty(T) {}
+  explicit TypedInit(RecTy *T) : Ty(T) {}
 
   RecTy *getType() const { return Ty; }
 
@@ -672,7 +718,8 @@ public:
 class VarInit : public TypedInit {
   std::string VarName;
 public:
-  VarInit(const std::string &VN, RecTy *T) : TypedInit(T), VarName(VN) {}
+  explicit VarInit(const std::string &VN, RecTy *T)
+    : TypedInit(T), VarName(VN) {}
 
   virtual Init *convertInitializerTo(RecTy *Ty) {
     return Ty->convertValue(this);
@@ -695,7 +742,7 @@ public:
   ///
   virtual Init *resolveReferences(Record &R, const RecordVal *RV);
 
-  virtual void print(std::ostream &OS) const { OS << VarName; }
+  virtual std::string getAsString() const { return VarName; }
 };
 
 
@@ -718,9 +765,7 @@ public:
   TypedInit *getVariable() const { return TI; }
   unsigned getBitNum() const { return Bit; }
 
-  virtual void print(std::ostream &OS) const {
-    TI->print(OS); OS << "{" << Bit << "}";
-  }
+  virtual std::string getAsString() const;
   virtual Init *resolveReferences(Record &R, const RecordVal *RV);
 };
 
@@ -753,9 +798,7 @@ public:
   virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
                                             unsigned Elt);
 
-  virtual void print(std::ostream &OS) const {
-    TI->print(OS); OS << "[" << Element << "]";
-  }
+  virtual std::string getAsString() const;
   virtual Init *resolveReferences(Record &R, const RecordVal *RV);
 };
 
@@ -764,7 +807,7 @@ public:
 class DefInit : public Init {
   Record *Def;
 public:
-  DefInit(Record *D) : Def(D) {}
+  explicit DefInit(Record *D) : Def(D) {}
 
   virtual Init *convertInitializerTo(RecTy *Ty) {
     return Ty->convertValue(this);
@@ -777,7 +820,7 @@ public:
   virtual RecTy *getFieldType(const std::string &FieldName) const;
   virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
 
-  virtual void print(std::ostream &OS) const;
+  virtual std::string getAsString() const;
 };
 
 
@@ -803,22 +846,24 @@ public:
 
   virtual Init *resolveReferences(Record &R, const RecordVal *RV);
 
-  virtual void print(std::ostream &OS) const {
-    Rec->print(OS); OS << "." << FieldName;
+  virtual std::string getAsString() const {
+    return Rec->getAsString() + "." + FieldName;
   }
 };
 
-/// DagInit - (def a, b) - Represent a DAG tree value.  DAG inits are required
-/// to have Records for their first value, after that, any legal Init is
-/// possible.
+/// DagInit - (v a, b) - Represent a DAG tree value.  DAG inits are required
+/// to have at least one value then a (possibly empty) list of arguments.  Each
+/// argument can have a name associated with it.
 ///
 class DagInit : public Init {
-  Record *NodeTypeDef;
+  Init *Val;
+  std::string ValName;
   std::vector<Init*> Args;
   std::vector<std::string> ArgNames;
 public:
-  DagInit(Record *D, const std::vector<std::pair<Init*, std::string> > &args)
-    : NodeTypeDef(D) {
+  DagInit(Init *V, std::string VN, 
+          const std::vector<std::pair<Init*, std::string> > &args)
+    : Val(V), ValName(VN) {
     Args.reserve(args.size());
     ArgNames.reserve(args.size());
     for (unsigned i = 0, e = args.size(); i != e; ++i) {
@@ -826,12 +871,18 @@ public:
       ArgNames.push_back(args[i].second);
     }
   }
-
+  DagInit(Init *V, std::string VN, const std::vector<Init*> &args, 
+          const std::vector<std::string> &argNames)
+  : Val(V), ValName(VN), Args(args), ArgNames(argNames) {
+  }
+  
   virtual Init *convertInitializerTo(RecTy *Ty) {
     return Ty->convertValue(this);
   }
 
-  Record *getNodeType() const { return NodeTypeDef; }
+  Init *getOperator() const { return Val; }
+
+  const std::string &getName() const { return ValName; }
 
   unsigned getNumArgs() const { return Args.size(); }
   Init *getArg(unsigned Num) const {
@@ -847,8 +898,32 @@ public:
     assert(Num < Args.size() && "Arg number out of range!");
     Args[Num] = I;
   }
+  
+  virtual Init *resolveReferences(Record &R, const RecordVal *RV);
+
+  virtual std::string getAsString() const;
+
+  typedef std::vector<Init*>::iterator             arg_iterator;
+  typedef std::vector<Init*>::const_iterator       const_arg_iterator;
+  typedef std::vector<std::string>::iterator       name_iterator;
+  typedef std::vector<std::string>::const_iterator const_name_iterator;
+
+  inline arg_iterator        arg_begin()       { return Args.begin(); }
+  inline const_arg_iterator  arg_begin() const { return Args.begin(); }
+  inline arg_iterator        arg_end  ()       { return Args.end();   }
+  inline const_arg_iterator  arg_end  () const { return Args.end();   }
+
+  inline size_t              arg_size () const { return Args.size();  }
+  inline bool                arg_empty() const { return Args.empty(); }
+
+  inline name_iterator       name_begin()       { return ArgNames.begin(); }
+  inline const_name_iterator name_begin() const { return ArgNames.begin(); }
+  inline name_iterator       name_end  ()       { return ArgNames.end();   }
+  inline const_name_iterator name_end  () const { return ArgNames.end();   }
+
+  inline size_t              name_size () const { return ArgNames.size();  }
+  inline bool                name_empty() const { return ArgNames.empty(); }
 
-  virtual void print(std::ostream &OS) const;
 };
 
 //===----------------------------------------------------------------------===//
@@ -889,16 +964,20 @@ inline std::ostream &operator<<(std::ostream &OS, const RecordVal &RV) {
 
 class Record {
   std::string Name;
+  TGLoc Loc;
   std::vector<std::string> TemplateArgs;
   std::vector<RecordVal> Values;
   std::vector<Record*> SuperClasses;
 public:
 
-  Record(const std::string &N) : Name(N) {}
+  explicit Record(const std::string &N, TGLoc loc) : Name(N), Loc(loc) {}
   ~Record() {}
-
+  
   const std::string &getName() const { return Name; }
   void setName(const std::string &Name);  // Also updates RecordKeeper.
+  
+  TGLoc getLoc() const { return Loc; }
+  
   const std::vector<std::string> &getTemplateArgs() const {
     return TemplateArgs;
   }
@@ -942,7 +1021,7 @@ public:
     assert(0 && "Name does not exist in record!");
   }
 
-  bool isSubClassOf(Record *R) const {
+  bool isSubClassOf(const Record *R) const {
     for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
       if (SuperClasses[i] == R)
         return true;
@@ -1001,11 +1080,17 @@ public:
   ListInit *getValueAsListInit(const std::string &FieldName) const;
 
   /// getValueAsListOfDefs - This method looks up the specified field and
-  /// returnsits value as a vector of records, throwing an exception if the
+  /// returns its value as a vector of records, throwing an exception if the
   /// field does not exist or if the value is not the right type.
   ///
   std::vector<Record*> getValueAsListOfDefs(const std::string &FieldName) const;
 
+  /// getValueAsListOfInts - This method looks up the specified field and returns
+  /// 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<int64_t> getValueAsListOfInts(const std::string &FieldName) const;
+  
   /// getValueAsDef - This method looks up the specified field and returns its
   /// value as a Record, throwing an exception if the field does not exist or if
   /// the value is not the right type.
@@ -1019,10 +1104,10 @@ public:
   bool getValueAsBit(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
-  /// the value is not the right type.
+  /// value as an int64_t, throwing an exception if the field does not exist or
+  /// if the value is not the right type.
   ///
-  int getValueAsInt(const std::string &FieldName) const;
+  int64_t getValueAsInt(const std::string &FieldName) const;
 
   /// getValueAsDag - This method looks up the specified field and returns its
   /// value as an Dag, throwing an exception if the field does not exist or if
@@ -1097,10 +1182,42 @@ public:
   void dump() const;
 };
 
+/// LessRecord - Sorting predicate to sort record pointers by name.
+///
+struct LessRecord {
+  bool operator()(const Record *Rec1, const Record *Rec2) const {
+    return Rec1->getName() < Rec2->getName();
+  }
+};
+
+/// LessRecordFieldName - Sorting predicate to sort record pointers by their 
+/// name field.
+///
+struct LessRecordFieldName {
+  bool operator()(const Record *Rec1, const Record *Rec2) const {
+    return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
+  }
+};
+
+
+class TGError {
+  TGLoc Loc;
+  std::string Message;
+public:
+  TGError(TGLoc loc, const std::string &message) : Loc(loc), Message(message) {}
+  
+  TGLoc getLoc() const { return Loc; }
+  const std::string &getMessage() const { return Message; }
+};
+  
+  
 std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK);
 
 extern RecordKeeper Records;
 
+void PrintError(TGLoc ErrorLoc, const std::string &Msg);
+
+  
 } // End llvm namespace
 
 #endif