Merge branch 'master' into systemz
[llvm/systemz.git] / tools / llvm-mc / AsmLexer.h
blob5d59d0ad7751365ca66665a6f7d360699989653f
1 //===- AsmLexer.h - Lexer for Assembly Files --------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class declares the lexer for assembly files.
12 //===----------------------------------------------------------------------===//
14 #ifndef ASMLEXER_H
15 #define ASMLEXER_H
17 #include "llvm/Support/DataTypes.h"
18 #include <string>
19 #include <cassert>
21 namespace llvm {
22 class MemoryBuffer;
23 class SourceMgr;
24 class SMLoc;
26 namespace asmtok {
27 enum TokKind {
28 // Markers
29 Eof, Error,
31 // String values.
32 Identifier,
33 Register,
34 String,
36 // Integer values.
37 IntVal,
39 // No-value.
40 EndOfStatement,
41 Colon,
42 Plus, Minus, Tilde,
43 Slash, // '/'
44 LParen, RParen,
45 Star, Comma, Dollar, Equal, EqualEqual,
47 Pipe, PipePipe, Caret,
48 Amp, AmpAmp, Exclaim, ExclaimEqual, Percent,
49 Less, LessEqual, LessLess, LessGreater,
50 Greater, GreaterEqual, GreaterGreater
54 /// AsmLexer - Lexer class for assembly files.
55 class AsmLexer {
56 SourceMgr &SrcMgr;
58 const char *CurPtr;
59 const MemoryBuffer *CurBuf;
60 // A llvm::StringSet<>, which provides uniqued and null-terminated strings.
61 void *TheStringSet;
63 // Information about the current token.
64 const char *TokStart;
65 asmtok::TokKind CurKind;
66 const char *CurStrVal; // This is valid for Identifier.
67 int64_t CurIntVal;
69 /// CurBuffer - This is the current buffer index we're lexing from as managed
70 /// by the SourceMgr object.
71 int CurBuffer;
73 void operator=(const AsmLexer&); // DO NOT IMPLEMENT
74 AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT
75 public:
76 AsmLexer(SourceMgr &SrcMgr);
77 ~AsmLexer();
79 asmtok::TokKind Lex() {
80 return CurKind = LexToken();
83 asmtok::TokKind getKind() const { return CurKind; }
84 bool is(asmtok::TokKind K) const { return CurKind == K; }
85 bool isNot(asmtok::TokKind K) const { return CurKind != K; }
87 const char *getCurStrVal() const {
88 assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register ||
89 CurKind == asmtok::String) &&
90 "This token doesn't have a string value");
91 return CurStrVal;
93 int64_t getCurIntVal() const {
94 assert(CurKind == asmtok::IntVal && "This token isn't an integer");
95 return CurIntVal;
98 SMLoc getLoc() const;
100 /// EnterIncludeFile - Enter the specified file. This returns true on failure.
101 bool EnterIncludeFile(const std::string &Filename);
103 void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
105 private:
106 int getNextChar();
107 asmtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
109 /// LexToken - Read the next token and return its code.
110 asmtok::TokKind LexToken();
111 asmtok::TokKind LexIdentifier();
112 asmtok::TokKind LexPercent();
113 asmtok::TokKind LexSlash();
114 asmtok::TokKind LexLineComment();
115 asmtok::TokKind LexDigit();
116 asmtok::TokKind LexQuote();
119 } // end namespace llvm
121 #endif