]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/utils/TableGen/TGParser.h
Update llvm/clang to trunk r126547.
[FreeBSD/FreeBSD.git] / contrib / llvm / utils / TableGen / TGParser.h
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 TGPARSER_H
15 #define TGPARSER_H
16
17 #include "TGLexer.h"
18 #include "llvm/ADT/Twine.h"
19 #include "llvm/Support/SourceMgr.h"
20 #include <map>
21
22 namespace llvm {
23   class Record;
24   class RecordVal;
25   class RecordKeeper;
26   struct RecTy;
27   struct Init;
28   struct MultiClass;
29   struct SubClassReference;
30   struct SubMultiClassReference;
31   
32   struct LetRecord {
33     std::string Name;
34     std::vector<unsigned> Bits;
35     Init *Value;
36     SMLoc Loc;
37     LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
38               SMLoc L)
39       : Name(N), Bits(B), Value(V), Loc(L) {
40     }
41   };
42   
43 class TGParser {
44   TGLexer Lex;
45   std::vector<std::vector<LetRecord> > LetStack;
46   std::map<std::string, MultiClass*> MultiClasses;
47   
48   /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the 
49   /// current value.
50   MultiClass *CurMultiClass;
51
52   // Record tracker
53   RecordKeeper &Records;
54 public:
55   TGParser(SourceMgr &SrcMgr, RecordKeeper &records) : 
56     Lex(SrcMgr), CurMultiClass(0), Records(records) {}
57   
58   /// ParseFile - Main entrypoint for parsing a tblgen file.  These parser
59   /// routines return true on error, or false on success.
60   bool ParseFile();
61   
62   bool Error(SMLoc L, const Twine &Msg) const {
63     Lex.PrintError(L, Msg);
64     return true;
65   }
66   bool TokError(const Twine &Msg) const {
67     return Error(Lex.getLoc(), Msg);
68   }
69 private:  // Semantic analysis methods.
70   bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV);
71   bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName, 
72                 const std::vector<unsigned> &BitList, Init *V);
73   bool AddSubClass(Record *Rec, SubClassReference &SubClass);
74   bool AddSubMultiClass(MultiClass *CurMC,
75                         SubMultiClassReference &SubMultiClass);
76
77 private:  // Parser methods.
78   bool ParseObjectList(MultiClass *MC = 0);
79   bool ParseObject(MultiClass *MC);
80   bool ParseClass();
81   bool ParseMultiClass();
82   bool ParseDefm(MultiClass *CurMultiClass);
83   bool ParseDef(MultiClass *CurMultiClass);
84   bool ParseTopLevelLet(MultiClass *CurMultiClass);
85   std::vector<LetRecord> ParseLetList();
86
87   bool ParseObjectBody(Record *CurRec);
88   bool ParseBody(Record *CurRec);
89   bool ParseBodyItem(Record *CurRec);
90
91   bool ParseTemplateArgList(Record *CurRec);
92   std::string ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
93
94   SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
95   SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
96
97   Init *ParseIDValue(Record *CurRec);
98   Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc);
99   Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = 0);
100   Init *ParseValue(Record *CurRec, RecTy *ItemType = 0);
101   std::vector<Init*> ParseValueList(Record *CurRec, Record *ArgsRec = 0, RecTy *EltTy = 0);
102   std::vector<std::pair<llvm::Init*, std::string> > ParseDagArgList(Record *);
103   bool ParseOptionalRangeList(std::vector<unsigned> &Ranges);
104   bool ParseOptionalBitList(std::vector<unsigned> &Ranges);
105   std::vector<unsigned> ParseRangeList();
106   bool ParseRangePiece(std::vector<unsigned> &Ranges);
107   RecTy *ParseType();
108   Init *ParseOperation(Record *CurRec);
109   RecTy *ParseOperatorType();
110   std::string ParseObjectName();
111   Record *ParseClassID();
112   MultiClass *ParseMultiClassID();
113   Record *ParseDefmID();
114 };
115   
116 } // end namespace llvm
117
118 #endif