1 //===- MILexer.h - Lexer for machine instructions -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the function that lexes the machine instruction source
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
16 #define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
18 #include "llvm/ADT/APSInt.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/STLExtras.h"
27 /// A token produced by the machine instruction lexer.
34 // Tokens with no info.
62 unsigned StringOffset;
67 MIToken(TokenKind Kind, StringRef Range, unsigned StringOffset = 0)
68 : Kind(Kind), StringOffset(StringOffset), Range(Range) {}
70 MIToken(TokenKind Kind, StringRef Range, const APSInt &IntVal,
71 unsigned StringOffset = 0)
72 : Kind(Kind), StringOffset(StringOffset), Range(Range), IntVal(IntVal) {}
74 TokenKind kind() const { return Kind; }
76 bool isError() const { return Kind == Error; }
78 bool isRegister() const {
79 return Kind == NamedRegister || Kind == underscore ||
80 Kind == VirtualRegister;
83 bool isRegisterFlag() const {
84 return Kind == kw_implicit || Kind == kw_implicit_define ||
85 Kind == kw_dead || Kind == kw_killed || Kind == kw_undef;
88 bool is(TokenKind K) const { return Kind == K; }
90 bool isNot(TokenKind K) const { return Kind != K; }
92 StringRef::iterator location() const { return Range.begin(); }
94 StringRef stringValue() const { return Range.drop_front(StringOffset); }
96 const APSInt &integerValue() const { return IntVal; }
98 bool hasIntegerValue() const {
99 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
100 Kind == GlobalValue || Kind == VirtualRegister ||
101 Kind == JumpTableIndex;
105 /// Consume a single machine instruction token in the given source and return
106 /// the remaining source string.
107 StringRef lexMIToken(
108 StringRef Source, MIToken &Token,
109 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
111 } // end namespace llvm