blob: 5e9843ccec85b884f6d816deb94ff0d2999eb5f8 [file] [log] [blame]
Chris Lattner8e3a8e02007-11-18 08:46:26 +00001//===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Lattner8e3a8e02007-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 Lattnerdf986172009-01-02 07:01:27 +000017#include "LLToken.h"
18#include "llvm/ADT/APSInt.h"
19#include "llvm/ADT/APFloat.h"
Chris Lattner8e3a8e02007-11-18 08:46:26 +000020#include <iosfwd>
Misha Brukman5679d182009-01-02 22:49:28 +000021#include <string>
22#include <vector>
Chris Lattner8e3a8e02007-11-18 08:46:26 +000023
24namespace llvm {
25 class MemoryBuffer;
Chris Lattnerdf986172009-01-02 07:01:27 +000026 class Type;
27 class ParseError;
Misha Brukman9ea40342009-01-02 22:46:48 +000028
Chris Lattner8e3a8e02007-11-18 08:46:26 +000029 class LLLexer {
30 const char *CurPtr;
Chris Lattner8e3a8e02007-11-18 08:46:26 +000031 MemoryBuffer *CurBuf;
Chris Lattnerdf986172009-01-02 07:01:27 +000032 ParseError &ErrorInfo;
33
34 // Information about the current token.
Chris Lattner8e3a8e02007-11-18 08:46:26 +000035 const char *TokStart;
Chris Lattnerdf986172009-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 Brukman9ea40342009-01-02 22:46:48 +000042
Chris Lattner8e3a8e02007-11-18 08:46:26 +000043 std::string TheError;
44 public:
Chris Lattnerdf986172009-01-02 07:01:27 +000045 explicit LLLexer(MemoryBuffer *StartBuf, ParseError &);
Chris Lattner8e3a8e02007-11-18 08:46:26 +000046 ~LLLexer() {}
47
Chris Lattnerdf986172009-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 Brukman9ea40342009-01-02 22:46:48 +000061
Chris Lattnerdf986172009-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 Lattner8e3a8e02007-11-18 08:46:26 +000064 std::string getFilename() const;
Misha Brukman9ea40342009-01-02 22:46:48 +000065
Chris Lattner8e3a8e02007-11-18 08:46:26 +000066 private:
Chris Lattnerdf986172009-01-02 07:01:27 +000067 lltok::Kind LexToken();
68
Chris Lattner8e3a8e02007-11-18 08:46:26 +000069 int getNextChar();
70 void SkipLineComment();
Chris Lattnerdf986172009-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 Brukman9ea40342009-01-02 22:46:48 +000078
Chris Lattnerdf986172009-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 Lattner8e3a8e02007-11-18 08:46:26 +000082 };
83} // end namespace llvm
84
85#endif