blob: 85703c766b099ec55f3c44a44ba2d7b2bbb7c7f6 [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"
Chris Lattnerac161bf2009-01-02 07:01:27 +000018#include "llvm/ADT/APFloat.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000019#include "llvm/ADT/APSInt.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;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +000041 Type *TyVal;
Chris Lattnerac161bf2009-01-02 07:01:27 +000042 APFloat APFloatVal;
43 APSInt APSIntVal;
Misha Brukman1d9a93d2009-01-02 22:46:48 +000044
Chris Lattner660c6b92007-11-18 08:46:26 +000045 public:
Owen Anderson32bc1e12009-07-07 18:44:11 +000046 explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &,
47 LLVMContext &C);
Chris Lattner660c6b92007-11-18 08:46:26 +000048 ~LLLexer() {}
49
Chris Lattnerac161bf2009-01-02 07:01:27 +000050 lltok::Kind Lex() {
51 return CurKind = LexToken();
52 }
53
Chris Lattner200e0752009-07-02 23:08:13 +000054 typedef SMLoc LocTy;
55 LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
Chris Lattnerac161bf2009-01-02 07:01:27 +000056 lltok::Kind getKind() const { return CurKind; }
Chris Lattnerdba43462010-04-01 04:53:22 +000057 const std::string &getStrVal() const { return StrVal; }
Chris Lattnerb1ed91f2011-07-09 17:41:24 +000058 Type *getTyVal() const { return TyVal; }
Chris Lattnerac161bf2009-01-02 07:01:27 +000059 unsigned getUIntVal() const { return UIntVal; }
60 const APSInt &getAPSIntVal() const { return APSIntVal; }
61 const APFloat &getAPFloatVal() const { return APFloatVal; }
62
Misha Brukman1d9a93d2009-01-02 22:46:48 +000063
Benjamin Kramerc7583112010-09-27 17:42:11 +000064 bool Error(LocTy L, const Twine &Msg) const;
65 bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); }
Chris Lattner660c6b92007-11-18 08:46:26 +000066 std::string getFilename() const;
Misha Brukman1d9a93d2009-01-02 22:46:48 +000067
Chris Lattner660c6b92007-11-18 08:46:26 +000068 private:
Chris Lattnerac161bf2009-01-02 07:01:27 +000069 lltok::Kind LexToken();
70
Chris Lattner660c6b92007-11-18 08:46:26 +000071 int getNextChar();
72 void SkipLineComment();
Nick Lewycky2176cdc2011-06-04 18:16:26 +000073 lltok::Kind ReadString(lltok::Kind kind);
74 bool ReadVarName();
75
Chris Lattnerac161bf2009-01-02 07:01:27 +000076 lltok::Kind LexIdentifier();
77 lltok::Kind LexDigitOrNegative();
78 lltok::Kind LexPositive();
79 lltok::Kind LexAt();
Chris Lattner1eed2d62009-12-30 04:56:59 +000080 lltok::Kind LexExclaim();
Chris Lattnerac161bf2009-01-02 07:01:27 +000081 lltok::Kind LexPercent();
82 lltok::Kind LexQuote();
83 lltok::Kind Lex0x();
Bill Wendling63b88192013-02-06 06:52:58 +000084 lltok::Kind LexHash();
Misha Brukman1d9a93d2009-01-02 22:46:48 +000085
Chris Lattnerac161bf2009-01-02 07:01:27 +000086 uint64_t atoull(const char *Buffer, const char *End);
87 uint64_t HexIntToVal(const char *Buffer, const char *End);
88 void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
Dale Johannesen93eefa02009-03-23 21:16:53 +000089 void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
Chris Lattner660c6b92007-11-18 08:46:26 +000090 };
91} // end namespace llvm
92
93#endif