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 *MV, class SubMultiClassReference &SubMultiClass);
72 private: // Parser methods.
73 bool ParseObjectList();
76 bool ParseMultiClass();
77 bool ParseMultiClassDef(MultiClass *CurMC);
79 bool ParseTopLevelLet();
80 std::vector<LetRecord> ParseLetList();
82 Record *ParseDef(MultiClass *CurMultiClass);
83 bool ParseObjectBody(Record *CurRec);
84 bool ParseBody(Record *CurRec);
85 bool ParseBodyItem(Record *CurRec);
87 bool ParseTemplateArgList(Record *CurRec);
88 std::string ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
90 SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
91 SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMultiClass);
93 Init *ParseIDValue(Record *CurRec);
94 Init *ParseIDValue(Record *CurRec, const std::string &Name, TGLoc NameLoc);
95 Init *ParseSimpleValue(Record *CurRec);
96 Init *ParseValue(Record *CurRec);
97 std::vector<Init*> ParseValueList(Record *CurRec);
98 std::vector<std::pair<llvm::Init*, std::string> > ParseDagArgList(Record *);
99 bool ParseOptionalRangeList(std::vector<unsigned> &Ranges);
100 bool ParseOptionalBitList(std::vector<unsigned> &Ranges);
101 std::vector<unsigned> ParseRangeList();
102 bool ParseRangePiece(std::vector<unsigned> &Ranges);
104 std::string ParseObjectName();
105 Record *ParseClassID();
106 MultiClass *ParseMultiClassID();
107 Record *ParseDefmID();
110 } // end namespace llvm