blob: 08e6f9c6eeb39adba0cf9f1e6a30ad647f461bcc [file] [log] [blame]
Chris Lattnera59e8772009-06-21 07:19:10 +00001//===- 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.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef ASMLEXER_H
15#define ASMLEXER_H
16
17#include "llvm/Support/DataTypes.h"
18#include <string>
19#include <cassert>
20
21namespace llvm {
22class MemoryBuffer;
23class SourceMgr;
24class SMLoc;
25
26namespace asmtok {
27 enum TokKind {
28 // Markers
29 Eof, Error,
30
31 Identifier,
32 IntVal,
33
34
35 Colon,
36 Plus,
37 Minus
38 };
39}
40
41/// AsmLexer - Lexer class for assembly files.
42class AsmLexer {
43 SourceMgr &SrcMgr;
44
45 const char *CurPtr;
46 const MemoryBuffer *CurBuf;
47
48 // Information about the current token.
49 const char *TokStart;
50 asmtok::TokKind CurKind;
51 std::string CurStrVal; // This is valid for Identifier.
52 int64_t CurIntVal;
53
54 /// CurBuffer - This is the current buffer index we're lexing from as managed
55 /// by the SourceMgr object.
56 int CurBuffer;
57
58public:
59 AsmLexer(SourceMgr &SrcMgr);
60 ~AsmLexer() {}
61
62 asmtok::TokKind Lex() {
63 return CurKind = LexToken();
64 }
65
66 asmtok::TokKind getKind() const { return CurKind; }
67
68 const std::string &getCurStrVal() const {
69 assert(CurKind == asmtok::Identifier &&
70 "This token doesn't have a string value");
71 return CurStrVal;
72 }
73 int64_t getCurIntVal() const {
74 assert(CurKind == asmtok::IntVal && "This token isn't an integer");
75 return CurIntVal;
76 }
77
78 SMLoc getLoc() const;
79
80 void PrintError(const char *Loc, const std::string &Msg) const;
81 void PrintError(SMLoc Loc, const std::string &Msg) const;
82
83private:
84 int getNextChar();
85
86 /// LexToken - Read the next token and return its code.
87 asmtok::TokKind LexToken();
88};
89
90} // end namespace llvm
91
92#endif