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/Support/DataTypes.h"
49 /// AsmLexer - Lexer class for assembly files.
54 const MemoryBuffer *CurBuf;
56 // Information about the current token.
58 asmtok::TokKind CurKind;
59 std::string CurStrVal; // This is valid for Identifier.
62 /// CurBuffer - This is the current buffer index we're lexing from as managed
63 /// by the SourceMgr object.
67 AsmLexer(SourceMgr &SrcMgr);
70 asmtok::TokKind Lex() {
71 return CurKind = LexToken();
74 asmtok::TokKind getKind() const { return CurKind; }
75 bool is(asmtok::TokKind K) const { return CurKind == K; }
76 bool isNot(asmtok::TokKind K) const { return CurKind != K; }
78 const std::string &getCurStrVal() const {
79 assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register ||
80 CurKind == asmtok::String) &&
81 "This token doesn't have a string value");
84 int64_t getCurIntVal() const {
85 assert(CurKind == asmtok::IntVal && "This token isn't an integer");
91 void PrintMessage(SMLoc Loc, const std::string &Msg) const;
95 asmtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
97 /// LexToken - Read the next token and return its code.
98 asmtok::TokKind LexToken();
99 asmtok::TokKind LexIdentifier();
100 asmtok::TokKind LexPercent();
101 asmtok::TokKind LexSlash();
102 asmtok::TokKind LexHash();
103 asmtok::TokKind LexDigit();
104 asmtok::TokKind LexQuote();
107 } // end namespace llvm