2015-06-22 20:37:46 +00:00
|
|
|
//===- MILexer.h - Lexer for machine instructions -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the function that lexes the machine instruction source
|
|
|
|
// string.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
|
|
|
|
#define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
|
|
|
|
|
2015-06-23 23:42:28 +00:00
|
|
|
#include "llvm/ADT/APSInt.h"
|
2015-06-22 20:37:46 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class Twine;
|
|
|
|
|
|
|
|
/// A token produced by the machine instruction lexer.
|
|
|
|
struct MIToken {
|
|
|
|
enum TokenKind {
|
|
|
|
// Markers
|
|
|
|
Eof,
|
|
|
|
Error,
|
2015-08-13 23:10:16 +00:00
|
|
|
Newline,
|
2015-06-22 20:37:46 +00:00
|
|
|
|
2015-06-23 16:35:26 +00:00
|
|
|
// Tokens with no info.
|
|
|
|
comma,
|
|
|
|
equal,
|
2015-06-24 17:34:58 +00:00
|
|
|
underscore,
|
2015-07-13 23:24:34 +00:00
|
|
|
colon,
|
2015-08-03 23:08:19 +00:00
|
|
|
coloncolon,
|
2015-07-22 17:58:46 +00:00
|
|
|
exclaim,
|
2015-07-28 17:28:03 +00:00
|
|
|
lparen,
|
|
|
|
rparen,
|
2015-08-14 18:57:24 +00:00
|
|
|
lbrace,
|
|
|
|
rbrace,
|
2015-08-05 22:26:15 +00:00
|
|
|
plus,
|
|
|
|
minus,
|
2015-06-23 16:35:26 +00:00
|
|
|
|
2015-07-06 23:07:26 +00:00
|
|
|
// Keywords
|
|
|
|
kw_implicit,
|
|
|
|
kw_implicit_define,
|
2015-07-07 20:34:53 +00:00
|
|
|
kw_dead,
|
2015-07-08 21:23:34 +00:00
|
|
|
kw_killed,
|
2015-07-08 23:58:31 +00:00
|
|
|
kw_undef,
|
2015-08-05 17:49:03 +00:00
|
|
|
kw_early_clobber,
|
2015-08-05 17:41:17 +00:00
|
|
|
kw_debug_use,
|
2015-07-17 00:24:15 +00:00
|
|
|
kw_frame_setup,
|
2015-07-22 21:15:11 +00:00
|
|
|
kw_debug_location,
|
2015-07-23 23:09:07 +00:00
|
|
|
kw_cfi_offset,
|
2015-07-27 20:39:03 +00:00
|
|
|
kw_cfi_def_cfa_register,
|
2015-07-21 22:28:27 +00:00
|
|
|
kw_cfi_def_cfa_offset,
|
2015-07-29 18:57:23 +00:00
|
|
|
kw_cfi_def_cfa,
|
2015-07-28 17:28:03 +00:00
|
|
|
kw_blockaddress,
|
2015-07-28 23:02:45 +00:00
|
|
|
kw_target_index,
|
2015-07-31 20:49:21 +00:00
|
|
|
kw_half,
|
|
|
|
kw_float,
|
|
|
|
kw_double,
|
|
|
|
kw_x86_fp80,
|
|
|
|
kw_fp128,
|
|
|
|
kw_ppc_fp128,
|
2015-08-06 00:44:07 +00:00
|
|
|
kw_target_flags,
|
2015-08-04 00:24:45 +00:00
|
|
|
kw_volatile,
|
2015-08-06 16:49:30 +00:00
|
|
|
kw_non_temporal,
|
2015-08-06 16:55:53 +00:00
|
|
|
kw_invariant,
|
2015-08-07 20:48:30 +00:00
|
|
|
kw_align,
|
2015-08-12 20:44:16 +00:00
|
|
|
kw_stack,
|
2015-08-12 21:00:22 +00:00
|
|
|
kw_got,
|
2015-08-12 21:11:08 +00:00
|
|
|
kw_jump_table,
|
2015-08-12 20:33:26 +00:00
|
|
|
kw_constant_pool,
|
2015-08-10 23:24:42 +00:00
|
|
|
kw_liveout,
|
2015-08-13 23:10:16 +00:00
|
|
|
kw_address_taken,
|
|
|
|
kw_landing_pad,
|
|
|
|
kw_liveins,
|
|
|
|
kw_successors,
|
2015-07-06 23:07:26 +00:00
|
|
|
|
2015-06-22 20:37:46 +00:00
|
|
|
// Identifier tokens
|
2015-06-23 16:35:26 +00:00
|
|
|
Identifier,
|
2015-08-05 18:52:21 +00:00
|
|
|
IntegerType,
|
2015-06-23 23:42:28 +00:00
|
|
|
NamedRegister,
|
2015-08-13 23:10:16 +00:00
|
|
|
MachineBasicBlockLabel,
|
2015-06-26 16:46:11 +00:00
|
|
|
MachineBasicBlock,
|
2015-07-16 23:37:45 +00:00
|
|
|
StackObject,
|
|
|
|
FixedStackObject,
|
2015-06-26 22:56:48 +00:00
|
|
|
NamedGlobalValue,
|
|
|
|
GlobalValue,
|
2015-07-21 16:59:53 +00:00
|
|
|
ExternalSymbol,
|
2015-06-23 23:42:28 +00:00
|
|
|
|
|
|
|
// Other tokens
|
2015-07-10 22:51:20 +00:00
|
|
|
IntegerLiteral,
|
2015-07-31 20:49:21 +00:00
|
|
|
FloatingPointLiteral,
|
2015-07-15 23:38:35 +00:00
|
|
|
VirtualRegister,
|
2015-07-20 20:51:18 +00:00
|
|
|
ConstantPoolItem,
|
2015-07-27 22:42:41 +00:00
|
|
|
JumpTableIndex,
|
2015-07-28 17:28:03 +00:00
|
|
|
NamedIRBlock,
|
2015-07-27 22:42:41 +00:00
|
|
|
IRBlock,
|
2015-08-03 23:08:19 +00:00
|
|
|
NamedIRValue,
|
2015-06-22 20:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
TokenKind Kind;
|
|
|
|
StringRef Range;
|
2015-08-06 23:17:42 +00:00
|
|
|
StringRef StringValue;
|
|
|
|
std::string StringValueStorage;
|
2015-06-23 23:42:28 +00:00
|
|
|
APSInt IntVal;
|
2015-06-22 20:37:46 +00:00
|
|
|
|
|
|
|
public:
|
2015-08-06 23:17:42 +00:00
|
|
|
MIToken() : Kind(Error) {}
|
2015-08-05 17:35:55 +00:00
|
|
|
|
2015-08-06 23:17:42 +00:00
|
|
|
MIToken &reset(TokenKind Kind, StringRef Range);
|
2015-06-22 20:37:46 +00:00
|
|
|
|
2015-08-06 23:17:42 +00:00
|
|
|
MIToken &setStringValue(StringRef StrVal);
|
|
|
|
MIToken &setOwnedStringValue(std::string StrVal);
|
|
|
|
MIToken &setIntegerValue(APSInt IntVal);
|
2015-06-23 23:42:28 +00:00
|
|
|
|
2015-06-22 20:37:46 +00:00
|
|
|
TokenKind kind() const { return Kind; }
|
|
|
|
|
|
|
|
bool isError() const { return Kind == Error; }
|
|
|
|
|
2015-08-13 23:10:16 +00:00
|
|
|
bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
|
|
|
|
|
|
|
|
bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
|
|
|
|
|
2015-06-24 17:34:58 +00:00
|
|
|
bool isRegister() const {
|
2015-07-10 22:51:20 +00:00
|
|
|
return Kind == NamedRegister || Kind == underscore ||
|
|
|
|
Kind == VirtualRegister;
|
2015-06-24 17:34:58 +00:00
|
|
|
}
|
2015-06-23 16:35:26 +00:00
|
|
|
|
2015-07-06 23:07:26 +00:00
|
|
|
bool isRegisterFlag() const {
|
2015-07-08 21:23:34 +00:00
|
|
|
return Kind == kw_implicit || Kind == kw_implicit_define ||
|
2015-08-05 17:41:17 +00:00
|
|
|
Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
|
2015-08-05 17:49:03 +00:00
|
|
|
Kind == kw_early_clobber || Kind == kw_debug_use;
|
2015-07-06 23:07:26 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 16:49:30 +00:00
|
|
|
bool isMemoryOperandFlag() const {
|
2015-08-06 16:55:53 +00:00
|
|
|
return Kind == kw_volatile || Kind == kw_non_temporal ||
|
|
|
|
Kind == kw_invariant;
|
2015-08-06 16:49:30 +00:00
|
|
|
}
|
2015-08-04 00:24:45 +00:00
|
|
|
|
2015-06-22 20:37:46 +00:00
|
|
|
bool is(TokenKind K) const { return Kind == K; }
|
|
|
|
|
|
|
|
bool isNot(TokenKind K) const { return Kind != K; }
|
|
|
|
|
|
|
|
StringRef::iterator location() const { return Range.begin(); }
|
|
|
|
|
2015-08-06 23:17:42 +00:00
|
|
|
StringRef range() const { return Range; }
|
2015-07-20 20:31:01 +00:00
|
|
|
|
2015-08-05 17:35:55 +00:00
|
|
|
/// Return the token's string value.
|
2015-08-06 23:17:42 +00:00
|
|
|
StringRef stringValue() const { return StringValue; }
|
2015-07-20 20:31:01 +00:00
|
|
|
|
2015-06-23 23:42:28 +00:00
|
|
|
const APSInt &integerValue() const { return IntVal; }
|
2015-06-26 16:46:11 +00:00
|
|
|
|
|
|
|
bool hasIntegerValue() const {
|
2015-06-26 22:56:48 +00:00
|
|
|
return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
|
2015-08-13 23:10:16 +00:00
|
|
|
Kind == MachineBasicBlockLabel || Kind == StackObject ||
|
|
|
|
Kind == FixedStackObject || Kind == GlobalValue ||
|
|
|
|
Kind == VirtualRegister || Kind == ConstantPoolItem ||
|
|
|
|
Kind == JumpTableIndex || Kind == IRBlock;
|
2015-06-26 16:46:11 +00:00
|
|
|
}
|
2015-06-22 20:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Consume a single machine instruction token in the given source and return
|
|
|
|
/// the remaining source string.
|
|
|
|
StringRef lexMIToken(
|
|
|
|
StringRef Source, MIToken &Token,
|
|
|
|
function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|