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"
33 // Tokens with no info.
35 l_square, r_square, // [ ]
36 l_brace, r_brace, // { }
37 l_paren, r_paren, // ( )
41 equal, question, // = ?
45 Bit, Bits, Class, Code, Dag, Def, Defm, Field, In, Int, Let, List,
49 XConcat, XSRA, XSRL, XSHL, XStrConcat, XCast, XSubst,
50 XForEach, XHead, XTail, XEmpty, XIf, XEq,
55 // String valued tokens.
56 Id, StrVal, VarName, CodeFragment
60 /// TGLexer - TableGen Lexer class.
65 const MemoryBuffer *CurBuf;
67 // Information about the current token.
69 tgtok::TokKind CurCode;
70 std::string CurStrVal; // This is valid for ID, STRVAL, VARNAME, CODEFRAGMENT
71 int64_t CurIntVal; // This is valid for INTVAL.
73 /// CurBuffer - This is the current buffer index we're lexing from as managed
74 /// by the SourceMgr object.
76 /// Dependencies - This is the list of all included files.
77 std::vector<std::string> Dependencies;
80 TGLexer(SourceMgr &SrcMgr);
83 tgtok::TokKind Lex() {
84 return CurCode = LexToken();
87 const std::vector<std::string> &getDependencies() const {
91 tgtok::TokKind getCode() const { return CurCode; }
93 const std::string &getCurStrVal() const {
94 assert((CurCode == tgtok::Id || CurCode == tgtok::StrVal ||
95 CurCode == tgtok::VarName || CurCode == tgtok::CodeFragment) &&
96 "This token doesn't have a string value");
99 int64_t getCurIntVal() const {
100 assert(CurCode == tgtok::IntVal && "This token isn't an integer");
104 SMLoc getLoc() const;
107 /// LexToken - Read the next token and return its code.
108 tgtok::TokKind LexToken();
110 tgtok::TokKind ReturnError(const char *Loc, const Twine &Msg);
113 int peekNextChar(int Index);
114 void SkipBCPLComment();
116 tgtok::TokKind LexIdentifier();
118 tgtok::TokKind LexString();
119 tgtok::TokKind LexVarName();
120 tgtok::TokKind LexNumber();
121 tgtok::TokKind LexBracket();
122 tgtok::TokKind LexExclaim();
125 } // end namespace llvm