blob: 4200137f640afb1e59227aab5f2b4ddc7dfb9e98 [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
Daniel Dunbar9a7e2cc2009-07-27 21:49:56 +000017#include "llvm/ADT/StringRef.h"
Daniel Dunbardbd692a2009-07-20 20:01:54 +000018#include "llvm/MC/MCAsmLexer.h"
Chris Lattnera59e8772009-06-21 07:19:10 +000019#include "llvm/Support/DataTypes.h"
20#include <string>
21#include <cassert>
22
23namespace llvm {
24class MemoryBuffer;
25class SourceMgr;
26class SMLoc;
27
Chris Lattnera59e8772009-06-21 07:19:10 +000028/// AsmLexer - Lexer class for assembly files.
Daniel Dunbardbd692a2009-07-20 20:01:54 +000029class AsmLexer : public MCAsmLexer {
Chris Lattnera59e8772009-06-21 07:19:10 +000030 SourceMgr &SrcMgr;
31
32 const char *CurPtr;
33 const MemoryBuffer *CurBuf;
34
Chris Lattnera59e8772009-06-21 07:19:10 +000035 const char *TokStart;
Daniel Dunbarcb358b62009-07-28 03:00:54 +000036
Daniel Dunbarcb358b62009-07-28 03:00:54 +000037 /// This is the current buffer index we're lexing from as managed by the
38 /// SourceMgr object.
Chris Lattnera59e8772009-06-21 07:19:10 +000039 int CurBuffer;
40
Chris Lattnerfaf32c12009-06-24 00:33:19 +000041 void operator=(const AsmLexer&); // DO NOT IMPLEMENT
42 AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT
Daniel Dunbarcbbe2482009-07-28 17:58:44 +000043
44protected:
45 /// LexToken - Read the next token and return its code.
46 virtual AsmToken LexToken();
47
Chris Lattnera59e8772009-06-21 07:19:10 +000048public:
49 AsmLexer(SourceMgr &SrcMgr);
Chris Lattnerfaf32c12009-06-24 00:33:19 +000050 ~AsmLexer();
Chris Lattnera59e8772009-06-21 07:19:10 +000051
Chris Lattnera59e8772009-06-21 07:19:10 +000052 SMLoc getLoc() const;
Daniel Dunbarcbbe2482009-07-28 17:58:44 +000053
Chris Lattner8e25e2d2009-07-16 06:14:39 +000054 /// EnterIncludeFile - Enter the specified file. This returns true on failure.
55 bool EnterIncludeFile(const std::string &Filename);
56
Daniel Dunbar3fb76832009-06-30 00:49:23 +000057 void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
Chris Lattnera59e8772009-06-21 07:19:10 +000058
59private:
60 int getNextChar();
Daniel Dunbarcb358b62009-07-28 03:00:54 +000061 AsmToken ReturnError(const char *Loc, const std::string &Msg);
Chris Lattnera59e8772009-06-21 07:19:10 +000062
Daniel Dunbarcb358b62009-07-28 03:00:54 +000063 AsmToken LexIdentifier();
64 AsmToken LexPercent();
65 AsmToken LexSlash();
66 AsmToken LexLineComment();
67 AsmToken LexDigit();
68 AsmToken LexQuote();
Chris Lattnera59e8772009-06-21 07:19:10 +000069};
70
71} // end namespace llvm
72
73#endif