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 <string>
00021 
00022 namespace llvm {
00023   class MemoryBuffer;
00024   class Type;
00025   class ParseError;
00026 
00027   class LLLexer {
00028     const char *CurPtr;
00029     MemoryBuffer *CurBuf;
00030     ParseError &ErrorInfo;
00031 
00032     // Information about the current token.
00033     const char *TokStart;
00034     lltok::Kind CurKind;
00035     std::string StrVal;
00036     unsigned UIntVal;
00037     const Type *TyVal;
00038     APFloat APFloatVal;
00039     APSInt  APSIntVal;
00040 
00041     std::string TheError;
00042   public:
00043     explicit LLLexer(MemoryBuffer *StartBuf, ParseError &);
00044     ~LLLexer() {}
00045 
00046     lltok::Kind Lex() {
00047       return CurKind = LexToken();
00048     }
00049 
00050     typedef const char* LocTy;
00051     LocTy getLoc() const { return TokStart; }
00052     lltok::Kind getKind() const { return CurKind; }
00053     const std::string getStrVal() const { return StrVal; }
00054     const Type *getTyVal() const { return TyVal; }
00055     unsigned getUIntVal() const { return UIntVal; }
00056     const APSInt &getAPSIntVal() const { return APSIntVal; }
00057     const APFloat &getAPFloatVal() const { return APFloatVal; }
00058 
00059 
00060     bool Error(LocTy L, const std::string &Msg) const;
00061     bool Error(const std::string &Msg) const { return Error(CurPtr, Msg); }
00062     std::string getFilename() const;
00063 
00064   private:
00065     lltok::Kind LexToken();
00066 
00067     int getNextChar();
00068     void SkipLineComment();
00069     lltok::Kind LexIdentifier();
00070     lltok::Kind LexDigitOrNegative();
00071     lltok::Kind LexPositive();
00072     lltok::Kind LexAt();
00073     lltok::Kind LexPercent();
00074     lltok::Kind LexQuote();
00075     lltok::Kind Lex0x();
00076 
00077     uint64_t atoull(const char *Buffer, const char *End);
00078     uint64_t HexIntToVal(const char *Buffer, const char *End);
00079     void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
00080   };
00081 } // end namespace llvm
00082 
00083 #endif