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"
31 // Tokens with no info.
33 l_square, r_square, // [ ]
34 l_brace, r_brace, // { }
35 l_paren, r_paren, // ( )
39 equal, question, // = ?
42 Bit, Bits, Class, Code, Dag, Def, Defm, Field, In, Int, Let, List,
46 XConcat, XSRA, XSRL, XSHL, XStrConcat,
51 // String valued tokens.
52 Id, StrVal, VarName, CodeFragment
56 /// TGLexer - TableGen Lexer class.
62 // Information about the current token.
64 tgtok::TokKind CurCode;
65 std::string CurStrVal; // This is valid for ID, STRVAL, VARNAME, CODEFRAGMENT
66 int64_t CurIntVal; // This is valid for INTVAL.
68 /// IncludeRec / IncludeStack - This captures the current set of include
69 /// directives we are nested within.
74 IncludeRec(MemoryBuffer *buffer, const char *curPtr, unsigned lineNo)
75 : Buffer(buffer), CurPtr(curPtr), LineNo(lineNo) {}
77 std::vector<IncludeRec> IncludeStack;
79 // IncludeDirectories - This is the list of directories we should search for
81 std::vector<std::string> IncludeDirectories;
83 TGLexer(MemoryBuffer *StartBuf);
86 void setIncludeDirs(const std::vector<std::string> &Dirs) {
87 IncludeDirectories = Dirs;
90 tgtok::TokKind Lex() {
91 return CurCode = LexToken();
94 tgtok::TokKind getCode() const { return CurCode; }
96 const std::string &getCurStrVal() const {
97 assert((CurCode == tgtok::Id || CurCode == tgtok::StrVal ||
98 CurCode == tgtok::VarName || CurCode == tgtok::CodeFragment) &&
99 "This token doesn't have a string value");
102 int64_t getCurIntVal() const {
103 assert(CurCode == tgtok::IntVal && "This token isn't an integer");
107 typedef const char* LocTy;
108 LocTy getLoc() const { return TokStart; }
110 void PrintError(LocTy Loc, const std::string &Msg) const;
112 void PrintIncludeStack(std::ostream &OS) const;
115 /// LexToken - Read the next token and return its code.
116 tgtok::TokKind LexToken();
118 tgtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
121 void SkipBCPLComment();
123 tgtok::TokKind LexIdentifier();
125 tgtok::TokKind LexString();
126 tgtok::TokKind LexVarName();
127 tgtok::TokKind LexNumber();
128 tgtok::TokKind LexBracket();
129 tgtok::TokKind LexExclaim();
132 } // end namespace llvm