X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-mc%2FAsmLexer.h;h=ce292f66b127be5b2b051c2a10a743acb3499d60;hb=9e6d1d1f5034347d237941f1bf08fba5c1583cd3;hp=3bedc6e8e77f4c72190484e2afa5a721dd986859;hpb=419adedaa1638fbe4e078c997f81e94327ebff5a;p=oota-llvm.git diff --git a/tools/llvm-mc/AsmLexer.h b/tools/llvm-mc/AsmLexer.h index 3bedc6e8e77..ce292f66b12 100644 --- a/tools/llvm-mc/AsmLexer.h +++ b/tools/llvm-mc/AsmLexer.h @@ -16,7 +16,8 @@ #include "llvm/ADT/StringRef.h" #include "llvm/MC/MCAsmLexer.h" -#include "llvm/Support/DataTypes.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/System/DataTypes.h" #include #include @@ -24,105 +25,39 @@ namespace llvm { class MemoryBuffer; class SourceMgr; class SMLoc; - -/// AsmToken - Target independent representation for an assembler token. -struct AsmToken { - enum TokenKind { - // Markers - Eof, Error, - - // String values. - Identifier, - Register, - String, - - // Integer values. - Integer, - - // No-value. - EndOfStatement, - Colon, - Plus, Minus, Tilde, - Slash, // '/' - LParen, RParen, - Star, Comma, Dollar, Equal, EqualEqual, - - Pipe, PipePipe, Caret, - Amp, AmpAmp, Exclaim, ExclaimEqual, Percent, - Less, LessEqual, LessLess, LessGreater, - Greater, GreaterEqual, GreaterGreater - }; - - TokenKind Kind; - - /// A reference to the entire token contents; this is always a pointer into - /// a memory buffer owned by the source manager. - StringRef Str; - - int64_t IntVal; - -public: - AsmToken() {} - AsmToken(TokenKind _Kind, const StringRef &_Str, int64_t _IntVal = 0) - : Kind(_Kind), Str(_Str), IntVal(_IntVal) {} - - TokenKind getKind() const { return Kind; } - bool is(TokenKind K) const { return Kind == K; } - bool isNot(TokenKind K) const { return Kind != K; } - - SMLoc getLoc() const; - - /// getString - Get the string for the current token, this includes all - /// characters (for example, the quotes on strings) in the token. - /// - /// The returned StringRef points into the source manager's memory buffer, and - /// is safe to store across calls to Lex(). - StringRef getString() const { return Str; } - - // FIXME: Don't compute this in advance, it makes every token larger, and is - // also not generally what we want (it is nicer for recovery etc. to lex 123br - // as a single token, then diagnose as an invalid number). - int64_t getIntVal() const { - assert(Kind == Integer && "This token isn't an integer"); - return IntVal; - } -}; +class MCAsmInfo; /// AsmLexer - Lexer class for assembly files. class AsmLexer : public MCAsmLexer { SourceMgr &SrcMgr; + const MCAsmInfo &MAI; const char *CurPtr; const MemoryBuffer *CurBuf; const char *TokStart; - /// The current token. - AsmToken CurTok; - /// This is the current buffer index we're lexing from as managed by the /// SourceMgr object. int CurBuffer; void operator=(const AsmLexer&); // DO NOT IMPLEMENT AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT + +protected: + /// LexToken - Read the next token and return its code. + virtual AsmToken LexToken(); + public: - AsmLexer(SourceMgr &SrcMgr); + AsmLexer(SourceMgr &SrcMgr, const MCAsmInfo &MAI); ~AsmLexer(); - AsmToken::TokenKind Lex() { - return CurTok = LexToken(), getKind(); - } - - AsmToken::TokenKind getKind() const { return CurTok.getKind(); } - bool is(AsmToken::TokenKind K) const { return CurTok.is(K); } - bool isNot(AsmToken::TokenKind K) const { return CurTok.isNot(K); } - SMLoc getLoc() const; - /// getTok - Return a reference to the current (last) lexed token. - const AsmToken &getTok() const { return CurTok; } - + StringRef LexUntilEndOfStatement(); + + bool isAtStartOfComment(char Char); + /// EnterIncludeFile - Enter the specified file. This returns true on failure. bool EnterIncludeFile(const std::string &Filename); @@ -132,10 +67,7 @@ private: int getNextChar(); AsmToken ReturnError(const char *Loc, const std::string &Msg); - /// LexToken - Read the next token and return its code. - AsmToken LexToken(); AsmToken LexIdentifier(); - AsmToken LexPercent(); AsmToken LexSlash(); AsmToken LexLineComment(); AsmToken LexDigit();