Silence -Wunused-variable in release builds.
[llvm/stm8.git] / utils / TableGen / TGParser.h
blob94a1c2b2b258265fd6e99d52a6c0d290ef66f8e9
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 "Error.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/Support/SourceMgr.h"
21 #include <map>
23 namespace llvm {
24 class Record;
25 class RecordVal;
26 class RecordKeeper;
27 struct RecTy;
28 struct Init;
29 struct MultiClass;
30 struct SubClassReference;
31 struct SubMultiClassReference;
33 struct LetRecord {
34 std::string Name;
35 std::vector<unsigned> Bits;
36 Init *Value;
37 SMLoc Loc;
38 LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
39 SMLoc L)
40 : Name(N), Bits(B), Value(V), Loc(L) {
44 class TGParser {
45 TGLexer Lex;
46 std::vector<std::vector<LetRecord> > LetStack;
47 std::map<std::string, MultiClass*> MultiClasses;
49 /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the
50 /// current value.
51 MultiClass *CurMultiClass;
53 // Record tracker
54 RecordKeeper &Records;
55 public:
56 TGParser(SourceMgr &SrcMgr, RecordKeeper &records) :
57 Lex(SrcMgr), CurMultiClass(0), Records(records) {}
59 /// ParseFile - Main entrypoint for parsing a tblgen file. These parser
60 /// routines return true on error, or false on success.
61 bool ParseFile();
63 bool Error(SMLoc L, const Twine &Msg) const {
64 PrintError(L, Msg);
65 return true;
67 bool TokError(const Twine &Msg) const {
68 return Error(Lex.getLoc(), Msg);
70 const std::vector<std::string> &getDependencies() const {
71 return Lex.getDependencies();
73 private: // Semantic analysis methods.
74 bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV);
75 bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName,
76 const std::vector<unsigned> &BitList, Init *V);
77 bool AddSubClass(Record *Rec, SubClassReference &SubClass);
78 bool AddSubMultiClass(MultiClass *CurMC,
79 SubMultiClassReference &SubMultiClass);
81 private: // Parser methods.
82 bool ParseObjectList(MultiClass *MC = 0);
83 bool ParseObject(MultiClass *MC);
84 bool ParseClass();
85 bool ParseMultiClass();
86 bool ParseDefm(MultiClass *CurMultiClass);
87 bool ParseDef(MultiClass *CurMultiClass);
88 bool ParseTopLevelLet(MultiClass *CurMultiClass);
89 std::vector<LetRecord> ParseLetList();
91 bool ParseObjectBody(Record *CurRec);
92 bool ParseBody(Record *CurRec);
93 bool ParseBodyItem(Record *CurRec);
95 bool ParseTemplateArgList(Record *CurRec);
96 std::string ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
98 SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
99 SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
101 Init *ParseIDValue(Record *CurRec);
102 Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc);
103 Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = 0);
104 Init *ParseValue(Record *CurRec, RecTy *ItemType = 0);
105 std::vector<Init*> ParseValueList(Record *CurRec, Record *ArgsRec = 0, RecTy *EltTy = 0);
106 std::vector<std::pair<llvm::Init*, std::string> > ParseDagArgList(Record *);
107 bool ParseOptionalRangeList(std::vector<unsigned> &Ranges);
108 bool ParseOptionalBitList(std::vector<unsigned> &Ranges);
109 std::vector<unsigned> ParseRangeList();
110 bool ParseRangePiece(std::vector<unsigned> &Ranges);
111 RecTy *ParseType();
112 Init *ParseOperation(Record *CurRec);
113 RecTy *ParseOperatorType();
114 std::string ParseObjectName();
115 Record *ParseClassID();
116 MultiClass *ParseMultiClassID();
117 Record *ParseDefmID();
120 } // end namespace llvm
122 #endif