blob: 905ff75ec9f86b148e24eaa297b703806c48909b [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;
Chris Lattnerff4bc462009-08-10 01:39:42 +000053
54 StringRef LexUntilEndOfStatement();
55
Daniel Dunbarcbbe2482009-07-28 17:58:44 +000056
Chris Lattner8e25e2d2009-07-16 06:14:39 +000057 /// EnterIncludeFile - Enter the specified file. This returns true on failure.
58 bool EnterIncludeFile(const std::string &Filename);
59
Daniel Dunbar3fb76832009-06-30 00:49:23 +000060 void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
Chris Lattnera59e8772009-06-21 07:19:10 +000061
62private:
63 int getNextChar();
Daniel Dunbarcb358b62009-07-28 03:00:54 +000064 AsmToken ReturnError(const char *Loc, const std::string &Msg);
Chris Lattnera59e8772009-06-21 07:19:10 +000065
Daniel Dunbarcb358b62009-07-28 03:00:54 +000066 AsmToken LexIdentifier();
67 AsmToken LexPercent();
68 AsmToken LexSlash();
69 AsmToken LexLineComment();
70 AsmToken LexDigit();
71 AsmToken LexQuote();
Chris Lattnera59e8772009-06-21 07:19:10 +000072};
73
74} // end namespace llvm
75
76#endif