1193323Sed//===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This class represents the Lexer for .ll files. 11193323Sed// 12193323Sed//===----------------------------------------------------------------------===// 13193323Sed 14193323Sed#ifndef LIB_ASMPARSER_LLLEXER_H 15193323Sed#define LIB_ASMPARSER_LLLEXER_H 16193323Sed 17193323Sed#include "LLToken.h" 18249423Sdim#include "llvm/ADT/APFloat.h" 19193323Sed#include "llvm/ADT/APSInt.h" 20195340Sed#include "llvm/Support/SourceMgr.h" 21193323Sed#include <string> 22193323Sed 23193323Sednamespace llvm { 24193323Sed class MemoryBuffer; 25193323Sed class Type; 26195340Sed class SMDiagnostic; 27198090Srdivacky class LLVMContext; 28193323Sed 29193323Sed class LLLexer { 30193323Sed const char *CurPtr; 31193323Sed MemoryBuffer *CurBuf; 32195340Sed SMDiagnostic &ErrorInfo; 33195340Sed SourceMgr &SM; 34198090Srdivacky LLVMContext &Context; 35193323Sed 36193323Sed // Information about the current token. 37193323Sed const char *TokStart; 38193323Sed lltok::Kind CurKind; 39193323Sed std::string StrVal; 40193323Sed unsigned UIntVal; 41224145Sdim Type *TyVal; 42193323Sed APFloat APFloatVal; 43193323Sed APSInt APSIntVal; 44193323Sed 45193323Sed public: 46198090Srdivacky explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &, 47198090Srdivacky LLVMContext &C); 48193323Sed ~LLLexer() {} 49193323Sed 50193323Sed lltok::Kind Lex() { 51193323Sed return CurKind = LexToken(); 52193323Sed } 53193323Sed 54195340Sed typedef SMLoc LocTy; 55195340Sed LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); } 56193323Sed lltok::Kind getKind() const { return CurKind; } 57206083Srdivacky const std::string &getStrVal() const { return StrVal; } 58224145Sdim Type *getTyVal() const { return TyVal; } 59193323Sed unsigned getUIntVal() const { return UIntVal; } 60193323Sed const APSInt &getAPSIntVal() const { return APSIntVal; } 61193323Sed const APFloat &getAPFloatVal() const { return APFloatVal; } 62193323Sed 63193323Sed 64218893Sdim bool Error(LocTy L, const Twine &Msg) const; 65218893Sdim bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); } 66193323Sed std::string getFilename() const; 67193323Sed 68193323Sed private: 69193323Sed lltok::Kind LexToken(); 70193323Sed 71193323Sed int getNextChar(); 72193323Sed void SkipLineComment(); 73223017Sdim lltok::Kind ReadString(lltok::Kind kind); 74223017Sdim bool ReadVarName(); 75223017Sdim 76193323Sed lltok::Kind LexIdentifier(); 77193323Sed lltok::Kind LexDigitOrNegative(); 78193323Sed lltok::Kind LexPositive(); 79193323Sed lltok::Kind LexAt(); 80201360Srdivacky lltok::Kind LexExclaim(); 81193323Sed lltok::Kind LexPercent(); 82193323Sed lltok::Kind LexQuote(); 83193323Sed lltok::Kind Lex0x(); 84249423Sdim lltok::Kind LexHash(); 85193323Sed 86193323Sed uint64_t atoull(const char *Buffer, const char *End); 87193323Sed uint64_t HexIntToVal(const char *Buffer, const char *End); 88193323Sed void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]); 89193323Sed void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]); 90193323Sed }; 91193323Sed} // end namespace llvm 92193323Sed 93193323Sed#endif 94