blob: cc40d3516e96d1133ae0084c2b814277eb2c7e56 [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"
Kevin Enderby9823ca92009-09-04 21:45:34 +000019#include "llvm/MC/MCAsmInfo.h"
Chandler Carruth8b67f772009-10-26 01:35:46 +000020#include "llvm/System/DataTypes.h"
Chris Lattnera59e8772009-06-21 07:19:10 +000021#include <string>
22#include <cassert>
23
24namespace llvm {
25class MemoryBuffer;
26class SourceMgr;
27class SMLoc;
Kevin Enderby9823ca92009-09-04 21:45:34 +000028class MCAsmInfo;
Chris Lattnera59e8772009-06-21 07:19:10 +000029
Chris Lattnera59e8772009-06-21 07:19:10 +000030/// AsmLexer - Lexer class for assembly files.
Daniel Dunbardbd692a2009-07-20 20:01:54 +000031class AsmLexer : public MCAsmLexer {
Chris Lattnera59e8772009-06-21 07:19:10 +000032 SourceMgr &SrcMgr;
Chris Lattnercec54502009-09-27 19:38:39 +000033 const MCAsmInfo &MAI;
Chris Lattnera59e8772009-06-21 07:19:10 +000034
35 const char *CurPtr;
36 const MemoryBuffer *CurBuf;
37
Chris Lattnera59e8772009-06-21 07:19:10 +000038 const char *TokStart;
Daniel Dunbarcb358b62009-07-28 03:00:54 +000039
Daniel Dunbarcb358b62009-07-28 03:00:54 +000040 /// This is the current buffer index we're lexing from as managed by the
41 /// SourceMgr object.
Chris Lattnera59e8772009-06-21 07:19:10 +000042 int CurBuffer;
43
Chris Lattnerfaf32c12009-06-24 00:33:19 +000044 void operator=(const AsmLexer&); // DO NOT IMPLEMENT
45 AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT
Daniel Dunbarcbbe2482009-07-28 17:58:44 +000046
47protected:
48 /// LexToken - Read the next token and return its code.
49 virtual AsmToken LexToken();
50
Chris Lattnera59e8772009-06-21 07:19:10 +000051public:
Kevin Enderby9823ca92009-09-04 21:45:34 +000052 AsmLexer(SourceMgr &SrcMgr, const MCAsmInfo &MAI);
Chris Lattnerfaf32c12009-06-24 00:33:19 +000053 ~AsmLexer();
Chris Lattnera59e8772009-06-21 07:19:10 +000054
Chris Lattnera59e8772009-06-21 07:19:10 +000055 SMLoc getLoc() const;
Chris Lattnerff4bc462009-08-10 01:39:42 +000056
57 StringRef LexUntilEndOfStatement();
Kevin Enderbyb5db8302009-09-16 18:08:00 +000058
59 bool isAtStartOfComment(char Char);
Daniel Dunbarcbbe2482009-07-28 17:58:44 +000060
Chris Lattner8e25e2d2009-07-16 06:14:39 +000061 /// EnterIncludeFile - Enter the specified file. This returns true on failure.
62 bool EnterIncludeFile(const std::string &Filename);
63
Chris Lattner258281d2010-01-19 06:22:22 +000064 const MCAsmInfo &getMAI() const { return MAI; }
65
Chris Lattnera59e8772009-06-21 07:19:10 +000066private:
67 int getNextChar();
Daniel Dunbarcb358b62009-07-28 03:00:54 +000068 AsmToken ReturnError(const char *Loc, const std::string &Msg);
Chris Lattnera59e8772009-06-21 07:19:10 +000069
Daniel Dunbarcb358b62009-07-28 03:00:54 +000070 AsmToken LexIdentifier();
Daniel Dunbarcb358b62009-07-28 03:00:54 +000071 AsmToken LexSlash();
72 AsmToken LexLineComment();
73 AsmToken LexDigit();
74 AsmToken LexQuote();
Chris Lattnera59e8772009-06-21 07:19:10 +000075};
76
77} // end namespace llvm
78
79#endif