1 //===- TGParser.h - Parser for TableGen Files -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class represents the Parser for tablegen files.
12 //===----------------------------------------------------------------------===//
18 #include "TGSourceMgr.h"
27 struct SubClassReference
;
28 struct SubMultiClassReference
;
32 std::vector
<unsigned> Bits
;
35 LetRecord(const std::string
&N
, const std::vector
<unsigned> &B
, Init
*V
,
37 : Name(N
), Bits(B
), Value(V
), Loc(L
) {
43 std::vector
<std::vector
<LetRecord
> > LetStack
;
44 std::map
<std::string
, MultiClass
*> MultiClasses
;
46 /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the
48 MultiClass
*CurMultiClass
;
50 TGParser(TGSourceMgr
&SrcMgr
) : Lex(SrcMgr
), CurMultiClass(0) {}
52 void setIncludeDirs(const std::vector
<std::string
> &D
){Lex
.setIncludeDirs(D
);}
54 /// ParseFile - Main entrypoint for parsing a tblgen file. These parser
55 /// routines return true on error, or false on success.
58 bool Error(TGLoc L
, const std::string
&Msg
) const {
59 Lex
.PrintError(L
, Msg
);
62 bool TokError(const std::string
&Msg
) const {
63 return Error(Lex
.getLoc(), Msg
);
65 private: // Semantic analysis methods.
66 bool AddValue(Record
*TheRec
, TGLoc Loc
, const RecordVal
&RV
);
67 bool SetValue(Record
*TheRec
, TGLoc Loc
, const std::string
&ValName
,
68 const std::vector
<unsigned> &BitList
, Init
*V
);
69 bool AddSubClass(Record
*Rec
, SubClassReference
&SubClass
);
70 bool AddSubMultiClass(MultiClass
*CurMC
,
71 SubMultiClassReference
&SubMultiClass
);
73 private: // Parser methods.
74 bool ParseObjectList();
77 bool ParseMultiClass();
78 bool ParseMultiClassDef(MultiClass
*CurMC
);
80 bool ParseTopLevelLet();
81 std::vector
<LetRecord
> ParseLetList();
83 Record
*ParseDef(MultiClass
*CurMultiClass
);
84 bool ParseObjectBody(Record
*CurRec
);
85 bool ParseBody(Record
*CurRec
);
86 bool ParseBodyItem(Record
*CurRec
);
88 bool ParseTemplateArgList(Record
*CurRec
);
89 std::string
ParseDeclaration(Record
*CurRec
, bool ParsingTemplateArgs
);
91 SubClassReference
ParseSubClassReference(Record
*CurRec
, bool isDefm
);
92 SubMultiClassReference
ParseSubMultiClassReference(MultiClass
*CurMC
);
94 Init
*ParseIDValue(Record
*CurRec
);
95 Init
*ParseIDValue(Record
*CurRec
, const std::string
&Name
, TGLoc NameLoc
);
96 Init
*ParseSimpleValue(Record
*CurRec
);
97 Init
*ParseValue(Record
*CurRec
);
98 std::vector
<Init
*> ParseValueList(Record
*CurRec
);
99 std::vector
<std::pair
<llvm::Init
*, std::string
> > ParseDagArgList(Record
*);
100 bool ParseOptionalRangeList(std::vector
<unsigned> &Ranges
);
101 bool ParseOptionalBitList(std::vector
<unsigned> &Ranges
);
102 std::vector
<unsigned> ParseRangeList();
103 bool ParseRangePiece(std::vector
<unsigned> &Ranges
);
105 std::string
ParseObjectName();
106 Record
*ParseClassID();
107 MultiClass
*ParseMultiClassID();
108 Record
*ParseDefmID();
111 } // end namespace llvm