blob: 49a63a16927a0fb0e7c478bb63bf251a99f9a5f4 [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"
Misha Brukman5679d182009-01-02 22:49:28 +000020#include <string>
Chris Lattner8e3a8e02007-11-18 08:46:26 +000021
22namespace llvm {
23 class MemoryBuffer;
Chris Lattnerdf986172009-01-02 07:01:27 +000024 class Type;
Chris Lattner92bcb422009-07-02 22:46:18 +000025 class SMDiagnostic;
Misha Brukman9ea40342009-01-02 22:46:48 +000026
Chris Lattner8e3a8e02007-11-18 08:46:26 +000027 class LLLexer {
28 const char *CurPtr;
Chris Lattner8e3a8e02007-11-18 08:46:26 +000029 MemoryBuffer *CurBuf;
Chris Lattner92bcb422009-07-02 22:46:18 +000030 SMDiagnostic &ErrorInfo;
Chris Lattnerdf986172009-01-02 07:01:27 +000031
32 // Information about the current token.
Chris Lattner8e3a8e02007-11-18 08:46:26 +000033 const char *TokStart;
Chris Lattnerdf986172009-01-02 07:01:27 +000034 lltok::Kind CurKind;
35 std::string StrVal;
36 unsigned UIntVal;
37 const Type *TyVal;
38 APFloat APFloatVal;
39 APSInt APSIntVal;
Misha Brukman9ea40342009-01-02 22:46:48 +000040
Chris Lattner8e3a8e02007-11-18 08:46:26 +000041 std::string TheError;
42 public:
Chris Lattner92bcb422009-07-02 22:46:18 +000043 explicit LLLexer(MemoryBuffer *StartBuf, SMDiagnostic &);
Chris Lattner8e3a8e02007-11-18 08:46:26 +000044 ~LLLexer() {}
45
Chris Lattnerdf986172009-01-02 07:01:27 +000046 lltok::Kind Lex() {
47 return CurKind = LexToken();
48 }
49
50 typedef const char* LocTy;
51 LocTy getLoc() const { return TokStart; }
52 lltok::Kind getKind() const { return CurKind; }
53 const std::string getStrVal() const { return StrVal; }
54 const Type *getTyVal() const { return TyVal; }
55 unsigned getUIntVal() const { return UIntVal; }
56 const APSInt &getAPSIntVal() const { return APSIntVal; }
57 const APFloat &getAPFloatVal() const { return APFloatVal; }
58
Misha Brukman9ea40342009-01-02 22:46:48 +000059
Chris Lattnerdf986172009-01-02 07:01:27 +000060 bool Error(LocTy L, const std::string &Msg) const;
61 bool Error(const std::string &Msg) const { return Error(CurPtr, Msg); }
Chris Lattner8e3a8e02007-11-18 08:46:26 +000062 std::string getFilename() const;
Misha Brukman9ea40342009-01-02 22:46:48 +000063
Chris Lattner8e3a8e02007-11-18 08:46:26 +000064 private:
Chris Lattnerdf986172009-01-02 07:01:27 +000065 lltok::Kind LexToken();
66
Chris Lattner8e3a8e02007-11-18 08:46:26 +000067 int getNextChar();
68 void SkipLineComment();
Chris Lattnerdf986172009-01-02 07:01:27 +000069 lltok::Kind LexIdentifier();
70 lltok::Kind LexDigitOrNegative();
71 lltok::Kind LexPositive();
72 lltok::Kind LexAt();
73 lltok::Kind LexPercent();
74 lltok::Kind LexQuote();
75 lltok::Kind Lex0x();
Misha Brukman9ea40342009-01-02 22:46:48 +000076
Chris Lattnerdf986172009-01-02 07:01:27 +000077 uint64_t atoull(const char *Buffer, const char *End);
78 uint64_t HexIntToVal(const char *Buffer, const char *End);
79 void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
Dale Johannesen1b25cb22009-03-23 21:16:53 +000080 void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
Chris Lattner8e3a8e02007-11-18 08:46:26 +000081 };
82} // end namespace llvm
83
84#endif