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 //===----------------------------------------------------------------------===//
17 #include "llvm/Support/DataTypes.h"
18 #include "llvm/Support/SMLoc.h"
34 // Tokens with no info.
36 l_square, r_square, // [ ]
37 l_brace, r_brace, // { }
38 l_paren, r_paren, // ( )
42 equal, question, // = ?
46 Bit, Bits, Class, Code, Dag, Def, Foreach, Defm, Field, In, Int, Let, List,
50 XConcat, XADD, XSRA, XSRL, XSHL, XStrConcat, XCast, XSubst,
51 XForEach, XHead, XTail, XEmpty, XIf, XEq,
56 // String valued tokens.
57 Id, StrVal, VarName, CodeFragment
61 /// TGLexer - TableGen Lexer class.
66 const MemoryBuffer *CurBuf;
68 // Information about the current token.
70 tgtok::TokKind CurCode;
71 std::string CurStrVal; // This is valid for ID, STRVAL, VARNAME, CODEFRAGMENT
72 int64_t CurIntVal; // This is valid for INTVAL.
74 /// CurBuffer - This is the current buffer index we're lexing from as managed
75 /// by the SourceMgr object.
79 typedef std::map<std::string, SMLoc> DependenciesMapTy;
81 /// Dependencies - This is the list of all included files.
82 DependenciesMapTy Dependencies;
85 TGLexer(SourceMgr &SrcMgr);
88 tgtok::TokKind Lex() {
89 return CurCode = LexToken();
92 const DependenciesMapTy &getDependencies() const {
96 tgtok::TokKind getCode() const { return CurCode; }
98 const std::string &getCurStrVal() const {
99 assert((CurCode == tgtok::Id || CurCode == tgtok::StrVal ||
100 CurCode == tgtok::VarName || CurCode == tgtok::CodeFragment) &&
101 "This token doesn't have a string value");
104 int64_t getCurIntVal() const {
105 assert(CurCode == tgtok::IntVal && "This token isn't an integer");
109 SMLoc getLoc() const;
112 /// LexToken - Read the next token and return its code.
113 tgtok::TokKind LexToken();
115 tgtok::TokKind ReturnError(const char *Loc, const Twine &Msg);
118 int peekNextChar(int Index);
119 void SkipBCPLComment();
121 tgtok::TokKind LexIdentifier();
123 tgtok::TokKind LexString();
124 tgtok::TokKind LexVarName();
125 tgtok::TokKind LexNumber();
126 tgtok::TokKind LexBracket();
127 tgtok::TokKind LexExclaim();
130 } // end namespace llvm