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 /// AsmToken - Target independent representation for an assembler token.
60 /// A reference to the entire token contents; this is always a pointer into
61 /// a memory buffer owned by the source manager.
68 AsmToken(asmtok::TokKind _Kind, const StringRef &_Str, int64_t _IntVal = 0)
69 : Kind(_Kind), Str(_Str), IntVal(_IntVal) {}
71 asmtok::TokKind getKind() const { return Kind; }
72 bool is(asmtok::TokKind K) const { return Kind == K; }
73 bool isNot(asmtok::TokKind K) const { return Kind != K; }
77 StringRef getString() const { return Str; }
79 int64_t getIntVal() const {
80 assert(Kind == asmtok::IntVal && "This token isn't an integer");
85 /// AsmLexer - Lexer class for assembly files.
86 class AsmLexer : public MCAsmLexer {
90 const MemoryBuffer *CurBuf;
94 /// The current token.
97 /// This is the current buffer index we're lexing from as managed by the
101 void operator=(const AsmLexer&); // DO NOT IMPLEMENT
102 AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT
104 AsmLexer(SourceMgr &SrcMgr);
107 asmtok::TokKind Lex() {
108 return CurTok = LexToken(), getKind();
111 asmtok::TokKind getKind() const { return CurTok.getKind(); }
112 bool is(asmtok::TokKind K) const { return CurTok.is(K); }
113 bool isNot(asmtok::TokKind K) const { return CurTok.isNot(K); }
115 /// getCurStrVal - Get the string for the current token, this includes all
116 /// characters (for example, the quotes on strings) in the token.
118 /// The returned StringRef points into the source manager's memory buffer, and
119 /// is safe to store across calls to Lex().
120 StringRef getCurStrVal() const {
121 return CurTok.getString();
123 int64_t getCurIntVal() const {
124 return CurTok.getIntVal();
127 SMLoc getLoc() const;
129 /// EnterIncludeFile - Enter the specified file. This returns true on failure.
130 bool EnterIncludeFile(const std::string &Filename);
132 void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
136 AsmToken ReturnError(const char *Loc, const std::string &Msg);
138 /// LexToken - Read the next token and return its code.
140 AsmToken LexIdentifier();
141 AsmToken LexPercent();
143 AsmToken LexLineComment();
148 } // end namespace llvm