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, // = ?
44 Bit, Bits, Class, Code, Dag, Def, Defm, Field, In, Int, Let, List,
48 XConcat, XSRA, XSRL, XSHL, XStrConcat, XCast, XSubst,
49 XForEach, XHead, XTail, XEmpty, XIf, XEq,
54 // String valued tokens.
55 Id, StrVal, VarName, CodeFragment
59 /// TGLexer - TableGen Lexer class.
64 const MemoryBuffer *CurBuf;
66 // Information about the current token.
68 tgtok::TokKind CurCode;
69 std::string CurStrVal; // This is valid for ID, STRVAL, VARNAME, CODEFRAGMENT
70 int64_t CurIntVal; // This is valid for INTVAL.
72 /// CurBuffer - This is the current buffer index we're lexing from as managed
73 /// by the SourceMgr object.
75 /// Dependencies - This is the list of all included files.
76 std::vector<std::string> Dependencies;
79 TGLexer(SourceMgr &SrcMgr);
82 tgtok::TokKind Lex() {
83 return CurCode = LexToken();
86 const std::vector<std::string> &getDependencies() const {
90 tgtok::TokKind getCode() const { return CurCode; }
92 const std::string &getCurStrVal() const {
93 assert((CurCode == tgtok::Id || CurCode == tgtok::StrVal ||
94 CurCode == tgtok::VarName || CurCode == tgtok::CodeFragment) &&
95 "This token doesn't have a string value");
98 int64_t getCurIntVal() const {
99 assert(CurCode == tgtok::IntVal && "This token isn't an integer");
103 SMLoc getLoc() const;
106 /// LexToken - Read the next token and return its code.
107 tgtok::TokKind LexToken();
109 tgtok::TokKind ReturnError(const char *Loc, const Twine &Msg);
112 void SkipBCPLComment();
114 tgtok::TokKind LexIdentifier();
116 tgtok::TokKind LexString();
117 tgtok::TokKind LexVarName();
118 tgtok::TokKind LexNumber();
119 tgtok::TokKind LexBracket();
120 tgtok::TokKind LexExclaim();
123 } // end namespace llvm