1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This class represents the Lexer for .ll files. 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LIB_ASMPARSER_LLLEXER_H 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LIB_ASMPARSER_LLLEXER_H 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "LLToken.h" 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/ADT/APSInt.h" 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/ADT/APFloat.h" 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/SourceMgr.h" 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include <string> 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm { 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class MemoryBuffer; 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class Type; 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class SMDiagnostic; 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class LLVMContext; 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class LLLexer { 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const char *CurPtr; 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman MemoryBuffer *CurBuf; 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman SMDiagnostic &ErrorInfo; 33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman SourceMgr &SM; 34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman LLVMContext &Context; 35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Information about the current token. 37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const char *TokStart; 38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind CurKind; 39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman std::string StrVal; 40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman unsigned UIntVal; 4119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Type *TyVal; 42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APFloat APFloatVal; 43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt APSIntVal; 44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman std::string TheError; 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public: 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &, 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman LLVMContext &C); 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ~LLLexer() {} 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind Lex() { 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return CurKind = LexToken(); 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman typedef SMLoc LocTy; 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); } 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind getKind() const { return CurKind; } 58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const std::string &getStrVal() const { return StrVal; } 5919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Type *getTyVal() const { return TyVal; } 60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman unsigned getUIntVal() const { return UIntVal; } 61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const APSInt &getAPSIntVal() const { return APSIntVal; } 62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const APFloat &getAPFloatVal() const { return APFloatVal; } 63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 6519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool Error(LocTy L, const Twine &Msg) const; 6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); } 67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman std::string getFilename() const; 68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman private: 70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind LexToken(); 71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman int getNextChar(); 73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void SkipLineComment(); 7419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman lltok::Kind ReadString(lltok::Kind kind); 7519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool ReadVarName(); 7619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind LexIdentifier(); 78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind LexDigitOrNegative(); 79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind LexPositive(); 80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind LexAt(); 81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind LexExclaim(); 82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind LexPercent(); 83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind LexQuote(); 84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman lltok::Kind Lex0x(); 85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman uint64_t atoull(const char *Buffer, const char *End); 87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman uint64_t HexIntToVal(const char *Buffer, const char *End); 88894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]); 89894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]); 90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // end namespace llvm 92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif 94