Do more to modernize MergeFunctions. Refactor in response to Chris' code review.
[llvm.git] / utils / TableGen / TGParser.h
blob0aee931423a618997ca2fd428690a5dbd1dc58e5
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 "llvm/Support/SourceMgr.h"
19 #include <map>
21 namespace llvm {
22 class Record;
23 class RecordVal;
24 struct RecTy;
25 struct Init;
26 struct MultiClass;
27 struct SubClassReference;
28 struct SubMultiClassReference;
30 struct LetRecord {
31 std::string Name;
32 std::vector<unsigned> Bits;
33 Init *Value;
34 SMLoc Loc;
35 LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
36 SMLoc L)
37 : Name(N), Bits(B), Value(V), Loc(L) {
41 class TGParser {
42 TGLexer Lex;
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
47 /// current value.
48 MultiClass *CurMultiClass;
49 public:
50 TGParser(SourceMgr &SrcMgr) : Lex(SrcMgr), CurMultiClass(0) {}
52 /// ParseFile - Main entrypoint for parsing a tblgen file. These parser
53 /// routines return true on error, or false on success.
54 bool ParseFile();
56 bool Error(SMLoc L, const std::string &Msg) const {
57 Lex.PrintError(L, Msg);
58 return true;
60 bool TokError(const std::string &Msg) const {
61 return Error(Lex.getLoc(), Msg);
63 private: // Semantic analysis methods.
64 bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV);
65 bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName,
66 const std::vector<unsigned> &BitList, Init *V);
67 bool AddSubClass(Record *Rec, SubClassReference &SubClass);
68 bool AddSubMultiClass(MultiClass *CurMC,
69 SubMultiClassReference &SubMultiClass);
71 private: // Parser methods.
72 bool ParseObjectList(MultiClass *MC = 0);
73 bool ParseObject(MultiClass *MC);
74 bool ParseClass();
75 bool ParseMultiClass();
76 bool ParseDefm(MultiClass *CurMultiClass);
77 bool ParseDef(MultiClass *CurMultiClass);
78 bool ParseTopLevelLet(MultiClass *CurMultiClass);
79 std::vector<LetRecord> ParseLetList();
81 bool ParseObjectBody(Record *CurRec);
82 bool ParseBody(Record *CurRec);
83 bool ParseBodyItem(Record *CurRec);
85 bool ParseTemplateArgList(Record *CurRec);
86 std::string ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
88 SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
89 SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
91 Init *ParseIDValue(Record *CurRec);
92 Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc);
93 Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = 0);
94 Init *ParseValue(Record *CurRec, RecTy *ItemType = 0);
95 std::vector<Init*> ParseValueList(Record *CurRec, Record *ArgsRec = 0, RecTy *EltTy = 0);
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 Init *ParseOperation(Record *CurRec);
103 RecTy *ParseOperatorType();
104 std::string ParseObjectName();
105 Record *ParseClassID();
106 MultiClass *ParseMultiClassID();
107 Record *ParseDefmID();
110 } // end namespace llvm
112 #endif