blob: 3057992231b5aa2f68903f1d433a7cb306cd4f5f [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;
Benjamin Kramer12ddd402009-08-11 17:45:13 +000027 class LLVMContext;
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 Lattner92bcb422009-07-02 22:46:18 +000032 SMDiagnostic &ErrorInfo;
Chris Lattnereeb4a842009-07-02 23:08:13 +000033 SourceMgr &SM;
Owen Andersonff6c91e2009-07-07 18:44:11 +000034 LLVMContext &Context;
Chris Lattnerdf986172009-01-02 07:01:27 +000035
36 // Information about the current token.
Chris Lattner8e3a8e02007-11-18 08:46:26 +000037 const char *TokStart;
Chris Lattnerdf986172009-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 Brukman9ea40342009-01-02 22:46:48 +000044
Chris Lattner8e3a8e02007-11-18 08:46:26 +000045 std::string TheError;
46 public:
Owen Andersonff6c91e2009-07-07 18:44:11 +000047 explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &,
48 LLVMContext &C);
Chris Lattner8e3a8e02007-11-18 08:46:26 +000049 ~LLLexer() {}
50
Chris Lattnerdf986172009-01-02 07:01:27 +000051 lltok::Kind Lex() {
52 return CurKind = LexToken();
53 }
54
Chris Lattnereeb4a842009-07-02 23:08:13 +000055 typedef SMLoc LocTy;
56 LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
Chris Lattnerdf986172009-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 Brukman9ea40342009-01-02 22:46:48 +000064
Chris Lattnerdf986172009-01-02 07:01:27 +000065 bool Error(LocTy L, const std::string &Msg) const;
Chris Lattnereeb4a842009-07-02 23:08:13 +000066 bool Error(const std::string &Msg) const { return Error(getLoc(), Msg); }
Chris Lattner8e3a8e02007-11-18 08:46:26 +000067 std::string getFilename() const;
Misha Brukman9ea40342009-01-02 22:46:48 +000068
Chris Lattner8e3a8e02007-11-18 08:46:26 +000069 private:
Chris Lattnerdf986172009-01-02 07:01:27 +000070 lltok::Kind LexToken();
71
Chris Lattner8e3a8e02007-11-18 08:46:26 +000072 int getNextChar();
73 void SkipLineComment();
Chris Lattnerdf986172009-01-02 07:01:27 +000074 lltok::Kind LexIdentifier();
75 lltok::Kind LexDigitOrNegative();
76 lltok::Kind LexPositive();
77 lltok::Kind LexAt();
Chris Lattnere434d272009-12-30 04:56:59 +000078 lltok::Kind LexExclaim();
Chris Lattnerdf986172009-01-02 07:01:27 +000079 lltok::Kind LexPercent();
80 lltok::Kind LexQuote();
81 lltok::Kind Lex0x();
Misha Brukman9ea40342009-01-02 22:46:48 +000082
Chris Lattnerdf986172009-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 Johannesen1b25cb22009-03-23 21:16:53 +000086 void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
Chris Lattner8e3a8e02007-11-18 08:46:26 +000087 };
88} // end namespace llvm
89
90#endif