MIR Serialization: Serialize physical register machine operands.
[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/StringRef.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include <functional>
21
22 namespace llvm {
23
24 class Twine;
25
26 /// A token produced by the machine instruction lexer.
27 struct MIToken {
28   enum TokenKind {
29     // Markers
30     Eof,
31     Error,
32
33     // Tokens with no info.
34     comma,
35     equal,
36
37     // Identifier tokens
38     Identifier,
39     NamedRegister
40   };
41
42 private:
43   TokenKind Kind;
44   StringRef Range;
45
46 public:
47   MIToken(TokenKind Kind, StringRef Range) : Kind(Kind), Range(Range) {}
48
49   TokenKind kind() const { return Kind; }
50
51   bool isError() const { return Kind == Error; }
52
53   bool isRegister() const { return Kind == NamedRegister; }
54
55   bool is(TokenKind K) const { return Kind == K; }
56
57   bool isNot(TokenKind K) const { return Kind != K; }
58
59   StringRef::iterator location() const { return Range.begin(); }
60
61   StringRef stringValue() const { return Range; }
62 };
63
64 /// Consume a single machine instruction token in the given source and return
65 /// the remaining source string.
66 StringRef lexMIToken(
67     StringRef Source, MIToken &Token,
68     function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
69
70 } // end namespace llvm
71
72 #endif