blob: 5e9843ccec85b884f6d816deb94ff0d2999eb5f8 [file] [log] [blame]
Chris Lattner17e73c22007-11-18 08:46:26 +00001//===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner17e73c22007-11-18 08:46:26 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This class represents the Lexer for .ll files.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LIB_ASMPARSER_LLLEXER_H
15#define LIB_ASMPARSER_LLLEXER_H
16
Chris Lattner103ff152009-01-02 07:01:27 +000017#include "LLToken.h"
18#include "llvm/ADT/APSInt.h"
19#include "llvm/ADT/APFloat.h"
Chris Lattner17e73c22007-11-18 08:46:26 +000020#include <iosfwd>
Misha Brukmanf03e2eb2009-01-02 22:49:28 +000021#include <string>
22#include <vector>
Chris Lattner17e73c22007-11-18 08:46:26 +000023
24namespace llvm {
25 class MemoryBuffer;
Chris Lattner103ff152009-01-02 07:01:27 +000026 class Type;
27 class ParseError;
Misha Brukman7d987212009-01-02 22:46:48 +000028
Chris Lattner17e73c22007-11-18 08:46:26 +000029 class LLLexer {
30 const char *CurPtr;
Chris Lattner17e73c22007-11-18 08:46:26 +000031 MemoryBuffer *CurBuf;
Chris Lattner103ff152009-01-02 07:01:27 +000032 ParseError &ErrorInfo;
33
34 // Information about the current token.
Chris Lattner17e73c22007-11-18 08:46:26 +000035 const char *TokStart;
Chris Lattner103ff152009-01-02 07:01:27 +000036 lltok::Kind CurKind;
37 std::string StrVal;
38 unsigned UIntVal;
39 const Type *TyVal;
40 APFloat APFloatVal;
41 APSInt APSIntVal;
Misha Brukman7d987212009-01-02 22:46:48 +000042
Chris Lattner17e73c22007-11-18 08:46:26 +000043 std::string TheError;
44 public:
Chris Lattner103ff152009-01-02 07:01:27 +000045 explicit LLLexer(MemoryBuffer *StartBuf, ParseError &);
Chris Lattner17e73c22007-11-18 08:46:26 +000046 ~LLLexer() {}
47
Chris Lattner103ff152009-01-02 07:01:27 +000048 lltok::Kind Lex() {
49 return CurKind = LexToken();
50 }
51
52 typedef const char* LocTy;
53 LocTy getLoc() const { return TokStart; }
54 lltok::Kind getKind() const { return CurKind; }
55 const std::string getStrVal() const { return StrVal; }
56 const Type *getTyVal() const { return TyVal; }
57 unsigned getUIntVal() const { return UIntVal; }
58 const APSInt &getAPSIntVal() const { return APSIntVal; }
59 const APFloat &getAPFloatVal() const { return APFloatVal; }
60
Misha Brukman7d987212009-01-02 22:46:48 +000061
Chris Lattner103ff152009-01-02 07:01:27 +000062 bool Error(LocTy L, const std::string &Msg) const;
63 bool Error(const std::string &Msg) const { return Error(CurPtr, Msg); }
Chris Lattner17e73c22007-11-18 08:46:26 +000064 std::string getFilename() const;
Misha Brukman7d987212009-01-02 22:46:48 +000065
Chris Lattner17e73c22007-11-18 08:46:26 +000066 private:
Chris Lattner103ff152009-01-02 07:01:27 +000067 lltok::Kind LexToken();
68
Chris Lattner17e73c22007-11-18 08:46:26 +000069 int getNextChar();
70 void SkipLineComment();
Chris Lattner103ff152009-01-02 07:01:27 +000071 lltok::Kind LexIdentifier();
72 lltok::Kind LexDigitOrNegative();
73 lltok::Kind LexPositive();
74 lltok::Kind LexAt();
75 lltok::Kind LexPercent();
76 lltok::Kind LexQuote();
77 lltok::Kind Lex0x();
Misha Brukman7d987212009-01-02 22:46:48 +000078
Chris Lattner103ff152009-01-02 07:01:27 +000079 uint64_t atoull(const char *Buffer, const char *End);
80 uint64_t HexIntToVal(const char *Buffer, const char *End);
81 void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
Chris Lattner17e73c22007-11-18 08:46:26 +000082 };
83} // end namespace llvm
84
85#endif