Fix bugs section.
[llvm-complete.git] / utils / TableGen / TGParser.h
bloba5435afacf29ad9f99d3c3422380f3d0265a32df
1 //===- TGParser.h - Parser for TableGen Files -------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class represents the Parser for tablegen files.
12 //===----------------------------------------------------------------------===//
14 #ifndef TGPARSER_H
15 #define TGPARSER_H
17 #include "TGLexer.h"
18 #include <map>
20 namespace llvm {
21 class Record;
22 class RecordVal;
23 class RecTy;
24 class Init;
25 struct MultiClass;
26 struct SubClassReference;
28 struct LetRecord {
29 std::string Name;
30 std::vector<unsigned> Bits;
31 Init *Value;
32 TGLexer::LocTy Loc;
33 LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
34 TGLexer::LocTy L)
35 : Name(N), Bits(B), Value(V), Loc(L) {
39 class TGParser {
40 TGLexer Lex;
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
45 /// current value.
46 MultiClass *CurMultiClass;
47 public:
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.
56 bool ParseFile();
58 bool Error(LocTy L, const std::string &Msg) const {
59 Lex.PrintError(L, Msg);
60 return true;
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, class SubClassReference &SubClass);
71 private: // Parser methods.
72 bool ParseObjectList();
73 bool ParseObject();
74 bool ParseClass();
75 bool ParseMultiClass();
76 bool ParseMultiClassDef(MultiClass *CurMC);
77 bool ParseDefm();
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);
101 RecTy *ParseType();
102 std::string ParseObjectName();
103 Record *ParseClassID();
104 Record *ParseDefmID();
107 } // end namespace llvm
109 #endif