MIR Serialization: Serialize the frame setup machine instruction flag.
[oota-llvm.git] / lib / CodeGen / MIRParser / MILexer.h
1 //===- MILexer.h - Lexer for machine instructions -------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the function that lexes the machine instruction source
11 // string.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
16 #define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
17
18 #include "llvm/ADT/APSInt.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include <functional>
22
23 namespace llvm {
24
25 class Twine;
26
27 /// A token produced by the machine instruction lexer.
28 struct MIToken {
29   enum TokenKind {
30     // Markers
31     Eof,
32     Error,
33
34     // Tokens with no info.
35     comma,
36     equal,
37     underscore,
38     colon,
39
40     // Keywords
41     kw_implicit,
42     kw_implicit_define,
43     kw_dead,
44     kw_killed,
45     kw_undef,
46     kw_frame_setup,
47
48     // Identifier tokens
49     Identifier,
50     NamedRegister,
51     MachineBasicBlock,
52     StackObject,
53     FixedStackObject,
54     NamedGlobalValue,
55     GlobalValue,
56
57     // Other tokens
58     IntegerLiteral,
59     VirtualRegister,
60     JumpTableIndex
61   };
62
63 private:
64   TokenKind Kind;
65   unsigned StringOffset;
66   StringRef Range;
67   APSInt IntVal;
68
69 public:
70   MIToken(TokenKind Kind, StringRef Range, unsigned StringOffset = 0)
71       : Kind(Kind), StringOffset(StringOffset), Range(Range) {}
72
73   MIToken(TokenKind Kind, StringRef Range, const APSInt &IntVal,
74           unsigned StringOffset = 0)
75       : Kind(Kind), StringOffset(StringOffset), Range(Range), IntVal(IntVal) {}
76
77   TokenKind kind() const { return Kind; }
78
79   bool isError() const { return Kind == Error; }
80
81   bool isRegister() const {
82     return Kind == NamedRegister || Kind == underscore ||
83            Kind == VirtualRegister;
84   }
85
86   bool isRegisterFlag() const {
87     return Kind == kw_implicit || Kind == kw_implicit_define ||
88            Kind == kw_dead || Kind == kw_killed || Kind == kw_undef;
89   }
90
91   bool is(TokenKind K) const { return Kind == K; }
92
93   bool isNot(TokenKind K) const { return Kind != K; }
94
95   StringRef::iterator location() const { return Range.begin(); }
96
97   StringRef stringValue() const { return Range.drop_front(StringOffset); }
98
99   const APSInt &integerValue() const { return IntVal; }
100
101   bool hasIntegerValue() const {
102     return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
103            Kind == StackObject || Kind == FixedStackObject ||
104            Kind == GlobalValue || Kind == VirtualRegister ||
105            Kind == JumpTableIndex;
106   }
107 };
108
109 /// Consume a single machine instruction token in the given source and return
110 /// the remaining source string.
111 StringRef lexMIToken(
112     StringRef Source, MIToken &Token,
113     function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
114
115 } // end namespace llvm
116
117 #endif