1 //===- AsmLexer.h - Lexer for Assembly 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 declares the lexer for assembly files.
12 //===----------------------------------------------------------------------===//
17 #include "llvm/MC/MCAsmLexer.h"
18 #include "llvm/Support/DataTypes.h"
46 Star, Comma, Dollar, Equal, EqualEqual,
48 Pipe, PipePipe, Caret,
49 Amp, AmpAmp, Exclaim, ExclaimEqual, Percent,
50 Less, LessEqual, LessLess, LessGreater,
51 Greater, GreaterEqual, GreaterGreater
55 /// AsmLexer - Lexer class for assembly files.
56 class AsmLexer : public MCAsmLexer {
60 const MemoryBuffer *CurBuf;
61 // A llvm::StringSet<>, which provides uniqued and null-terminated strings.
64 // Information about the current token.
66 asmtok::TokKind CurKind;
67 const char *CurStrVal; // This is valid for Identifier.
70 /// CurBuffer - This is the current buffer index we're lexing from as managed
71 /// by the SourceMgr object.
74 void operator=(const AsmLexer&); // DO NOT IMPLEMENT
75 AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT
77 AsmLexer(SourceMgr &SrcMgr);
80 asmtok::TokKind Lex() {
81 return CurKind = LexToken();
84 asmtok::TokKind getKind() const { return CurKind; }
85 bool is(asmtok::TokKind K) const { return CurKind == K; }
86 bool isNot(asmtok::TokKind K) const { return CurKind != K; }
88 const char *getCurStrVal() const {
89 assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register ||
90 CurKind == asmtok::String) &&
91 "This token doesn't have a string value");
94 int64_t getCurIntVal() const {
95 assert(CurKind == asmtok::IntVal && "This token isn't an integer");
101 /// EnterIncludeFile - Enter the specified file. This returns true on failure.
102 bool EnterIncludeFile(const std::string &Filename);
104 void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
108 asmtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
110 /// LexToken - Read the next token and return its code.
111 asmtok::TokKind LexToken();
112 asmtok::TokKind LexIdentifier();
113 asmtok::TokKind LexPercent();
114 asmtok::TokKind LexSlash();
115 asmtok::TokKind LexLineComment();
116 asmtok::TokKind LexDigit();
117 asmtok::TokKind LexQuote();
120 } // end namespace llvm