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 //===----------------------------------------------------------------------===//
26 class SubClassReference;
30 std::vector<unsigned> Bits;
33 LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
35 : Name(N), Bits(B), Value(V), Loc(L) {
41 std::vector<std::vector<LetRecord> > LetStack;
42 std::map<std::string, MultiClass*> MultiClasses;
44 /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the
46 MultiClass *CurMultiClass;
48 typedef TGLexer::LocTy LocTy;
50 TGParser(MemoryBuffer *StartBuf) : Lex(StartBuf), 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(LocTy 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, LocTy Loc, const RecordVal &RV);
67 bool SetValue(Record *TheRec, LocTy Loc, const std::string &ValName,
68 const std::vector<unsigned> &BitList, Init *V);
69 bool AddSubClass(Record *Rec, SubClassReference &SubClass);
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);
91 Init *ParseIDValue(Record *CurRec);
92 Init *ParseIDValue(Record *CurRec, const std::string &Name, LocTy NameLoc);
93 Init *ParseSimpleValue(Record *CurRec);
94 Init *ParseValue(Record *CurRec);
95 std::vector<Init*> ParseValueList(Record *CurRec);
96 std::vector<std::pair<llvm::Init*, std::string> > ParseDagArgList(Record *);
97 bool ParseOptionalRangeList(std::vector<unsigned> &Ranges);
98 bool ParseOptionalBitList(std::vector<unsigned> &Ranges);
99 std::vector<unsigned> ParseRangeList();
100 bool ParseRangePiece(std::vector<unsigned> &Ranges);
102 std::string ParseObjectName();
103 Record *ParseClassID();
104 Record *ParseDefmID();
107 } // end namespace llvm