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/StringRef.h"
19 #include "llvm/ADT/STLExtras.h"
26 /// A token produced by the machine instruction lexer.
42 MIToken(TokenKind Kind, StringRef Range) : Kind(Kind), Range(Range) {}
44 TokenKind kind() const { return Kind; }
46 bool isError() const { return Kind == Error; }
48 bool is(TokenKind K) const { return Kind == K; }
50 bool isNot(TokenKind K) const { return Kind != K; }
52 StringRef::iterator location() const { return Range.begin(); }
54 StringRef stringValue() const { return Range; }
57 /// Consume a single machine instruction token in the given source and return
58 /// the remaining source string.
60 StringRef Source, MIToken &Token,
61 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
63 } // end namespace llvm