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/ADT/Twine.h"
19 #include "llvm/Support/SourceMgr.h"
29 struct SubClassReference;
30 struct SubMultiClassReference;
34 std::vector<unsigned> Bits;
37 LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
39 : Name(N), Bits(B), Value(V), Loc(L) {
45 std::vector<std::vector<LetRecord> > LetStack;
46 std::map<std::string, MultiClass*> MultiClasses;
48 /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the
50 MultiClass *CurMultiClass;
53 RecordKeeper &Records;
55 TGParser(SourceMgr &SrcMgr, RecordKeeper &records) :
56 Lex(SrcMgr), CurMultiClass(0), Records(records) {}
58 /// ParseFile - Main entrypoint for parsing a tblgen file. These parser
59 /// routines return true on error, or false on success.
62 bool Error(SMLoc L, const Twine &Msg) const {
63 Lex.PrintError(L, Msg);
66 bool TokError(const Twine &Msg) const {
67 return Error(Lex.getLoc(), Msg);
69 const std::vector<std::string> &getDependencies() const {
70 return Lex.getDependencies();
72 private: // Semantic analysis methods.
73 bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV);
74 bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName,
75 const std::vector<unsigned> &BitList, Init *V);
76 bool AddSubClass(Record *Rec, SubClassReference &SubClass);
77 bool AddSubMultiClass(MultiClass *CurMC,
78 SubMultiClassReference &SubMultiClass);
80 private: // Parser methods.
81 bool ParseObjectList(MultiClass *MC = 0);
82 bool ParseObject(MultiClass *MC);
84 bool ParseMultiClass();
85 bool ParseDefm(MultiClass *CurMultiClass);
86 bool ParseDef(MultiClass *CurMultiClass);
87 bool ParseTopLevelLet(MultiClass *CurMultiClass);
88 std::vector<LetRecord> ParseLetList();
90 bool ParseObjectBody(Record *CurRec);
91 bool ParseBody(Record *CurRec);
92 bool ParseBodyItem(Record *CurRec);
94 bool ParseTemplateArgList(Record *CurRec);
95 std::string ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
97 SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
98 SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
100 Init *ParseIDValue(Record *CurRec);
101 Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc);
102 Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = 0);
103 Init *ParseValue(Record *CurRec, RecTy *ItemType = 0);
104 std::vector<Init*> ParseValueList(Record *CurRec, Record *ArgsRec = 0, RecTy *EltTy = 0);
105 std::vector<std::pair<llvm::Init*, std::string> > ParseDagArgList(Record *);
106 bool ParseOptionalRangeList(std::vector<unsigned> &Ranges);
107 bool ParseOptionalBitList(std::vector<unsigned> &Ranges);
108 std::vector<unsigned> ParseRangeList();
109 bool ParseRangePiece(std::vector<unsigned> &Ranges);
111 Init *ParseOperation(Record *CurRec);
112 RecTy *ParseOperatorType();
113 std::string ParseObjectName();
114 Record *ParseClassID();
115 MultiClass *ParseMultiClassID();
116 Record *ParseDefmID();
119 } // end namespace llvm