2017-09-27 23:26:01 +00:00
|
|
|
//===- MILexer.cpp - Machine instructions lexer implementation ------------===//
|
2015-06-22 20:37:46 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-06-22 20:37:46 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the lexing of machine instructions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MILexer.h"
|
2017-09-27 23:26:01 +00:00
|
|
|
#include "llvm/ADT/APSInt.h"
|
2016-04-16 07:51:28 +00:00
|
|
|
#include "llvm/ADT/None.h"
|
2017-09-27 23:26:01 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2015-07-20 20:31:01 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2015-07-06 23:07:26 +00:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2017-09-27 23:26:01 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-06-22 20:37:46 +00:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-09-27 23:26:01 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
2015-06-22 20:37:46 +00:00
|
|
|
#include <cctype>
|
2017-09-27 23:26:01 +00:00
|
|
|
#include <string>
|
2015-06-22 20:37:46 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-09-27 23:26:01 +00:00
|
|
|
using ErrorCallbackType =
|
|
|
|
function_ref<void(StringRef::iterator Loc, const Twine &)>;
|
2016-03-18 20:41:11 +00:00
|
|
|
|
2015-06-22 20:37:46 +00:00
|
|
|
/// This class provides a way to iterate and get characters from the source
|
|
|
|
/// string.
|
|
|
|
class Cursor {
|
2017-09-27 23:26:01 +00:00
|
|
|
const char *Ptr = nullptr;
|
|
|
|
const char *End = nullptr;
|
2015-06-22 20:37:46 +00:00
|
|
|
|
|
|
|
public:
|
2017-09-27 23:26:01 +00:00
|
|
|
Cursor(NoneType) {}
|
2015-06-30 16:51:29 +00:00
|
|
|
|
2015-06-22 20:37:46 +00:00
|
|
|
explicit Cursor(StringRef Str) {
|
|
|
|
Ptr = Str.data();
|
|
|
|
End = Ptr + Str.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isEOF() const { return Ptr == End; }
|
|
|
|
|
2015-06-24 06:40:09 +00:00
|
|
|
char peek(int I = 0) const { return End - Ptr <= I ? 0 : Ptr[I]; }
|
2015-06-22 20:37:46 +00:00
|
|
|
|
2015-06-26 16:46:11 +00:00
|
|
|
void advance(unsigned I = 1) { Ptr += I; }
|
2015-06-22 20:37:46 +00:00
|
|
|
|
|
|
|
StringRef remaining() const { return StringRef(Ptr, End - Ptr); }
|
|
|
|
|
|
|
|
StringRef upto(Cursor C) const {
|
|
|
|
assert(C.Ptr >= Ptr && C.Ptr <= End);
|
|
|
|
return StringRef(Ptr, C.Ptr - Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef::iterator location() const { return Ptr; }
|
2015-06-30 16:51:29 +00:00
|
|
|
|
|
|
|
operator bool() const { return Ptr != nullptr; }
|
2015-06-22 20:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2015-08-06 23:17:42 +00:00
|
|
|
MIToken &MIToken::reset(TokenKind Kind, StringRef Range) {
|
|
|
|
this->Kind = Kind;
|
|
|
|
this->Range = Range;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
MIToken &MIToken::setStringValue(StringRef StrVal) {
|
|
|
|
StringValue = StrVal;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
MIToken &MIToken::setOwnedStringValue(std::string StrVal) {
|
|
|
|
StringValueStorage = std::move(StrVal);
|
|
|
|
StringValue = StringValueStorage;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
MIToken &MIToken::setIntegerValue(APSInt IntVal) {
|
|
|
|
this->IntVal = std::move(IntVal);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-06-22 20:37:46 +00:00
|
|
|
/// Skip the leading whitespace characters and return the updated cursor.
|
|
|
|
static Cursor skipWhitespace(Cursor C) {
|
2015-08-13 23:10:16 +00:00
|
|
|
while (isblank(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isNewlineChar(char C) { return C == '\n' || C == '\r'; }
|
|
|
|
|
|
|
|
/// Skip a line comment and return the updated cursor.
|
|
|
|
static Cursor skipComment(Cursor C) {
|
|
|
|
if (C.peek() != ';')
|
|
|
|
return C;
|
|
|
|
while (!isNewlineChar(C.peek()) && !C.isEOF())
|
2015-06-22 20:37:46 +00:00
|
|
|
C.advance();
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-07-17 22:48:04 +00:00
|
|
|
/// Return true if the given character satisfies the following regular
|
|
|
|
/// expression: [-a-zA-Z$._0-9]
|
2015-06-22 20:37:46 +00:00
|
|
|
static bool isIdentifierChar(char C) {
|
2015-07-17 22:48:04 +00:00
|
|
|
return isalpha(C) || isdigit(C) || C == '_' || C == '-' || C == '.' ||
|
|
|
|
C == '$';
|
2015-06-22 20:37:46 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 17:35:55 +00:00
|
|
|
/// Unescapes the given string value.
|
|
|
|
///
|
|
|
|
/// Expects the string value to be quoted.
|
|
|
|
static std::string unescapeQuotedString(StringRef Value) {
|
2015-07-20 20:31:01 +00:00
|
|
|
assert(Value.front() == '"' && Value.back() == '"');
|
|
|
|
Cursor C = Cursor(Value.substr(1, Value.size() - 2));
|
|
|
|
|
2015-08-05 17:35:55 +00:00
|
|
|
std::string Str;
|
2015-07-20 20:31:01 +00:00
|
|
|
Str.reserve(C.remaining().size());
|
|
|
|
while (!C.isEOF()) {
|
|
|
|
char Char = C.peek();
|
|
|
|
if (Char == '\\') {
|
|
|
|
if (C.peek(1) == '\\') {
|
|
|
|
// Two '\' become one
|
|
|
|
Str += '\\';
|
|
|
|
C.advance(2);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isxdigit(C.peek(1)) && isxdigit(C.peek(2))) {
|
|
|
|
Str += hexDigitValue(C.peek(1)) * 16 + hexDigitValue(C.peek(2));
|
|
|
|
C.advance(3);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Str += Char;
|
|
|
|
C.advance();
|
|
|
|
}
|
2015-08-05 17:35:55 +00:00
|
|
|
return Str;
|
2015-07-20 20:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex a string constant using the following regular expression: \"[^\"]*\"
|
2016-03-18 20:41:11 +00:00
|
|
|
static Cursor lexStringConstant(Cursor C, ErrorCallbackType ErrorCallback) {
|
2015-07-20 20:31:01 +00:00
|
|
|
assert(C.peek() == '"');
|
|
|
|
for (C.advance(); C.peek() != '"'; C.advance()) {
|
2015-08-13 23:10:16 +00:00
|
|
|
if (C.isEOF() || isNewlineChar(C.peek())) {
|
2015-07-20 20:31:01 +00:00
|
|
|
ErrorCallback(
|
|
|
|
C.location(),
|
|
|
|
"end of machine instruction reached before the closing '\"'");
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
C.advance();
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2016-03-18 20:41:11 +00:00
|
|
|
static Cursor lexName(Cursor C, MIToken &Token, MIToken::TokenKind Type,
|
|
|
|
unsigned PrefixLength, ErrorCallbackType ErrorCallback) {
|
2015-07-28 17:03:40 +00:00
|
|
|
auto Range = C;
|
|
|
|
C.advance(PrefixLength);
|
|
|
|
if (C.peek() == '"') {
|
|
|
|
if (Cursor R = lexStringConstant(C, ErrorCallback)) {
|
2015-08-05 17:35:55 +00:00
|
|
|
StringRef String = Range.upto(R);
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(Type, String)
|
|
|
|
.setOwnedStringValue(
|
|
|
|
unescapeQuotedString(String.drop_front(PrefixLength)));
|
2015-07-28 17:03:40 +00:00
|
|
|
return R;
|
|
|
|
}
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(MIToken::Error, Range.remaining());
|
2015-07-28 17:03:40 +00:00
|
|
|
return Range;
|
|
|
|
}
|
|
|
|
while (isIdentifierChar(C.peek()))
|
|
|
|
C.advance();
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(Type, Range.upto(C))
|
|
|
|
.setStringValue(Range.upto(C).drop_front(PrefixLength));
|
2015-07-28 17:03:40 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-07-06 23:07:26 +00:00
|
|
|
static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
|
|
|
|
return StringSwitch<MIToken::TokenKind>(Identifier)
|
|
|
|
.Case("_", MIToken::underscore)
|
|
|
|
.Case("implicit", MIToken::kw_implicit)
|
|
|
|
.Case("implicit-def", MIToken::kw_implicit_define)
|
2015-08-19 18:55:47 +00:00
|
|
|
.Case("def", MIToken::kw_def)
|
2015-07-07 20:34:53 +00:00
|
|
|
.Case("dead", MIToken::kw_dead)
|
2015-07-08 21:23:34 +00:00
|
|
|
.Case("killed", MIToken::kw_killed)
|
2015-07-08 23:58:31 +00:00
|
|
|
.Case("undef", MIToken::kw_undef)
|
2015-08-14 19:07:07 +00:00
|
|
|
.Case("internal", MIToken::kw_internal)
|
2015-08-05 17:49:03 +00:00
|
|
|
.Case("early-clobber", MIToken::kw_early_clobber)
|
2015-08-05 17:41:17 +00:00
|
|
|
.Case("debug-use", MIToken::kw_debug_use)
|
2017-12-12 17:53:59 +00:00
|
|
|
.Case("renamable", MIToken::kw_renamable)
|
2015-08-19 19:05:34 +00:00
|
|
|
.Case("tied-def", MIToken::kw_tied_def)
|
2015-07-17 00:24:15 +00:00
|
|
|
.Case("frame-setup", MIToken::kw_frame_setup)
|
2018-01-09 11:33:22 +00:00
|
|
|
.Case("frame-destroy", MIToken::kw_frame_destroy)
|
2018-05-03 00:07:56 +00:00
|
|
|
.Case("nnan", MIToken::kw_nnan)
|
|
|
|
.Case("ninf", MIToken::kw_ninf)
|
|
|
|
.Case("nsz", MIToken::kw_nsz)
|
|
|
|
.Case("arcp", MIToken::kw_arcp)
|
|
|
|
.Case("contract", MIToken::kw_contract)
|
|
|
|
.Case("afn", MIToken::kw_afn)
|
|
|
|
.Case("reassoc", MIToken::kw_reassoc)
|
2018-09-11 21:35:32 +00:00
|
|
|
.Case("nuw" , MIToken::kw_nuw)
|
|
|
|
.Case("nsw" , MIToken::kw_nsw)
|
|
|
|
.Case("exact" , MIToken::kw_exact)
|
2019-06-05 22:33:10 +00:00
|
|
|
.Case("fpexcept", MIToken::kw_fpexcept)
|
2015-07-22 21:15:11 +00:00
|
|
|
.Case("debug-location", MIToken::kw_debug_location)
|
2016-07-26 18:20:00 +00:00
|
|
|
.Case("same_value", MIToken::kw_cfi_same_value)
|
|
|
|
.Case("offset", MIToken::kw_cfi_offset)
|
2017-12-15 15:17:18 +00:00
|
|
|
.Case("rel_offset", MIToken::kw_cfi_rel_offset)
|
2016-07-26 18:20:00 +00:00
|
|
|
.Case("def_cfa_register", MIToken::kw_cfi_def_cfa_register)
|
|
|
|
.Case("def_cfa_offset", MIToken::kw_cfi_def_cfa_offset)
|
2017-12-15 15:17:18 +00:00
|
|
|
.Case("adjust_cfa_offset", MIToken::kw_cfi_adjust_cfa_offset)
|
|
|
|
.Case("escape", MIToken::kw_cfi_escape)
|
2016-07-26 18:20:00 +00:00
|
|
|
.Case("def_cfa", MIToken::kw_cfi_def_cfa)
|
2017-12-15 15:17:18 +00:00
|
|
|
.Case("remember_state", MIToken::kw_cfi_remember_state)
|
2017-11-02 12:00:58 +00:00
|
|
|
.Case("restore", MIToken::kw_cfi_restore)
|
2017-12-15 15:17:18 +00:00
|
|
|
.Case("restore_state", MIToken::kw_cfi_restore_state)
|
|
|
|
.Case("undefined", MIToken::kw_cfi_undefined)
|
|
|
|
.Case("register", MIToken::kw_cfi_register)
|
|
|
|
.Case("window_save", MIToken::kw_cfi_window_save)
|
2018-12-18 10:37:42 +00:00
|
|
|
.Case("negate_ra_sign_state", MIToken::kw_cfi_aarch64_negate_ra_sign_state)
|
2015-07-28 17:28:03 +00:00
|
|
|
.Case("blockaddress", MIToken::kw_blockaddress)
|
2016-07-29 20:32:59 +00:00
|
|
|
.Case("intrinsic", MIToken::kw_intrinsic)
|
2015-07-28 23:02:45 +00:00
|
|
|
.Case("target-index", MIToken::kw_target_index)
|
2015-07-31 20:49:21 +00:00
|
|
|
.Case("half", MIToken::kw_half)
|
|
|
|
.Case("float", MIToken::kw_float)
|
|
|
|
.Case("double", MIToken::kw_double)
|
|
|
|
.Case("x86_fp80", MIToken::kw_x86_fp80)
|
|
|
|
.Case("fp128", MIToken::kw_fp128)
|
|
|
|
.Case("ppc_fp128", MIToken::kw_ppc_fp128)
|
2015-08-06 00:44:07 +00:00
|
|
|
.Case("target-flags", MIToken::kw_target_flags)
|
2015-08-04 00:24:45 +00:00
|
|
|
.Case("volatile", MIToken::kw_volatile)
|
2015-08-06 16:49:30 +00:00
|
|
|
.Case("non-temporal", MIToken::kw_non_temporal)
|
[CodeGen] Split out the notions of MI invariance and MI dereferenceability.
Summary:
An IR load can be invariant, dereferenceable, neither, or both. But
currently, MI's notion of invariance is IR-invariant &&
IR-dereferenceable.
This patch splits up the notions of invariance and dereferenceability at
the MI level. It's NFC, so adds some probably-unnecessary
"is-dereferenceable" checks, which we can remove later if desired.
Reviewers: chandlerc, tstellarAMD
Subscribers: jholewinski, arsenm, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D23371
llvm-svn: 281151
2016-09-11 01:38:58 +00:00
|
|
|
.Case("dereferenceable", MIToken::kw_dereferenceable)
|
2015-08-06 16:55:53 +00:00
|
|
|
.Case("invariant", MIToken::kw_invariant)
|
2015-08-07 20:48:30 +00:00
|
|
|
.Case("align", MIToken::kw_align)
|
2018-01-26 11:47:28 +00:00
|
|
|
.Case("addrspace", MIToken::kw_addrspace)
|
2015-08-12 20:44:16 +00:00
|
|
|
.Case("stack", MIToken::kw_stack)
|
2015-08-12 21:00:22 +00:00
|
|
|
.Case("got", MIToken::kw_got)
|
2015-08-12 21:11:08 +00:00
|
|
|
.Case("jump-table", MIToken::kw_jump_table)
|
2015-08-12 20:33:26 +00:00
|
|
|
.Case("constant-pool", MIToken::kw_constant_pool)
|
2015-08-20 00:12:57 +00:00
|
|
|
.Case("call-entry", MIToken::kw_call_entry)
|
2015-08-10 23:24:42 +00:00
|
|
|
.Case("liveout", MIToken::kw_liveout)
|
2015-08-13 23:10:16 +00:00
|
|
|
.Case("address-taken", MIToken::kw_address_taken)
|
|
|
|
.Case("landing-pad", MIToken::kw_landing_pad)
|
|
|
|
.Case("liveins", MIToken::kw_liveins)
|
|
|
|
.Case("successors", MIToken::kw_successors)
|
2016-08-17 20:25:25 +00:00
|
|
|
.Case("floatpred", MIToken::kw_floatpred)
|
|
|
|
.Case("intpred", MIToken::kw_intpred)
|
2019-08-13 15:34:38 +00:00
|
|
|
.Case("shufflemask", MIToken::kw_shufflemask)
|
[x86/MIR] Implement support for pre- and post-instruction symbols, as
well as MIR parsing support for `MCSymbol` `MachineOperand`s.
The only real way to test pre- and post-instruction symbol support is to
use them in operands, so I ended up implementing that within the patch
as well. I can split out the operand support if folks really want but it
doesn't really seem worth it.
The functional implementation of pre- and post-instruction symbols is
now *completely trivial*. Two tiny bits of code in the (misnamed)
AsmPrinter. It should be completely target independent as well. We emit
these exactly the same way as we emit basic block labels. Most of the
code here is to give full dumping, MIR printing, and MIR parsing support
so that we can write useful tests.
The MIR parsing of MC symbol operands still isn't 100%, as it forces the
symbols to be non-temporary and non-local symbols with names. However,
those names often can encode most (if not all) of the special semantics
desired, and unnamed symbols seem especially annoying to serialize and
de-serialize. While this isn't perfect or full support, it seems plenty
to write tests that exercise usage of these kinds of operands.
The MIR support for pre-and post-instruction symbols was quite
straightforward. I chose to print them out in an as-if-operand syntax
similar to debug locations as this seemed the cleanest way and let me
use nice introducer tokens rather than inventing more magic punctuation
like we use for memoperands.
However, supporting MIR-based parsing of these symbols caused me to
change the design of the symbol support to allow setting arbitrary
symbols. Without this, I don't see any reasonable way to test things
with MIR.
Differential Revision: https://reviews.llvm.org/D50833
llvm-svn: 339962
2018-08-16 23:11:05 +00:00
|
|
|
.Case("pre-instr-symbol", MIToken::kw_pre_instr_symbol)
|
|
|
|
.Case("post-instr-symbol", MIToken::kw_post_instr_symbol)
|
2019-11-05 10:54:50 -08:00
|
|
|
.Case("heap-alloc-marker", MIToken::kw_heap_alloc_marker)
|
2018-08-20 20:37:57 +00:00
|
|
|
.Case("unknown-size", MIToken::kw_unknown_size)
|
2015-07-06 23:07:26 +00:00
|
|
|
.Default(MIToken::Identifier);
|
|
|
|
}
|
|
|
|
|
2015-06-30 16:51:29 +00:00
|
|
|
static Cursor maybeLexIdentifier(Cursor C, MIToken &Token) {
|
2016-07-26 21:49:34 +00:00
|
|
|
if (!isalpha(C.peek()) && C.peek() != '_')
|
2015-06-30 16:51:29 +00:00
|
|
|
return None;
|
2015-06-22 20:37:46 +00:00
|
|
|
auto Range = C;
|
|
|
|
while (isIdentifierChar(C.peek()))
|
|
|
|
C.advance();
|
2015-06-24 17:34:58 +00:00
|
|
|
auto Identifier = Range.upto(C);
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(getIdentifierKind(Identifier), Identifier)
|
|
|
|
.setStringValue(Identifier);
|
2015-06-22 20:37:46 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2016-03-18 20:41:11 +00:00
|
|
|
static Cursor maybeLexMachineBasicBlock(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
2015-08-13 23:10:16 +00:00
|
|
|
bool IsReference = C.remaining().startswith("%bb.");
|
|
|
|
if (!IsReference && !C.remaining().startswith("bb."))
|
2015-06-30 16:51:29 +00:00
|
|
|
return None;
|
2015-06-26 16:46:11 +00:00
|
|
|
auto Range = C;
|
2015-08-13 23:10:16 +00:00
|
|
|
unsigned PrefixLength = IsReference ? 4 : 3;
|
|
|
|
C.advance(PrefixLength); // Skip '%bb.' or 'bb.'
|
2015-06-26 16:46:11 +00:00
|
|
|
if (!isdigit(C.peek())) {
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(MIToken::Error, C.remaining());
|
2015-06-26 16:46:11 +00:00
|
|
|
ErrorCallback(C.location(), "expected a number after '%bb.'");
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
auto NumberRange = C;
|
|
|
|
while (isdigit(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
StringRef Number = NumberRange.upto(C);
|
2015-08-13 23:10:16 +00:00
|
|
|
unsigned StringOffset = PrefixLength + Number.size(); // Drop '%bb.<id>'
|
2017-12-04 17:18:51 +00:00
|
|
|
// TODO: The format bb.<id>.<irname> is supported only when it's not a
|
|
|
|
// reference. Once we deprecate the format where the irname shows up, we
|
|
|
|
// should only lex forward if it is a reference.
|
2015-06-26 16:46:11 +00:00
|
|
|
if (C.peek() == '.') {
|
|
|
|
C.advance(); // Skip '.'
|
|
|
|
++StringOffset;
|
|
|
|
while (isIdentifierChar(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
}
|
2015-08-13 23:10:16 +00:00
|
|
|
Token.reset(IsReference ? MIToken::MachineBasicBlock
|
|
|
|
: MIToken::MachineBasicBlockLabel,
|
|
|
|
Range.upto(C))
|
2015-08-06 23:17:42 +00:00
|
|
|
.setIntegerValue(APSInt(Number))
|
|
|
|
.setStringValue(Range.upto(C).drop_front(StringOffset));
|
2015-06-26 16:46:11 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-07-15 23:38:35 +00:00
|
|
|
static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule,
|
|
|
|
MIToken::TokenKind Kind) {
|
|
|
|
if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.size())))
|
|
|
|
return None;
|
|
|
|
auto Range = C;
|
|
|
|
C.advance(Rule.size());
|
|
|
|
auto NumberRange = C;
|
|
|
|
while (isdigit(C.peek()))
|
|
|
|
C.advance();
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(Kind, Range.upto(C)).setIntegerValue(APSInt(NumberRange.upto(C)));
|
2015-07-15 23:38:35 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:37:45 +00:00
|
|
|
static Cursor maybeLexIndexAndName(Cursor C, MIToken &Token, StringRef Rule,
|
|
|
|
MIToken::TokenKind Kind) {
|
|
|
|
if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.size())))
|
|
|
|
return None;
|
|
|
|
auto Range = C;
|
|
|
|
C.advance(Rule.size());
|
|
|
|
auto NumberRange = C;
|
|
|
|
while (isdigit(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
StringRef Number = NumberRange.upto(C);
|
|
|
|
unsigned StringOffset = Rule.size() + Number.size();
|
|
|
|
if (C.peek() == '.') {
|
|
|
|
C.advance();
|
|
|
|
++StringOffset;
|
|
|
|
while (isIdentifierChar(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
}
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(Kind, Range.upto(C))
|
|
|
|
.setIntegerValue(APSInt(Number))
|
|
|
|
.setStringValue(Range.upto(C).drop_front(StringOffset));
|
2015-07-16 23:37:45 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-07-15 23:38:35 +00:00
|
|
|
static Cursor maybeLexJumpTableIndex(Cursor C, MIToken &Token) {
|
|
|
|
return maybeLexIndex(C, Token, "%jump-table.", MIToken::JumpTableIndex);
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:37:45 +00:00
|
|
|
static Cursor maybeLexStackObject(Cursor C, MIToken &Token) {
|
|
|
|
return maybeLexIndexAndName(C, Token, "%stack.", MIToken::StackObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cursor maybeLexFixedStackObject(Cursor C, MIToken &Token) {
|
|
|
|
return maybeLexIndex(C, Token, "%fixed-stack.", MIToken::FixedStackObject);
|
|
|
|
}
|
|
|
|
|
2015-07-20 20:51:18 +00:00
|
|
|
static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token) {
|
|
|
|
return maybeLexIndex(C, Token, "%const.", MIToken::ConstantPoolItem);
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:18:46 +00:00
|
|
|
static Cursor maybeLexSubRegisterIndex(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
|
|
|
const StringRef Rule = "%subreg.";
|
|
|
|
if (!C.remaining().startswith(Rule))
|
|
|
|
return None;
|
|
|
|
return lexName(C, Token, MIToken::SubRegisterIndex, Rule.size(),
|
|
|
|
ErrorCallback);
|
|
|
|
}
|
|
|
|
|
2016-03-18 20:41:11 +00:00
|
|
|
static Cursor maybeLexIRBlock(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
2015-07-28 17:28:03 +00:00
|
|
|
const StringRef Rule = "%ir-block.";
|
|
|
|
if (!C.remaining().startswith(Rule))
|
|
|
|
return None;
|
|
|
|
if (isdigit(C.peek(Rule.size())))
|
|
|
|
return maybeLexIndex(C, Token, Rule, MIToken::IRBlock);
|
2015-08-05 17:35:55 +00:00
|
|
|
return lexName(C, Token, MIToken::NamedIRBlock, Rule.size(), ErrorCallback);
|
2015-07-27 22:42:41 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 20:41:11 +00:00
|
|
|
static Cursor maybeLexIRValue(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
2015-08-03 23:08:19 +00:00
|
|
|
const StringRef Rule = "%ir.";
|
|
|
|
if (!C.remaining().startswith(Rule))
|
|
|
|
return None;
|
2015-08-19 23:31:05 +00:00
|
|
|
if (isdigit(C.peek(Rule.size())))
|
|
|
|
return maybeLexIndex(C, Token, Rule, MIToken::IRValue);
|
2015-08-05 17:35:55 +00:00
|
|
|
return lexName(C, Token, MIToken::NamedIRValue, Rule.size(), ErrorCallback);
|
2015-08-03 23:08:19 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 22:23:00 +00:00
|
|
|
static Cursor maybeLexStringConstant(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
|
|
|
if (C.peek() != '"')
|
|
|
|
return None;
|
|
|
|
return lexName(C, Token, MIToken::StringConstant, /*PrefixLength=*/0,
|
|
|
|
ErrorCallback);
|
|
|
|
}
|
|
|
|
|
2015-07-10 22:51:20 +00:00
|
|
|
static Cursor lexVirtualRegister(Cursor C, MIToken &Token) {
|
|
|
|
auto Range = C;
|
|
|
|
C.advance(); // Skip '%'
|
|
|
|
auto NumberRange = C;
|
|
|
|
while (isdigit(C.peek()))
|
|
|
|
C.advance();
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(MIToken::VirtualRegister, Range.upto(C))
|
|
|
|
.setIntegerValue(APSInt(NumberRange.upto(C)));
|
2015-07-10 22:51:20 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2016-07-26 21:49:34 +00:00
|
|
|
/// Returns true for a character allowed in a register name.
|
|
|
|
static bool isRegisterChar(char C) {
|
|
|
|
return isIdentifierChar(C) && C != '.';
|
|
|
|
}
|
|
|
|
|
2018-03-30 18:15:54 +00:00
|
|
|
static Cursor lexNamedVirtualRegister(Cursor C, MIToken &Token) {
|
|
|
|
Cursor Range = C;
|
|
|
|
C.advance(); // Skip '%'
|
|
|
|
while (isRegisterChar(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
Token.reset(MIToken::NamedVirtualRegister, Range.upto(C))
|
|
|
|
.setStringValue(Range.upto(C).drop_front(1)); // Drop the '%'
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2018-01-31 22:04:26 +00:00
|
|
|
static Cursor maybeLexRegister(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
|
|
|
if (C.peek() != '%' && C.peek() != '$')
|
2015-06-30 16:51:29 +00:00
|
|
|
return None;
|
2018-01-31 22:04:26 +00:00
|
|
|
|
|
|
|
if (C.peek() == '%') {
|
|
|
|
if (isdigit(C.peek(1)))
|
|
|
|
return lexVirtualRegister(C, Token);
|
|
|
|
|
2018-03-30 18:15:54 +00:00
|
|
|
if (isRegisterChar(C.peek(1)))
|
|
|
|
return lexNamedVirtualRegister(C, Token);
|
|
|
|
|
2018-01-31 22:04:26 +00:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(C.peek() == '$');
|
2015-06-23 16:35:26 +00:00
|
|
|
auto Range = C;
|
2018-01-31 22:04:26 +00:00
|
|
|
C.advance(); // Skip '$'
|
2016-07-26 21:49:34 +00:00
|
|
|
while (isRegisterChar(C.peek()))
|
2015-06-23 16:35:26 +00:00
|
|
|
C.advance();
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(MIToken::NamedRegister, Range.upto(C))
|
2018-01-31 22:04:26 +00:00
|
|
|
.setStringValue(Range.upto(C).drop_front(1)); // Drop the '$'
|
2015-06-23 16:35:26 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2016-03-18 20:41:11 +00:00
|
|
|
static Cursor maybeLexGlobalValue(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
2015-07-21 21:23:08 +00:00
|
|
|
if (C.peek() != '@')
|
|
|
|
return None;
|
|
|
|
if (!isdigit(C.peek(1)))
|
2015-08-05 17:35:55 +00:00
|
|
|
return lexName(C, Token, MIToken::NamedGlobalValue, /*PrefixLength=*/1,
|
2015-07-21 21:23:08 +00:00
|
|
|
ErrorCallback);
|
|
|
|
auto Range = C;
|
|
|
|
C.advance(1); // Skip the '@'
|
|
|
|
auto NumberRange = C;
|
|
|
|
while (isdigit(C.peek()))
|
|
|
|
C.advance();
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(MIToken::GlobalValue, Range.upto(C))
|
|
|
|
.setIntegerValue(APSInt(NumberRange.upto(C)));
|
2015-07-21 21:23:08 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2016-03-18 20:41:11 +00:00
|
|
|
static Cursor maybeLexExternalSymbol(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
2018-01-10 00:56:48 +00:00
|
|
|
if (C.peek() != '&')
|
2015-07-21 16:59:53 +00:00
|
|
|
return None;
|
2015-08-05 17:35:55 +00:00
|
|
|
return lexName(C, Token, MIToken::ExternalSymbol, /*PrefixLength=*/1,
|
|
|
|
ErrorCallback);
|
2015-07-21 16:59:53 +00:00
|
|
|
}
|
|
|
|
|
[x86/MIR] Implement support for pre- and post-instruction symbols, as
well as MIR parsing support for `MCSymbol` `MachineOperand`s.
The only real way to test pre- and post-instruction symbol support is to
use them in operands, so I ended up implementing that within the patch
as well. I can split out the operand support if folks really want but it
doesn't really seem worth it.
The functional implementation of pre- and post-instruction symbols is
now *completely trivial*. Two tiny bits of code in the (misnamed)
AsmPrinter. It should be completely target independent as well. We emit
these exactly the same way as we emit basic block labels. Most of the
code here is to give full dumping, MIR printing, and MIR parsing support
so that we can write useful tests.
The MIR parsing of MC symbol operands still isn't 100%, as it forces the
symbols to be non-temporary and non-local symbols with names. However,
those names often can encode most (if not all) of the special semantics
desired, and unnamed symbols seem especially annoying to serialize and
de-serialize. While this isn't perfect or full support, it seems plenty
to write tests that exercise usage of these kinds of operands.
The MIR support for pre-and post-instruction symbols was quite
straightforward. I chose to print them out in an as-if-operand syntax
similar to debug locations as this seemed the cleanest way and let me
use nice introducer tokens rather than inventing more magic punctuation
like we use for memoperands.
However, supporting MIR-based parsing of these symbols caused me to
change the design of the symbol support to allow setting arbitrary
symbols. Without this, I don't see any reasonable way to test things
with MIR.
Differential Revision: https://reviews.llvm.org/D50833
llvm-svn: 339962
2018-08-16 23:11:05 +00:00
|
|
|
static Cursor maybeLexMCSymbol(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
|
|
|
const StringRef Rule = "<mcsymbol ";
|
|
|
|
if (!C.remaining().startswith(Rule))
|
|
|
|
return None;
|
|
|
|
auto Start = C;
|
|
|
|
C.advance(Rule.size());
|
|
|
|
|
|
|
|
// Try a simple unquoted name.
|
|
|
|
if (C.peek() != '"') {
|
|
|
|
while (isIdentifierChar(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
StringRef String = Start.upto(C).drop_front(Rule.size());
|
|
|
|
if (C.peek() != '>') {
|
|
|
|
ErrorCallback(C.location(),
|
|
|
|
"expected the '<mcsymbol ...' to be closed by a '>'");
|
|
|
|
Token.reset(MIToken::Error, Start.remaining());
|
|
|
|
return Start;
|
|
|
|
}
|
|
|
|
C.advance();
|
|
|
|
|
|
|
|
Token.reset(MIToken::MCSymbol, Start.upto(C)).setStringValue(String);
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise lex out a quoted name.
|
|
|
|
Cursor R = lexStringConstant(C, ErrorCallback);
|
|
|
|
if (!R) {
|
|
|
|
ErrorCallback(C.location(),
|
|
|
|
"unable to parse quoted string from opening quote");
|
|
|
|
Token.reset(MIToken::Error, Start.remaining());
|
|
|
|
return Start;
|
|
|
|
}
|
|
|
|
StringRef String = Start.upto(R).drop_front(Rule.size());
|
|
|
|
if (R.peek() != '>') {
|
|
|
|
ErrorCallback(R.location(),
|
|
|
|
"expected the '<mcsymbol ...' to be closed by a '>'");
|
|
|
|
Token.reset(MIToken::Error, Start.remaining());
|
|
|
|
return Start;
|
|
|
|
}
|
|
|
|
R.advance();
|
|
|
|
|
|
|
|
Token.reset(MIToken::MCSymbol, Start.upto(R))
|
|
|
|
.setOwnedStringValue(unescapeQuotedString(String));
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2015-07-31 20:49:21 +00:00
|
|
|
static bool isValidHexFloatingPointPrefix(char C) {
|
|
|
|
return C == 'H' || C == 'K' || C == 'L' || C == 'M';
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cursor lexFloatingPointLiteral(Cursor Range, Cursor C, MIToken &Token) {
|
|
|
|
C.advance();
|
|
|
|
// Skip over [0-9]*([eE][-+]?[0-9]+)?
|
|
|
|
while (isdigit(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
if ((C.peek() == 'e' || C.peek() == 'E') &&
|
|
|
|
(isdigit(C.peek(1)) ||
|
|
|
|
((C.peek(1) == '-' || C.peek(1) == '+') && isdigit(C.peek(2))))) {
|
|
|
|
C.advance(2);
|
|
|
|
while (isdigit(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
}
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
|
2015-07-31 20:49:21 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2016-10-12 21:06:45 +00:00
|
|
|
static Cursor maybeLexHexadecimalLiteral(Cursor C, MIToken &Token) {
|
|
|
|
if (C.peek() != '0' || (C.peek(1) != 'x' && C.peek(1) != 'X'))
|
|
|
|
return None;
|
|
|
|
Cursor Range = C;
|
|
|
|
C.advance(2);
|
|
|
|
unsigned PrefLen = 2;
|
|
|
|
if (isValidHexFloatingPointPrefix(C.peek())) {
|
|
|
|
C.advance();
|
|
|
|
PrefLen++;
|
|
|
|
}
|
|
|
|
while (isxdigit(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
StringRef StrVal = Range.upto(C);
|
|
|
|
if (StrVal.size() <= PrefLen)
|
|
|
|
return None;
|
|
|
|
if (PrefLen == 2)
|
|
|
|
Token.reset(MIToken::HexLiteral, Range.upto(C));
|
|
|
|
else // It must be 3, which means that there was a floating-point prefix.
|
|
|
|
Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-07-31 20:49:21 +00:00
|
|
|
static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token) {
|
2015-06-30 16:51:29 +00:00
|
|
|
if (!isdigit(C.peek()) && (C.peek() != '-' || !isdigit(C.peek(1))))
|
|
|
|
return None;
|
2015-06-23 23:42:28 +00:00
|
|
|
auto Range = C;
|
|
|
|
C.advance();
|
|
|
|
while (isdigit(C.peek()))
|
|
|
|
C.advance();
|
2015-07-31 20:49:21 +00:00
|
|
|
if (C.peek() == '.')
|
|
|
|
return lexFloatingPointLiteral(Range, C, Token);
|
2015-06-23 23:42:28 +00:00
|
|
|
StringRef StrVal = Range.upto(C);
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(MIToken::IntegerLiteral, StrVal).setIntegerValue(APSInt(StrVal));
|
2015-06-23 23:42:28 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-08-17 22:05:15 +00:00
|
|
|
static MIToken::TokenKind getMetadataKeywordKind(StringRef Identifier) {
|
|
|
|
return StringSwitch<MIToken::TokenKind>(Identifier)
|
|
|
|
.Case("!tbaa", MIToken::md_tbaa)
|
2015-08-17 22:06:40 +00:00
|
|
|
.Case("!alias.scope", MIToken::md_alias_scope)
|
2015-08-17 22:08:02 +00:00
|
|
|
.Case("!noalias", MIToken::md_noalias)
|
2015-08-17 22:09:52 +00:00
|
|
|
.Case("!range", MIToken::md_range)
|
2017-08-23 20:31:27 +00:00
|
|
|
.Case("!DIExpression", MIToken::md_diexpr)
|
[mir] Serialize DILocation inline when not possible to use a metadata reference
Summary:
Sometimes MIR-level passes create DILocations that were not present in the
LLVM-IR. For example, it may merge two DILocations together to produce a
DILocation that points to line 0.
Previously, the address of these DILocations were printed which prevented the
MIR from being read back into LLVM. With this patch, DILocations will use
metadata references where possible and fall back on serializing them inline like so:
MOV32mr %stack.0.x.addr, 1, _, 0, _, %0, debug-location !DILocation(line: 1, scope: !15)
Reviewers: aprantl, vsk, arphaman
Reviewed By: aprantl
Subscribers: probinson, llvm-commits
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D55243
llvm-svn: 349035
2018-12-13 14:25:27 +00:00
|
|
|
.Case("!DILocation", MIToken::md_dilocation)
|
2015-08-17 22:05:15 +00:00
|
|
|
.Default(MIToken::Error);
|
|
|
|
}
|
|
|
|
|
2019-11-05 10:54:50 -08:00
|
|
|
static Cursor maybeLexExclaim(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
2015-08-17 22:05:15 +00:00
|
|
|
if (C.peek() != '!')
|
|
|
|
return None;
|
|
|
|
auto Range = C;
|
|
|
|
C.advance(1);
|
|
|
|
if (isdigit(C.peek()) || !isIdentifierChar(C.peek())) {
|
|
|
|
Token.reset(MIToken::exclaim, Range.upto(C));
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
while (isIdentifierChar(C.peek()))
|
|
|
|
C.advance();
|
|
|
|
StringRef StrVal = Range.upto(C);
|
|
|
|
Token.reset(getMetadataKeywordKind(StrVal), StrVal);
|
|
|
|
if (Token.isError())
|
|
|
|
ErrorCallback(Token.location(),
|
|
|
|
"use of unknown metadata keyword '" + StrVal + "'");
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-06-23 16:35:26 +00:00
|
|
|
static MIToken::TokenKind symbolToken(char C) {
|
|
|
|
switch (C) {
|
|
|
|
case ',':
|
|
|
|
return MIToken::comma;
|
2016-07-26 21:49:34 +00:00
|
|
|
case '.':
|
|
|
|
return MIToken::dot;
|
2015-06-23 16:35:26 +00:00
|
|
|
case '=':
|
|
|
|
return MIToken::equal;
|
2015-07-13 23:24:34 +00:00
|
|
|
case ':':
|
|
|
|
return MIToken::colon;
|
2015-07-28 17:28:03 +00:00
|
|
|
case '(':
|
|
|
|
return MIToken::lparen;
|
|
|
|
case ')':
|
|
|
|
return MIToken::rparen;
|
2015-08-14 18:57:24 +00:00
|
|
|
case '{':
|
|
|
|
return MIToken::lbrace;
|
|
|
|
case '}':
|
|
|
|
return MIToken::rbrace;
|
2015-08-05 22:26:15 +00:00
|
|
|
case '+':
|
|
|
|
return MIToken::plus;
|
|
|
|
case '-':
|
|
|
|
return MIToken::minus;
|
2016-03-08 00:57:31 +00:00
|
|
|
case '<':
|
2016-03-08 02:00:43 +00:00
|
|
|
return MIToken::less;
|
2016-03-08 00:57:31 +00:00
|
|
|
case '>':
|
2016-03-08 02:00:43 +00:00
|
|
|
return MIToken::greater;
|
2015-06-23 16:35:26 +00:00
|
|
|
default:
|
|
|
|
return MIToken::Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-30 16:51:29 +00:00
|
|
|
static Cursor maybeLexSymbol(Cursor C, MIToken &Token) {
|
2015-08-03 23:08:19 +00:00
|
|
|
MIToken::TokenKind Kind;
|
|
|
|
unsigned Length = 1;
|
|
|
|
if (C.peek() == ':' && C.peek(1) == ':') {
|
|
|
|
Kind = MIToken::coloncolon;
|
|
|
|
Length = 2;
|
|
|
|
} else
|
|
|
|
Kind = symbolToken(C.peek());
|
2015-06-30 16:51:29 +00:00
|
|
|
if (Kind == MIToken::Error)
|
|
|
|
return None;
|
2015-06-23 16:35:26 +00:00
|
|
|
auto Range = C;
|
2015-08-03 23:08:19 +00:00
|
|
|
C.advance(Length);
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(Kind, Range.upto(C));
|
2015-06-23 16:35:26 +00:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-08-13 23:10:16 +00:00
|
|
|
static Cursor maybeLexNewline(Cursor C, MIToken &Token) {
|
|
|
|
if (!isNewlineChar(C.peek()))
|
|
|
|
return None;
|
|
|
|
auto Range = C;
|
|
|
|
C.advance();
|
|
|
|
Token.reset(MIToken::Newline, Range.upto(C));
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2016-03-18 20:41:11 +00:00
|
|
|
static Cursor maybeLexEscapedIRValue(Cursor C, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
2015-08-21 21:54:12 +00:00
|
|
|
if (C.peek() != '`')
|
|
|
|
return None;
|
|
|
|
auto Range = C;
|
|
|
|
C.advance();
|
|
|
|
auto StrRange = C;
|
|
|
|
while (C.peek() != '`') {
|
|
|
|
if (C.isEOF() || isNewlineChar(C.peek())) {
|
|
|
|
ErrorCallback(
|
|
|
|
C.location(),
|
|
|
|
"end of machine instruction reached before the closing '`'");
|
|
|
|
Token.reset(MIToken::Error, Range.remaining());
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
C.advance();
|
|
|
|
}
|
|
|
|
StringRef Value = StrRange.upto(C);
|
|
|
|
C.advance();
|
|
|
|
Token.reset(MIToken::QuotedIRValue, Range.upto(C)).setStringValue(Value);
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2016-03-18 20:41:11 +00:00
|
|
|
StringRef llvm::lexMIToken(StringRef Source, MIToken &Token,
|
|
|
|
ErrorCallbackType ErrorCallback) {
|
2015-08-13 23:10:16 +00:00
|
|
|
auto C = skipComment(skipWhitespace(Cursor(Source)));
|
2015-06-22 20:37:46 +00:00
|
|
|
if (C.isEOF()) {
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(MIToken::Eof, C.remaining());
|
2015-06-22 20:37:46 +00:00
|
|
|
return C.remaining();
|
|
|
|
}
|
|
|
|
|
2015-06-30 16:51:29 +00:00
|
|
|
if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback))
|
|
|
|
return R.remaining();
|
2015-08-13 23:10:16 +00:00
|
|
|
if (Cursor R = maybeLexIdentifier(C, Token))
|
|
|
|
return R.remaining();
|
2015-07-15 23:38:35 +00:00
|
|
|
if (Cursor R = maybeLexJumpTableIndex(C, Token))
|
|
|
|
return R.remaining();
|
2015-07-16 23:37:45 +00:00
|
|
|
if (Cursor R = maybeLexStackObject(C, Token))
|
|
|
|
return R.remaining();
|
|
|
|
if (Cursor R = maybeLexFixedStackObject(C, Token))
|
|
|
|
return R.remaining();
|
2015-07-20 20:51:18 +00:00
|
|
|
if (Cursor R = maybeLexConstantPoolItem(C, Token))
|
|
|
|
return R.remaining();
|
2016-03-28 18:18:46 +00:00
|
|
|
if (Cursor R = maybeLexSubRegisterIndex(C, Token, ErrorCallback))
|
|
|
|
return R.remaining();
|
2015-07-28 17:28:03 +00:00
|
|
|
if (Cursor R = maybeLexIRBlock(C, Token, ErrorCallback))
|
2015-07-27 22:42:41 +00:00
|
|
|
return R.remaining();
|
2015-08-03 23:08:19 +00:00
|
|
|
if (Cursor R = maybeLexIRValue(C, Token, ErrorCallback))
|
|
|
|
return R.remaining();
|
2018-01-31 22:04:26 +00:00
|
|
|
if (Cursor R = maybeLexRegister(C, Token, ErrorCallback))
|
2015-06-30 16:51:29 +00:00
|
|
|
return R.remaining();
|
2015-07-20 20:31:01 +00:00
|
|
|
if (Cursor R = maybeLexGlobalValue(C, Token, ErrorCallback))
|
2015-06-30 16:51:29 +00:00
|
|
|
return R.remaining();
|
2015-07-21 16:59:53 +00:00
|
|
|
if (Cursor R = maybeLexExternalSymbol(C, Token, ErrorCallback))
|
|
|
|
return R.remaining();
|
[x86/MIR] Implement support for pre- and post-instruction symbols, as
well as MIR parsing support for `MCSymbol` `MachineOperand`s.
The only real way to test pre- and post-instruction symbol support is to
use them in operands, so I ended up implementing that within the patch
as well. I can split out the operand support if folks really want but it
doesn't really seem worth it.
The functional implementation of pre- and post-instruction symbols is
now *completely trivial*. Two tiny bits of code in the (misnamed)
AsmPrinter. It should be completely target independent as well. We emit
these exactly the same way as we emit basic block labels. Most of the
code here is to give full dumping, MIR printing, and MIR parsing support
so that we can write useful tests.
The MIR parsing of MC symbol operands still isn't 100%, as it forces the
symbols to be non-temporary and non-local symbols with names. However,
those names often can encode most (if not all) of the special semantics
desired, and unnamed symbols seem especially annoying to serialize and
de-serialize. While this isn't perfect or full support, it seems plenty
to write tests that exercise usage of these kinds of operands.
The MIR support for pre-and post-instruction symbols was quite
straightforward. I chose to print them out in an as-if-operand syntax
similar to debug locations as this seemed the cleanest way and let me
use nice introducer tokens rather than inventing more magic punctuation
like we use for memoperands.
However, supporting MIR-based parsing of these symbols caused me to
change the design of the symbol support to allow setting arbitrary
symbols. Without this, I don't see any reasonable way to test things
with MIR.
Differential Revision: https://reviews.llvm.org/D50833
llvm-svn: 339962
2018-08-16 23:11:05 +00:00
|
|
|
if (Cursor R = maybeLexMCSymbol(C, Token, ErrorCallback))
|
|
|
|
return R.remaining();
|
2016-10-12 21:06:45 +00:00
|
|
|
if (Cursor R = maybeLexHexadecimalLiteral(C, Token))
|
2015-07-31 20:49:21 +00:00
|
|
|
return R.remaining();
|
|
|
|
if (Cursor R = maybeLexNumericalLiteral(C, Token))
|
2015-06-30 16:51:29 +00:00
|
|
|
return R.remaining();
|
2019-11-05 10:54:50 -08:00
|
|
|
if (Cursor R = maybeLexExclaim(C, Token, ErrorCallback))
|
2015-08-17 22:05:15 +00:00
|
|
|
return R.remaining();
|
2015-06-30 16:51:29 +00:00
|
|
|
if (Cursor R = maybeLexSymbol(C, Token))
|
|
|
|
return R.remaining();
|
2015-08-13 23:10:16 +00:00
|
|
|
if (Cursor R = maybeLexNewline(C, Token))
|
|
|
|
return R.remaining();
|
2015-08-21 21:54:12 +00:00
|
|
|
if (Cursor R = maybeLexEscapedIRValue(C, Token, ErrorCallback))
|
|
|
|
return R.remaining();
|
2017-07-11 22:23:00 +00:00
|
|
|
if (Cursor R = maybeLexStringConstant(C, Token, ErrorCallback))
|
|
|
|
return R.remaining();
|
2015-06-30 16:51:29 +00:00
|
|
|
|
2015-08-06 23:17:42 +00:00
|
|
|
Token.reset(MIToken::Error, C.remaining());
|
2015-06-22 20:37:46 +00:00
|
|
|
ErrorCallback(C.location(),
|
2015-06-30 16:51:29 +00:00
|
|
|
Twine("unexpected character '") + Twine(C.peek()) + "'");
|
2015-06-22 20:37:46 +00:00
|
|
|
return C.remaining();
|
|
|
|
}
|