#ifndef TGLEXER_H
#define TGLEXER_H
+#include "llvm/Support/DataTypes.h"
#include <vector>
#include <string>
#include <iosfwd>
namespace llvm {
class MemoryBuffer;
+class TGSourceMgr;
+class TGLoc;
namespace tgtok {
enum TokKind {
/// TGLexer - TableGen Lexer class.
class TGLexer {
+ TGSourceMgr &SrcMgr;
+
const char *CurPtr;
- unsigned CurLineNo;
- MemoryBuffer *CurBuf;
+ const MemoryBuffer *CurBuf;
// Information about the current token.
const char *TokStart;
tgtok::TokKind CurCode;
std::string CurStrVal; // This is valid for ID, STRVAL, VARNAME, CODEFRAGMENT
- int CurIntVal; // This is valid for INTVAL.
-
- /// 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;
+ int64_t CurIntVal; // This is valid for INTVAL.
+
+ /// CurBuffer - This is the current buffer index we're lexing from as managed
+ /// by the SourceMgr object.
+ int CurBuffer;
// IncludeDirectories - This is the list of directories we should search for
// include files in.
std::vector<std::string> IncludeDirectories;
public:
- TGLexer(MemoryBuffer *StartBuf);
- ~TGLexer();
+ TGLexer(TGSourceMgr &SrcMgr);
+ ~TGLexer() {}
void setIncludeDirs(const std::vector<std::string> &Dirs) {
IncludeDirectories = Dirs;
"This token doesn't have a string value");
return CurStrVal;
}
- int getCurIntVal() const {
+ int64_t getCurIntVal() const {
assert(CurCode == tgtok::IntVal && "This token isn't an integer");
return CurIntVal;
}
- typedef const char* LocTy;
- LocTy getLoc() const { return TokStart; }
+ TGLoc getLoc() const;
- void PrintError(LocTy Loc, const std::string &Msg) const;
-
- void PrintIncludeStack(std::ostream &OS) const;
+ void PrintError(const char *Loc, const std::string &Msg) const;
+ void PrintError(TGLoc Loc, const std::string &Msg) const;
private:
/// LexToken - Read the next token and return its code.