1 //===- TGLexer.h - Lexer 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 Lexer for tablegen files.
12 //===----------------------------------------------------------------------===//
30 // Tokens with no info.
32 l_square, r_square, // [ ]
33 l_brace, r_brace, // { }
34 l_paren, r_paren, // ( )
38 equal, question, // = ?
41 Bit, Bits, Class, Code, Dag, Def, Defm, Field, In, Int, Let, List,
45 XConcat, XSRA, XSRL, XSHL, XStrConcat,
50 // String valued tokens.
51 Id, StrVal, VarName, CodeFragment
55 /// TGLexer - TableGen Lexer class.
61 // Information about the current token.
63 tgtok::TokKind CurCode;
64 std::string CurStrVal; // This is valid for ID, STRVAL, VARNAME, CODEFRAGMENT
65 int CurIntVal; // This is valid for INTVAL.
67 /// IncludeRec / IncludeStack - This captures the current set of include
68 /// directives we are nested within.
73 IncludeRec(MemoryBuffer *buffer, const char *curPtr, unsigned lineNo)
74 : Buffer(buffer), CurPtr(curPtr), LineNo(lineNo) {}
76 std::vector<IncludeRec> IncludeStack;
78 // IncludeDirectories - This is the list of directories we should search for
80 std::vector<std::string> IncludeDirectories;
82 TGLexer(MemoryBuffer *StartBuf);
85 void setIncludeDirs(const std::vector<std::string> &Dirs) {
86 IncludeDirectories = Dirs;
89 tgtok::TokKind Lex() {
90 return CurCode = LexToken();
93 tgtok::TokKind getCode() const { return CurCode; }
95 const std::string &getCurStrVal() const {
96 assert((CurCode == tgtok::Id || CurCode == tgtok::StrVal ||
97 CurCode == tgtok::VarName || CurCode == tgtok::CodeFragment) &&
98 "This token doesn't have a string value");
101 int getCurIntVal() const {
102 assert(CurCode == tgtok::IntVal && "This token isn't an integer");
106 typedef const char* LocTy;
107 LocTy getLoc() const { return TokStart; }
109 void PrintError(LocTy Loc, const std::string &Msg) const;
111 void PrintIncludeStack(std::ostream &OS) const;
114 /// LexToken - Read the next token and return its code.
115 tgtok::TokKind LexToken();
117 tgtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
120 void SkipBCPLComment();
122 tgtok::TokKind LexIdentifier();
124 tgtok::TokKind LexString();
125 tgtok::TokKind LexVarName();
126 tgtok::TokKind LexNumber();
127 tgtok::TokKind LexBracket();
128 tgtok::TokKind LexExclaim();
131 } // end namespace llvm