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/ADT/StringRef.h"
18 #include "llvm/MC/MCAsmLexer.h"
19 #include "llvm/Support/DataTypes.h"
47 Star, Comma, Dollar, Equal, EqualEqual,
49 Pipe, PipePipe, Caret,
50 Amp, AmpAmp, Exclaim, ExclaimEqual, Percent,
51 Less, LessEqual, LessLess, LessGreater,
52 Greater, GreaterEqual, GreaterGreater
56 /// AsmLexer - Lexer class for assembly files.
57 class AsmLexer : public MCAsmLexer {
61 const MemoryBuffer *CurBuf;
62 // A llvm::StringSet<>, which provides uniqued and null-terminated strings.
65 // Information about the current token.
67 asmtok::TokKind CurKind;
68 const char *CurStrVal; // This is valid for Identifier.
71 /// CurBuffer - This is the current buffer index we're lexing from as managed
72 /// by the SourceMgr object.
75 void operator=(const AsmLexer&); // DO NOT IMPLEMENT
76 AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT
78 AsmLexer(SourceMgr &SrcMgr);
81 asmtok::TokKind Lex() {
82 return CurKind = LexToken();
85 asmtok::TokKind getKind() const { return CurKind; }
86 bool is(asmtok::TokKind K) const { return CurKind == K; }
87 bool isNot(asmtok::TokKind K) const { return CurKind != K; }
89 /// getCurStrVal - Get the string for the current token, this includes all
90 /// characters (for example, the quotes on strings) in the token.
92 /// The returned StringRef points into the source manager's memory buffer, and
93 /// is safe to store across calls to Lex().
94 StringRef getCurStrVal() const {
95 assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register ||
96 CurKind == asmtok::String) &&
97 "This token doesn't have a string value");
100 int64_t getCurIntVal() const {
101 assert(CurKind == asmtok::IntVal && "This token isn't an integer");
105 SMLoc getLoc() const;
107 /// EnterIncludeFile - Enter the specified file. This returns true on failure.
108 bool EnterIncludeFile(const std::string &Filename);
110 void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
114 asmtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
116 /// LexToken - Read the next token and return its code.
117 asmtok::TokKind LexToken();
118 asmtok::TokKind LexIdentifier();
119 asmtok::TokKind LexPercent();
120 asmtok::TokKind LexSlash();
121 asmtok::TokKind LexLineComment();
122 asmtok::TokKind LexDigit();
123 asmtok::TokKind LexQuote();
126 } // end namespace llvm