blob: 3057992231b5aa2f68903f1d433a7cb306cd4f5f [file] [log] [blame]
Chris Lattner660c6b92007-11-18 08:46:26 +00001//===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Lattner660c6b92007-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 Lattnerac161bf2009-01-02 07:01:27 +000017#include "LLToken.h"
18#include "llvm/ADT/APSInt.h"
19#include "llvm/ADT/APFloat.h"
Chris Lattner200e0752009-07-02 23:08:13 +000020#include "llvm/Support/SourceMgr.h"
Misha Brukmanfcef9092009-01-02 22:49:28 +000021#include <string>
Chris Lattner660c6b92007-11-18 08:46:26 +000022
23namespace llvm {
24 class MemoryBuffer;
Chris Lattnerac161bf2009-01-02 07:01:27 +000025 class Type;
Chris Lattnera76611a2009-07-02 22:46:18 +000026 class SMDiagnostic;
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +000027 class LLVMContext;
Misha Brukman1d9a93d2009-01-02 22:46:48 +000028
Chris Lattner660c6b92007-11-18 08:46:26 +000029 class LLLexer {
30 const char *CurPtr;
Chris Lattner660c6b92007-11-18 08:46:26 +000031 MemoryBuffer *CurBuf;
Chris Lattnera76611a2009-07-02 22:46:18 +000032 SMDiagnostic &ErrorInfo;
Chris Lattner200e0752009-07-02 23:08:13 +000033 SourceMgr &SM;
Owen Anderson32bc1e12009-07-07 18:44:11 +000034 LLVMContext &Context;
Chris Lattnerac161bf2009-01-02 07:01:27 +000035
36 // Information about the current token.
Chris Lattner660c6b92007-11-18 08:46:26 +000037 const char *TokStart;
Chris Lattnerac161bf2009-01-02 07:01:27 +000038 lltok::Kind CurKind;
39 std::string StrVal;
40 unsigned UIntVal;
41 const Type *TyVal;
42 APFloat APFloatVal;
43 APSInt APSIntVal;
Misha Brukman1d9a93d2009-01-02 22:46:48 +000044
Chris Lattner660c6b92007-11-18 08:46:26 +000045 std::string TheError;
46 public:
Owen Anderson32bc1e12009-07-07 18:44:11 +000047 explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &,
48 LLVMContext &C);
Chris Lattner660c6b92007-11-18 08:46:26 +000049 ~LLLexer() {}
50
Chris Lattnerac161bf2009-01-02 07:01:27 +000051 lltok::Kind Lex() {
52 return CurKind = LexToken();
53 }
54
Chris Lattner200e0752009-07-02 23:08:13 +000055 typedef SMLoc LocTy;
56 LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
Chris Lattnerac161bf2009-01-02 07:01:27 +000057 lltok::Kind getKind() const { return CurKind; }
58 const std::string getStrVal() const { return StrVal; }
59 const Type *getTyVal() const { return TyVal; }
60 unsigned getUIntVal() const { return UIntVal; }
61 const APSInt &getAPSIntVal() const { return APSIntVal; }
62 const APFloat &getAPFloatVal() const { return APFloatVal; }
63
Misha Brukman1d9a93d2009-01-02 22:46:48 +000064
Chris Lattnerac161bf2009-01-02 07:01:27 +000065 bool Error(LocTy L, const std::string &Msg) const;
Chris Lattner200e0752009-07-02 23:08:13 +000066 bool Error(const std::string &Msg) const { return Error(getLoc(), Msg); }
Chris Lattner660c6b92007-11-18 08:46:26 +000067 std::string getFilename() const;
Misha Brukman1d9a93d2009-01-02 22:46:48 +000068
Chris Lattner660c6b92007-11-18 08:46:26 +000069 private:
Chris Lattnerac161bf2009-01-02 07:01:27 +000070 lltok::Kind LexToken();
71
Chris Lattner660c6b92007-11-18 08:46:26 +000072 int getNextChar();
73 void SkipLineComment();
Chris Lattnerac161bf2009-01-02 07:01:27 +000074 lltok::Kind LexIdentifier();
75 lltok::Kind LexDigitOrNegative();
76 lltok::Kind LexPositive();
77 lltok::Kind LexAt();
Chris Lattner1eed2d62009-12-30 04:56:59 +000078 lltok::Kind LexExclaim();
Chris Lattnerac161bf2009-01-02 07:01:27 +000079 lltok::Kind LexPercent();
80 lltok::Kind LexQuote();
81 lltok::Kind Lex0x();
Misha Brukman1d9a93d2009-01-02 22:46:48 +000082
Chris Lattnerac161bf2009-01-02 07:01:27 +000083 uint64_t atoull(const char *Buffer, const char *End);
84 uint64_t HexIntToVal(const char *Buffer, const char *End);
85 void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
Dale Johannesen93eefa02009-03-23 21:16:53 +000086 void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
Chris Lattner660c6b92007-11-18 08:46:26 +000087 };
88} // end namespace llvm
89
90#endif