1f4a2713aSLionel Sambuc //===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10f4a2713aSLionel Sambuc // This class represents the Lexer for .ll files. 11f4a2713aSLionel Sambuc // 12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13f4a2713aSLionel Sambuc 14*0a6a1f1dSLionel Sambuc #ifndef LLVM_LIB_ASMPARSER_LLLEXER_H 15*0a6a1f1dSLionel Sambuc #define LLVM_LIB_ASMPARSER_LLLEXER_H 16f4a2713aSLionel Sambuc 17f4a2713aSLionel Sambuc #include "LLToken.h" 18f4a2713aSLionel Sambuc #include "llvm/ADT/APFloat.h" 19f4a2713aSLionel Sambuc #include "llvm/ADT/APSInt.h" 20f4a2713aSLionel Sambuc #include "llvm/Support/SourceMgr.h" 21f4a2713aSLionel Sambuc #include <string> 22f4a2713aSLionel Sambuc 23f4a2713aSLionel Sambuc namespace llvm { 24f4a2713aSLionel Sambuc class MemoryBuffer; 25f4a2713aSLionel Sambuc class Type; 26f4a2713aSLionel Sambuc class SMDiagnostic; 27f4a2713aSLionel Sambuc class LLVMContext; 28f4a2713aSLionel Sambuc 29f4a2713aSLionel Sambuc class LLLexer { 30f4a2713aSLionel Sambuc const char *CurPtr; 31*0a6a1f1dSLionel Sambuc StringRef CurBuf; 32f4a2713aSLionel Sambuc SMDiagnostic &ErrorInfo; 33f4a2713aSLionel Sambuc SourceMgr &SM; 34f4a2713aSLionel Sambuc LLVMContext &Context; 35f4a2713aSLionel Sambuc 36f4a2713aSLionel Sambuc // Information about the current token. 37f4a2713aSLionel Sambuc const char *TokStart; 38f4a2713aSLionel Sambuc lltok::Kind CurKind; 39f4a2713aSLionel Sambuc std::string StrVal; 40f4a2713aSLionel Sambuc unsigned UIntVal; 41f4a2713aSLionel Sambuc Type *TyVal; 42f4a2713aSLionel Sambuc APFloat APFloatVal; 43f4a2713aSLionel Sambuc APSInt APSIntVal; 44f4a2713aSLionel Sambuc 45f4a2713aSLionel Sambuc public: 46*0a6a1f1dSLionel Sambuc explicit LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &, 47f4a2713aSLionel Sambuc LLVMContext &C); ~LLLexer()48f4a2713aSLionel Sambuc ~LLLexer() {} 49f4a2713aSLionel Sambuc Lex()50f4a2713aSLionel Sambuc lltok::Kind Lex() { 51f4a2713aSLionel Sambuc return CurKind = LexToken(); 52f4a2713aSLionel Sambuc } 53f4a2713aSLionel Sambuc 54f4a2713aSLionel Sambuc typedef SMLoc LocTy; getLoc()55f4a2713aSLionel Sambuc LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); } getKind()56f4a2713aSLionel Sambuc lltok::Kind getKind() const { return CurKind; } getStrVal()57f4a2713aSLionel Sambuc const std::string &getStrVal() const { return StrVal; } getTyVal()58f4a2713aSLionel Sambuc Type *getTyVal() const { return TyVal; } getUIntVal()59f4a2713aSLionel Sambuc unsigned getUIntVal() const { return UIntVal; } getAPSIntVal()60f4a2713aSLionel Sambuc const APSInt &getAPSIntVal() const { return APSIntVal; } getAPFloatVal()61f4a2713aSLionel Sambuc const APFloat &getAPFloatVal() const { return APFloatVal; } 62f4a2713aSLionel Sambuc 63f4a2713aSLionel Sambuc 64f4a2713aSLionel Sambuc bool Error(LocTy L, const Twine &Msg) const; Error(const Twine & Msg)65f4a2713aSLionel Sambuc bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); } 66*0a6a1f1dSLionel Sambuc 67*0a6a1f1dSLionel Sambuc void Warning(LocTy WarningLoc, const Twine &Msg) const; Warning(const Twine & Msg)68*0a6a1f1dSLionel Sambuc void Warning(const Twine &Msg) const { return Warning(getLoc(), Msg); } 69f4a2713aSLionel Sambuc 70f4a2713aSLionel Sambuc private: 71f4a2713aSLionel Sambuc lltok::Kind LexToken(); 72f4a2713aSLionel Sambuc 73f4a2713aSLionel Sambuc int getNextChar(); 74f4a2713aSLionel Sambuc void SkipLineComment(); 75f4a2713aSLionel Sambuc lltok::Kind ReadString(lltok::Kind kind); 76f4a2713aSLionel Sambuc bool ReadVarName(); 77f4a2713aSLionel Sambuc 78f4a2713aSLionel Sambuc lltok::Kind LexIdentifier(); 79f4a2713aSLionel Sambuc lltok::Kind LexDigitOrNegative(); 80f4a2713aSLionel Sambuc lltok::Kind LexPositive(); 81f4a2713aSLionel Sambuc lltok::Kind LexAt(); 82*0a6a1f1dSLionel Sambuc lltok::Kind LexDollar(); 83f4a2713aSLionel Sambuc lltok::Kind LexExclaim(); 84f4a2713aSLionel Sambuc lltok::Kind LexPercent(); 85*0a6a1f1dSLionel Sambuc lltok::Kind LexVar(lltok::Kind Var, lltok::Kind VarID); 86f4a2713aSLionel Sambuc lltok::Kind LexQuote(); 87f4a2713aSLionel Sambuc lltok::Kind Lex0x(); 88f4a2713aSLionel Sambuc lltok::Kind LexHash(); 89f4a2713aSLionel Sambuc 90f4a2713aSLionel Sambuc uint64_t atoull(const char *Buffer, const char *End); 91f4a2713aSLionel Sambuc uint64_t HexIntToVal(const char *Buffer, const char *End); 92f4a2713aSLionel Sambuc void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]); 93f4a2713aSLionel Sambuc void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]); 94f4a2713aSLionel Sambuc }; 95f4a2713aSLionel Sambuc } // end namespace llvm 96f4a2713aSLionel Sambuc 97f4a2713aSLionel Sambuc #endif 98