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
, XNameConcat
, XCast
, XSubst
,
49 XForEach
, XCar
, XCdr
, XNull
, XIf
,
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.
76 // IncludeDirectories - This is the list of directories we should search for
78 std::vector
<std::string
> IncludeDirectories
;
80 TGLexer(TGSourceMgr
&SrcMgr
);
83 void setIncludeDirs(const std::vector
<std::string
> &Dirs
) {
84 IncludeDirectories
= Dirs
;
87 tgtok::TokKind
Lex() {
88 return CurCode
= LexToken();
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 TGLoc
getLoc() const;
106 void PrintError(const char *Loc
, const std::string
&Msg
) const;
107 void PrintError(TGLoc Loc
, const std::string
&Msg
) const;
110 /// LexToken - Read the next token and return its code.
111 tgtok::TokKind
LexToken();
113 tgtok::TokKind
ReturnError(const char *Loc
, const std::string
&Msg
);
116 void SkipBCPLComment();
118 tgtok::TokKind
LexIdentifier();
120 tgtok::TokKind
LexString();
121 tgtok::TokKind
LexVarName();
122 tgtok::TokKind
LexNumber();
123 tgtok::TokKind
LexBracket();
124 tgtok::TokKind
LexExclaim();
127 } // end namespace llvm