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 "llvm/Support/SourceMgr.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(SourceMgr
&SrcMgr
) : Lex(SrcMgr
), CurMultiClass(0) {}
52 /// ParseFile - Main entrypoint for parsing a tblgen file. These parser
53 /// routines return true on error, or false on success.
56 bool Error(SMLoc L
, const std::string
&Msg
) const {
57 Lex
.PrintError(L
, Msg
);
60 bool TokError(const std::string
&Msg
) const {
61 return Error(Lex
.getLoc(), Msg
);
63 private: // Semantic analysis methods.
64 bool AddValue(Record
*TheRec
, SMLoc Loc
, const RecordVal
&RV
);
65 bool SetValue(Record
*TheRec
, SMLoc Loc
, const std::string
&ValName
,
66 const std::vector
<unsigned> &BitList
, Init
*V
);
67 bool AddSubClass(Record
*Rec
, SubClassReference
&SubClass
);
68 bool AddSubMultiClass(MultiClass
*CurMC
,
69 SubMultiClassReference
&SubMultiClass
);
71 private: // Parser methods.
72 bool ParseObjectList();
75 bool ParseMultiClass();
76 bool ParseMultiClassDef(MultiClass
*CurMC
);
78 bool ParseTopLevelLet();
79 std::vector
<LetRecord
> ParseLetList();
81 Record
*ParseDef(MultiClass
*CurMultiClass
);
82 bool ParseObjectBody(Record
*CurRec
);
83 bool ParseBody(Record
*CurRec
);
84 bool ParseBodyItem(Record
*CurRec
);
86 bool ParseTemplateArgList(Record
*CurRec
);
87 std::string
ParseDeclaration(Record
*CurRec
, bool ParsingTemplateArgs
);
89 SubClassReference
ParseSubClassReference(Record
*CurRec
, bool isDefm
);
90 SubMultiClassReference
ParseSubMultiClassReference(MultiClass
*CurMC
);
92 Init
*ParseIDValue(Record
*CurRec
);
93 Init
*ParseIDValue(Record
*CurRec
, const std::string
&Name
, SMLoc NameLoc
);
94 Init
*ParseSimpleValue(Record
*CurRec
, RecTy
*ItemType
= 0);
95 Init
*ParseValue(Record
*CurRec
, RecTy
*ItemType
= 0);
96 std::vector
<Init
*> ParseValueList(Record
*CurRec
, Record
*ArgsRec
= 0, RecTy
*EltTy
= 0);
97 std::vector
<std::pair
<llvm::Init
*, std::string
> > ParseDagArgList(Record
*);
98 bool ParseOptionalRangeList(std::vector
<unsigned> &Ranges
);
99 bool ParseOptionalBitList(std::vector
<unsigned> &Ranges
);
100 std::vector
<unsigned> ParseRangeList();
101 bool ParseRangePiece(std::vector
<unsigned> &Ranges
);
103 Init
*ParseOperation(Record
*CurRec
);
104 RecTy
*ParseOperatorType();
105 std::string
ParseObjectName();
106 Record
*ParseClassID();
107 MultiClass
*ParseMultiClassID();
108 Record
*ParseDefmID();
111 } // end namespace llvm