blob: b5e58f1418ec23a543b090bbb0b3772b64b4b257 [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 Lattnereeb4a842009-07-02 23:08:13 +000020#include "llvm/Support/SourceMgr.h"
Misha Brukman5679d182009-01-02 22:49:28 +000021#include <string>
Chris Lattner8e3a8e02007-11-18 08:46:26 +000022
23namespace llvm {
24 class MemoryBuffer;
Chris Lattnerdf986172009-01-02 07:01:27 +000025 class Type;
Chris Lattner92bcb422009-07-02 22:46:18 +000026 class SMDiagnostic;
Misha Brukman9ea40342009-01-02 22:46:48 +000027
Chris Lattner8e3a8e02007-11-18 08:46:26 +000028 class LLLexer {
29 const char *CurPtr;
Chris Lattner8e3a8e02007-11-18 08:46:26 +000030 MemoryBuffer *CurBuf;
Chris Lattner92bcb422009-07-02 22:46:18 +000031 SMDiagnostic &ErrorInfo;
Chris Lattnereeb4a842009-07-02 23:08:13 +000032 SourceMgr &SM;
Chris Lattnerdf986172009-01-02 07:01:27 +000033
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 Lattnereeb4a842009-07-02 23:08:13 +000045 explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &);
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
Chris Lattnereeb4a842009-07-02 23:08:13 +000052 typedef SMLoc LocTy;
53 LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
Chris Lattnerdf986172009-01-02 07:01:27 +000054 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;
Chris Lattnereeb4a842009-07-02 23:08:13 +000063 bool Error(const std::string &Msg) const { return Error(getLoc(), 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]);
Dale Johannesen1b25cb22009-03-23 21:16:53 +000082 void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
Chris Lattner8e3a8e02007-11-18 08:46:26 +000083 };
84} // end namespace llvm
85
86#endif