MIR Serialization: Serialize the memory operand's noalias metadata node.
[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     Newline,
34
35     // Tokens with no info.
36     comma,
37     equal,
38     underscore,
39     colon,
40     coloncolon,
41     exclaim,
42     lparen,
43     rparen,
44     lbrace,
45     rbrace,
46     plus,
47     minus,
48
49     // Keywords
50     kw_implicit,
51     kw_implicit_define,
52     kw_dead,
53     kw_killed,
54     kw_undef,
55     kw_internal,
56     kw_early_clobber,
57     kw_debug_use,
58     kw_frame_setup,
59     kw_debug_location,
60     kw_cfi_same_value,
61     kw_cfi_offset,
62     kw_cfi_def_cfa_register,
63     kw_cfi_def_cfa_offset,
64     kw_cfi_def_cfa,
65     kw_blockaddress,
66     kw_target_index,
67     kw_half,
68     kw_float,
69     kw_double,
70     kw_x86_fp80,
71     kw_fp128,
72     kw_ppc_fp128,
73     kw_target_flags,
74     kw_volatile,
75     kw_non_temporal,
76     kw_invariant,
77     kw_align,
78     kw_stack,
79     kw_got,
80     kw_jump_table,
81     kw_constant_pool,
82     kw_liveout,
83     kw_address_taken,
84     kw_landing_pad,
85     kw_liveins,
86     kw_successors,
87
88     // Named metadata keywords
89     md_tbaa,
90     md_alias_scope,
91     md_noalias,
92
93     // Identifier tokens
94     Identifier,
95     IntegerType,
96     NamedRegister,
97     MachineBasicBlockLabel,
98     MachineBasicBlock,
99     StackObject,
100     FixedStackObject,
101     NamedGlobalValue,
102     GlobalValue,
103     ExternalSymbol,
104
105     // Other tokens
106     IntegerLiteral,
107     FloatingPointLiteral,
108     VirtualRegister,
109     ConstantPoolItem,
110     JumpTableIndex,
111     NamedIRBlock,
112     IRBlock,
113     NamedIRValue,
114   };
115
116 private:
117   TokenKind Kind;
118   StringRef Range;
119   StringRef StringValue;
120   std::string StringValueStorage;
121   APSInt IntVal;
122
123 public:
124   MIToken() : Kind(Error) {}
125
126   MIToken &reset(TokenKind Kind, StringRef Range);
127
128   MIToken &setStringValue(StringRef StrVal);
129   MIToken &setOwnedStringValue(std::string StrVal);
130   MIToken &setIntegerValue(APSInt IntVal);
131
132   TokenKind kind() const { return Kind; }
133
134   bool isError() const { return Kind == Error; }
135
136   bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
137
138   bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
139
140   bool isRegister() const {
141     return Kind == NamedRegister || Kind == underscore ||
142            Kind == VirtualRegister;
143   }
144
145   bool isRegisterFlag() const {
146     return Kind == kw_implicit || Kind == kw_implicit_define ||
147            Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
148            Kind == kw_internal || Kind == kw_early_clobber ||
149            Kind == kw_debug_use;
150   }
151
152   bool isMemoryOperandFlag() const {
153     return Kind == kw_volatile || Kind == kw_non_temporal ||
154            Kind == kw_invariant;
155   }
156
157   bool is(TokenKind K) const { return Kind == K; }
158
159   bool isNot(TokenKind K) const { return Kind != K; }
160
161   StringRef::iterator location() const { return Range.begin(); }
162
163   StringRef range() const { return Range; }
164
165   /// Return the token's string value.
166   StringRef stringValue() const { return StringValue; }
167
168   const APSInt &integerValue() const { return IntVal; }
169
170   bool hasIntegerValue() const {
171     return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
172            Kind == MachineBasicBlockLabel || Kind == StackObject ||
173            Kind == FixedStackObject || Kind == GlobalValue ||
174            Kind == VirtualRegister || Kind == ConstantPoolItem ||
175            Kind == JumpTableIndex || Kind == IRBlock;
176   }
177 };
178
179 /// Consume a single machine instruction token in the given source and return
180 /// the remaining source string.
181 StringRef lexMIToken(
182     StringRef Source, MIToken &Token,
183     function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
184
185 } // end namespace llvm
186
187 #endif