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"
32 // Tokens with no info.
34 l_square, r_square, // [ ]
35 l_brace, r_brace, // { }
36 l_paren, r_paren, // ( )
40 equal, question, // = ?
43 Bit, Bits, Class, Code, Dag, Def, Defm, Field, In, Int, Let, List,
47 XConcat, XSRA, XSRL, XSHL, XStrConcat,
52 // String valued tokens.
53 Id, StrVal, VarName, CodeFragment
57 /// TGLexer - TableGen Lexer class.
62 const MemoryBuffer *CurBuf;
64 // Information about the current token.
66 tgtok::TokKind CurCode;
67 std::string CurStrVal; // This is valid for ID, STRVAL, VARNAME, CODEFRAGMENT
68 int64_t CurIntVal; // This is valid for INTVAL.
70 /// CurBuffer - This is the current buffer index we're lexing from as managed
71 /// by the SourceMgr object.
74 // IncludeDirectories - This is the list of directories we should search for
76 std::vector<std::string> IncludeDirectories;
78 TGLexer(TGSourceMgr &SrcMgr);
81 void setIncludeDirs(const std::vector<std::string> &Dirs) {
82 IncludeDirectories = Dirs;
85 tgtok::TokKind Lex() {
86 return CurCode = LexToken();
89 tgtok::TokKind getCode() const { return CurCode; }
91 const std::string &getCurStrVal() const {
92 assert((CurCode == tgtok::Id || CurCode == tgtok::StrVal ||
93 CurCode == tgtok::VarName || CurCode == tgtok::CodeFragment) &&
94 "This token doesn't have a string value");
97 int64_t getCurIntVal() const {
98 assert(CurCode == tgtok::IntVal && "This token isn't an integer");
102 typedef const char* LocTy;
103 LocTy getLoc() const { return TokStart; }
105 void PrintError(LocTy Loc, const std::string &Msg) const;
108 /// LexToken - Read the next token and return its code.
109 tgtok::TokKind LexToken();
111 tgtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
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