Proper name 16 bit libcalls
[llvm/msp430.git] / utils / TableGen / TGLexer.h
blob734dc2651e33d397e188d61a9ac2dd8949c20393
1 //===- TGLexer.h - Lexer for TableGen Files ---------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class represents the Lexer for tablegen files.
12 //===----------------------------------------------------------------------===//
14 #ifndef TGLEXER_H
15 #define TGLEXER_H
17 #include "llvm/Support/DataTypes.h"
18 #include <vector>
19 #include <string>
20 #include <iosfwd>
21 #include <cassert>
23 namespace llvm {
24 class MemoryBuffer;
25 class TGSourceMgr;
26 class TGLoc;
28 namespace tgtok {
29 enum TokKind {
30 // Markers
31 Eof, Error,
33 // Tokens with no info.
34 minus, plus, // - +
35 l_square, r_square, // [ ]
36 l_brace, r_brace, // { }
37 l_paren, r_paren, // ( )
38 less, greater, // < >
39 colon, semi, // ; :
40 comma, period, // , .
41 equal, question, // = ?
43 // Keywords.
44 Bit, Bits, Class, Code, Dag, Def, Defm, Field, In, Int, Let, List,
45 MultiClass, String,
47 // !keywords.
48 XConcat, XSRA, XSRL, XSHL, XStrConcat, XNameConcat,
50 // Integer value.
51 IntVal,
53 // String valued tokens.
54 Id, StrVal, VarName, CodeFragment
58 /// TGLexer - TableGen Lexer class.
59 class TGLexer {
60 TGSourceMgr &SrcMgr;
62 const char *CurPtr;
63 const MemoryBuffer *CurBuf;
65 // Information about the current token.
66 const char *TokStart;
67 tgtok::TokKind CurCode;
68 std::string CurStrVal; // This is valid for ID, STRVAL, VARNAME, CODEFRAGMENT
69 int64_t CurIntVal; // This is valid for INTVAL.
71 /// CurBuffer - This is the current buffer index we're lexing from as managed
72 /// by the SourceMgr object.
73 int CurBuffer;
75 // IncludeDirectories - This is the list of directories we should search for
76 // include files in.
77 std::vector<std::string> IncludeDirectories;
78 public:
79 TGLexer(TGSourceMgr &SrcMgr);
80 ~TGLexer() {}
82 void setIncludeDirs(const std::vector<std::string> &Dirs) {
83 IncludeDirectories = Dirs;
86 tgtok::TokKind Lex() {
87 return CurCode = LexToken();
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");
96 return CurStrVal;
98 int64_t getCurIntVal() const {
99 assert(CurCode == tgtok::IntVal && "This token isn't an integer");
100 return CurIntVal;
103 TGLoc getLoc() const;
105 void PrintError(const char *Loc, const std::string &Msg) const;
106 void PrintError(TGLoc Loc, const std::string &Msg) const;
108 private:
109 /// LexToken - Read the next token and return its code.
110 tgtok::TokKind LexToken();
112 tgtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
114 int getNextChar();
115 void SkipBCPLComment();
116 bool SkipCComment();
117 tgtok::TokKind LexIdentifier();
118 bool LexInclude();
119 tgtok::TokKind LexString();
120 tgtok::TokKind LexVarName();
121 tgtok::TokKind LexNumber();
122 tgtok::TokKind LexBracket();
123 tgtok::TokKind LexExclaim();
126 } // end namespace llvm
128 #endif