LCOV - code coverage report
Current view: top level - lib/TableGen - TGParser.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 9 9 100.0 %
Date: 2018-06-17 00:07:59 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- TGParser.h - Parser for TableGen Files -------------------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This class represents the Parser for tablegen files.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #ifndef LLVM_LIB_TABLEGEN_TGPARSER_H
      15             : #define LLVM_LIB_TABLEGEN_TGPARSER_H
      16             : 
      17             : #include "TGLexer.h"
      18             : #include "llvm/ADT/Twine.h"
      19             : #include "llvm/Support/SourceMgr.h"
      20             : #include "llvm/TableGen/Error.h"
      21             : #include "llvm/TableGen/Record.h"
      22             : #include <map>
      23             : 
      24             : namespace llvm {
      25             :   class Record;
      26             :   class RecordVal;
      27             :   class RecordKeeper;
      28             :   class RecTy;
      29             :   class Init;
      30             :   struct MultiClass;
      31             :   struct SubClassReference;
      32             :   struct SubMultiClassReference;
      33             : 
      34      847472 :   struct LetRecord {
      35             :     StringInit *Name;
      36             :     std::vector<unsigned> Bits;
      37             :     Init *Value;
      38             :     SMLoc Loc;
      39             :     LetRecord(StringInit *N, ArrayRef<unsigned> B, Init *V, SMLoc L)
      40      248340 :       : Name(N), Bits(B), Value(V), Loc(L) {
      41             :     }
      42             :   };
      43             : 
      44             :   /// ForeachLoop - Record the iteration state associated with a for loop.
      45             :   /// This is used to instantiate items in the loop body.
      46             :   struct ForeachLoop {
      47             :     VarInit *IterVar;
      48             :     ListInit *ListValue;
      49             : 
      50             :     ForeachLoop(VarInit *IVar, ListInit *LValue)
      51        3077 :       : IterVar(IVar), ListValue(LValue) {}
      52             :   };
      53             : 
      54             :   struct DefsetRecord {
      55             :     SMLoc Loc;
      56             :     RecTy *EltTy;
      57             :     SmallVector<Init *, 16> Elements;
      58             :   };
      59             : 
      60         662 : class TGParser {
      61             :   TGLexer Lex;
      62             :   std::vector<SmallVector<LetRecord, 4>> LetStack;
      63             :   std::map<std::string, std::unique_ptr<MultiClass>> MultiClasses;
      64             : 
      65             :   /// Loops - Keep track of any foreach loops we are within.
      66             :   ///
      67             :   typedef std::vector<ForeachLoop> LoopVector;
      68             :   LoopVector Loops;
      69             : 
      70             :   SmallVector<DefsetRecord *, 2> Defsets;
      71             : 
      72             :   /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the
      73             :   /// current value.
      74             :   MultiClass *CurMultiClass;
      75             : 
      76             :   // Record tracker
      77             :   RecordKeeper &Records;
      78             : 
      79             :   // A "named boolean" indicating how to parse identifiers.  Usually
      80             :   // identifiers map to some existing object but in special cases
      81             :   // (e.g. parsing def names) no such object exists yet because we are
      82             :   // in the middle of creating in.  For those situations, allow the
      83             :   // parser to ignore missing object errors.
      84             :   enum IDParseMode {
      85             :     ParseValueMode,   // We are parsing a value we expect to look up.
      86             :     ParseNameMode,    // We are parsing a name of an object that does not yet
      87             :                       // exist.
      88             :   };
      89             : 
      90             : public:
      91             :   TGParser(SourceMgr &SrcMgr, RecordKeeper &records)
      92         672 :       : Lex(SrcMgr), CurMultiClass(nullptr), Records(records) {}
      93             : 
      94             :   /// ParseFile - Main entrypoint for parsing a tblgen file.  These parser
      95             :   /// routines return true on error, or false on success.
      96             :   bool ParseFile();
      97             : 
      98             :   bool Error(SMLoc L, const Twine &Msg) const {
      99          11 :     PrintError(L, Msg);
     100             :     return true;
     101             :   }
     102           1 :   bool TokError(const Twine &Msg) const {
     103           2 :     return Error(Lex.getLoc(), Msg);
     104             :   }
     105             :   const TGLexer::DependenciesMapTy &getDependencies() const {
     106             :     return Lex.getDependencies();
     107             :   }
     108             : 
     109             : private:  // Semantic analysis methods.
     110             :   bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV);
     111             :   bool SetValue(Record *TheRec, SMLoc Loc, Init *ValName,
     112             :                 ArrayRef<unsigned> BitList, Init *V,
     113             :                 bool AllowSelfAssignment = false);
     114             :   bool AddSubClass(Record *Rec, SubClassReference &SubClass);
     115             :   bool AddSubMultiClass(MultiClass *CurMC,
     116             :                         SubMultiClassReference &SubMultiClass);
     117             : 
     118             :   // IterRecord: Map an iterator name to a value.
     119             :   struct IterRecord {
     120             :     VarInit *IterVar;
     121             :     Init *IterValue;
     122      199601 :     IterRecord(VarInit *Var, Init *Val) : IterVar(Var), IterValue(Val) {}
     123             :   };
     124             : 
     125             :   // IterSet: The set of all iterator values at some point in the
     126             :   // iteration space.
     127             :   typedef std::vector<IterRecord> IterSet;
     128             : 
     129             :   bool addDefOne(std::unique_ptr<Record> Rec, IterSet &IterVals);
     130             :   bool addDefForeach(Record *Rec, IterSet &IterVals);
     131             :   bool addDef(std::unique_ptr<Record> Rec);
     132             : 
     133             : private:  // Parser methods.
     134             :   bool ParseObjectList(MultiClass *MC = nullptr);
     135             :   bool ParseObject(MultiClass *MC);
     136             :   bool ParseClass();
     137             :   bool ParseMultiClass();
     138             :   bool ParseDefm(MultiClass *CurMultiClass);
     139             :   bool ParseDef(MultiClass *CurMultiClass);
     140             :   bool ParseDefset();
     141             :   bool ParseForeach(MultiClass *CurMultiClass);
     142             :   bool ParseTopLevelLet(MultiClass *CurMultiClass);
     143             :   void ParseLetList(SmallVectorImpl<LetRecord> &Result);
     144             : 
     145             :   bool ParseObjectBody(Record *CurRec);
     146             :   bool ParseBody(Record *CurRec);
     147             :   bool ParseBodyItem(Record *CurRec);
     148             : 
     149             :   bool ParseTemplateArgList(Record *CurRec);
     150             :   Init *ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
     151             :   VarInit *ParseForeachDeclaration(ListInit *&ForeachListValue);
     152             : 
     153             :   SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
     154             :   SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
     155             : 
     156             :   Init *ParseIDValue(Record *CurRec, StringInit *Name, SMLoc NameLoc,
     157             :                      IDParseMode Mode = ParseValueMode);
     158             :   Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = nullptr,
     159             :                          IDParseMode Mode = ParseValueMode);
     160             :   Init *ParseValue(Record *CurRec, RecTy *ItemType = nullptr,
     161             :                    IDParseMode Mode = ParseValueMode);
     162             :   void ParseValueList(SmallVectorImpl<llvm::Init*> &Result, Record *CurRec,
     163             :                       Record *ArgsRec = nullptr, RecTy *EltTy = nullptr);
     164             :   void ParseDagArgList(
     165             :       SmallVectorImpl<std::pair<llvm::Init*, StringInit*>> &Result,
     166             :       Record *CurRec);
     167             :   bool ParseOptionalRangeList(SmallVectorImpl<unsigned> &Ranges);
     168             :   bool ParseOptionalBitList(SmallVectorImpl<unsigned> &Ranges);
     169             :   void ParseRangeList(SmallVectorImpl<unsigned> &Result);
     170             :   bool ParseRangePiece(SmallVectorImpl<unsigned> &Ranges);
     171             :   RecTy *ParseType();
     172             :   Init *ParseOperation(Record *CurRec, RecTy *ItemType);
     173             :   RecTy *ParseOperatorType();
     174             :   Init *ParseObjectName(MultiClass *CurMultiClass);
     175             :   Record *ParseClassID();
     176             :   MultiClass *ParseMultiClassID();
     177             :   bool ApplyLetStack(Record *CurRec);
     178             : };
     179             : 
     180             : } // end namespace llvm
     181             : 
     182             : #endif

Generated by: LCOV version 1.13