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.
52 unsigned StringOffset;
57 MIToken(TokenKind Kind, StringRef Range, unsigned StringOffset = 0)
58 : Kind(Kind), StringOffset(StringOffset), Range(Range) {}
60 MIToken(TokenKind Kind, StringRef Range, const APSInt &IntVal,
61 unsigned StringOffset = 0)
62 : Kind(Kind), StringOffset(StringOffset), Range(Range), IntVal(IntVal) {}
64 TokenKind kind() const { return Kind; }
66 bool isError() const { return Kind == Error; }
68 bool isRegister() const {
69 return Kind == NamedRegister || Kind == underscore;
72 bool is(TokenKind K) const { return Kind == K; }
74 bool isNot(TokenKind K) const { return Kind != K; }
76 StringRef::iterator location() const { return Range.begin(); }
78 StringRef stringValue() const { return Range.drop_front(StringOffset); }
80 const APSInt &integerValue() const { return IntVal; }
82 bool hasIntegerValue() const {
83 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
88 /// Consume a single machine instruction token in the given source and return
89 /// the remaining source string.
91 StringRef Source, MIToken &Token,
92 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
94 } // end namespace llvm