LLVM API Documentation
00001 //===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This class represents the Lexer for .ll files. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_LIB_ASMPARSER_LLLEXER_H 00015 #define LLVM_LIB_ASMPARSER_LLLEXER_H 00016 00017 #include "LLToken.h" 00018 #include "llvm/ADT/APFloat.h" 00019 #include "llvm/ADT/APSInt.h" 00020 #include "llvm/Support/SourceMgr.h" 00021 #include <string> 00022 00023 namespace llvm { 00024 class MemoryBuffer; 00025 class Type; 00026 class SMDiagnostic; 00027 class LLVMContext; 00028 00029 class LLLexer { 00030 const char *CurPtr; 00031 StringRef CurBuf; 00032 SMDiagnostic &ErrorInfo; 00033 SourceMgr &SM; 00034 LLVMContext &Context; 00035 00036 // Information about the current token. 00037 const char *TokStart; 00038 lltok::Kind CurKind; 00039 std::string StrVal; 00040 unsigned UIntVal; 00041 Type *TyVal; 00042 APFloat APFloatVal; 00043 APSInt APSIntVal; 00044 00045 public: 00046 explicit LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &, 00047 LLVMContext &C); 00048 ~LLLexer() {} 00049 00050 lltok::Kind Lex() { 00051 return CurKind = LexToken(); 00052 } 00053 00054 typedef SMLoc LocTy; 00055 LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); } 00056 lltok::Kind getKind() const { return CurKind; } 00057 const std::string &getStrVal() const { return StrVal; } 00058 Type *getTyVal() const { return TyVal; } 00059 unsigned getUIntVal() const { return UIntVal; } 00060 const APSInt &getAPSIntVal() const { return APSIntVal; } 00061 const APFloat &getAPFloatVal() const { return APFloatVal; } 00062 00063 00064 bool Error(LocTy L, const Twine &Msg) const; 00065 bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); } 00066 00067 void Warning(LocTy WarningLoc, const Twine &Msg) const; 00068 void Warning(const Twine &Msg) const { return Warning(getLoc(), Msg); } 00069 00070 private: 00071 lltok::Kind LexToken(); 00072 00073 int getNextChar(); 00074 void SkipLineComment(); 00075 lltok::Kind ReadString(lltok::Kind kind); 00076 bool ReadVarName(); 00077 00078 lltok::Kind LexIdentifier(); 00079 lltok::Kind LexDigitOrNegative(); 00080 lltok::Kind LexPositive(); 00081 lltok::Kind LexAt(); 00082 lltok::Kind LexDollar(); 00083 lltok::Kind LexExclaim(); 00084 lltok::Kind LexPercent(); 00085 lltok::Kind LexQuote(); 00086 lltok::Kind Lex0x(); 00087 lltok::Kind LexHash(); 00088 00089 uint64_t atoull(const char *Buffer, const char *End); 00090 uint64_t HexIntToVal(const char *Buffer, const char *End); 00091 void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]); 00092 void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]); 00093 }; 00094 } // end namespace llvm 00095 00096 #endif