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