LLVM API Documentation

LLLexer.h

Go to the documentation of this file.
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 LIB_ASMPARSER_LLLEXER_H
00015 #define LIB_ASMPARSER_LLLEXER_H
00016 
00017 #include "LLToken.h"
00018 #include "llvm/ADT/APSInt.h"
00019 #include "llvm/ADT/APFloat.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     MemoryBuffer *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     const Type *TyVal;
00042     APFloat APFloatVal;
00043     APSInt  APSIntVal;
00044 
00045     std::string TheError;
00046   public:
00047     explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &,
00048                      LLVMContext &C);
00049     ~LLLexer() {}
00050 
00051     lltok::Kind Lex() {
00052       return CurKind = LexToken();
00053     }
00054 
00055     typedef SMLoc LocTy;
00056     LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
00057     lltok::Kind getKind() const { return CurKind; }
00058     const std::string getStrVal() const { return StrVal; }
00059     const Type *getTyVal() const { return TyVal; }
00060     unsigned getUIntVal() const { return UIntVal; }
00061     const APSInt &getAPSIntVal() const { return APSIntVal; }
00062     const APFloat &getAPFloatVal() const { return APFloatVal; }
00063 
00064 
00065     bool Error(LocTy L, const std::string &Msg) const;
00066     bool Error(const std::string &Msg) const { return Error(getLoc(), Msg); }
00067     std::string getFilename() const;
00068 
00069   private:
00070     lltok::Kind LexToken();
00071 
00072     int getNextChar();
00073     void SkipLineComment();
00074     lltok::Kind LexIdentifier();
00075     lltok::Kind LexDigitOrNegative();
00076     lltok::Kind LexPositive();
00077     lltok::Kind LexAt();
00078     lltok::Kind LexMetadata();
00079     lltok::Kind LexPercent();
00080     lltok::Kind LexQuote();
00081     lltok::Kind Lex0x();
00082 
00083     uint64_t atoull(const char *Buffer, const char *End);
00084     uint64_t HexIntToVal(const char *Buffer, const char *End);
00085     void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
00086     void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
00087   };
00088 } // end namespace llvm
00089 
00090 #endif