Proper name 16 bit libcalls
[llvm/msp430.git] / utils / TableGen / TGParser.h
blob358fee65cb2da0a23592860ff1b907047f06ce38
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 "TGSourceMgr.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 TGLoc Loc;
35 LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
36 TGLoc 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(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.
56 bool ParseFile();
58 bool Error(TGLoc 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, 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 *CurMC,
71 SubMultiClassReference &SubMultiClass);
73 private: // Parser methods.
74 bool ParseObjectList();
75 bool ParseObject();
76 bool ParseClass();
77 bool ParseMultiClass();
78 bool ParseMultiClassDef(MultiClass *CurMC);
79 bool ParseDefm();
80 bool ParseTopLevelLet();
81 std::vector<LetRecord> ParseLetList();
83 Record *ParseDef(MultiClass *CurMultiClass);
84 bool ParseObjectBody(Record *CurRec);
85 bool ParseBody(Record *CurRec);
86 bool ParseBodyItem(Record *CurRec);
88 bool ParseTemplateArgList(Record *CurRec);
89 std::string ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
91 SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
92 SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
94 Init *ParseIDValue(Record *CurRec);
95 Init *ParseIDValue(Record *CurRec, const std::string &Name, TGLoc NameLoc);
96 Init *ParseSimpleValue(Record *CurRec);
97 Init *ParseValue(Record *CurRec);
98 std::vector<Init*> ParseValueList(Record *CurRec);
99 std::vector<std::pair<llvm::Init*, std::string> > ParseDagArgList(Record *);
100 bool ParseOptionalRangeList(std::vector<unsigned> &Ranges);
101 bool ParseOptionalBitList(std::vector<unsigned> &Ranges);
102 std::vector<unsigned> ParseRangeList();
103 bool ParseRangePiece(std::vector<unsigned> &Ranges);
104 RecTy *ParseType();
105 std::string ParseObjectName();
106 Record *ParseClassID();
107 MultiClass *ParseMultiClassID();
108 Record *ParseDefmID();
111 } // end namespace llvm
113 #endif