summaryrefslogtreecommitdiff
path: root/utils/TableGen/TGLexer.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-11-18 02:57:27 +0000
committerChris Lattner <sabre@nondot.org>2007-11-18 02:57:27 +0000
commita8058744229a44e80f90c8530bb7fe47cbab1b70 (patch)
treea06234bf6fcaa882d47d7eb597cec3a91b3e2c67 /utils/TableGen/TGLexer.h
parentb348d18caf834bc26a80e60aa7a2c9b1748734e8 (diff)
downloadllvm-a8058744229a44e80f90c8530bb7fe47cbab1b70.tar.gz
llvm-a8058744229a44e80f90c8530bb7fe47cbab1b70.tar.bz2
llvm-a8058744229a44e80f90c8530bb7fe47cbab1b70.tar.xz
reimplement the tblgen lexer with a simple hand-written lexer. This eliminates
one dependency on flex and gets rid of two ".cvs" files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44210 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/TGLexer.h')
-rw-r--r--utils/TableGen/TGLexer.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/utils/TableGen/TGLexer.h b/utils/TableGen/TGLexer.h
new file mode 100644
index 0000000000..517b81a496
--- /dev/null
+++ b/utils/TableGen/TGLexer.h
@@ -0,0 +1,74 @@
+//===- TGLexer.h - Lexer for TableGen Files ---------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This class represents the Lexer for tablegen files.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TGLEXER_H
+#define TGLEXER_H
+
+#include <vector>
+#include <string>
+#include <iosfwd>
+
+namespace llvm {
+class MemoryBuffer;
+
+class TGLexer {
+ const char *CurPtr;
+ unsigned CurLineNo;
+ MemoryBuffer *CurBuf;
+
+ /// IncludeRec / IncludeStack - This captures the current set of include
+ /// directives we are nested within.
+ struct IncludeRec {
+ MemoryBuffer *Buffer;
+ const char *CurPtr;
+ unsigned LineNo;
+ IncludeRec(MemoryBuffer *buffer, const char *curPtr, unsigned lineNo)
+ : Buffer(buffer), CurPtr(curPtr), LineNo(lineNo) {}
+ };
+ std::vector<IncludeRec> IncludeStack;
+
+ // IncludeDirectories - This is the list of directories we should search for
+ // include files in.
+ std::vector<std::string> IncludeDirectories;
+
+ std::string TheError;
+public:
+ TGLexer(MemoryBuffer *StartBuf);
+ ~TGLexer();
+
+ void setIncludeDirs(const std::vector<std::string> &Dirs) {
+ IncludeDirectories = Dirs;
+ }
+
+ int LexToken();
+
+ const std::string getError() const { return TheError; }
+
+ std::ostream &err();
+ void PrintIncludeStack(std::ostream &OS);
+private:
+ int getNextChar();
+ void SkipBCPLComment();
+ bool SkipCComment();
+ int LexIdentifier();
+ bool LexInclude();
+ int LexString();
+ int LexVarName();
+ int LexNumber();
+ int LexBracket();
+ int LexExclaim();
+};
+
+} // end namespace llvm
+
+#endif