X86 asm parser: Use a loop to disambiguate suffixes instead of copy paste

This works towards making the Intel syntax asm matcher use a completely
different disambiguation strategy.

No functional change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214352 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Kleckner
2014-07-30 22:23:11 +00:00
parent cb99212bc1
commit 7af08a4a9b

View File

@@ -32,6 +32,7 @@
#include "llvm/Support/SourceMgr.h" #include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <memory> #include <memory>
using namespace llvm; using namespace llvm;
@@ -2389,34 +2390,18 @@ bool X86AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
const char *Suffixes = Base[0] != 'f' ? "bwlq" : "slt\0"; const char *Suffixes = Base[0] != 'f' ? "bwlq" : "slt\0";
// Check for the various suffix matches. // Check for the various suffix matches.
Tmp[Base.size()] = Suffixes[0];
unsigned ErrorInfoIgnore; unsigned ErrorInfoIgnore;
unsigned ErrorInfoMissingFeature = 0; // Init suppresses compiler warnings. unsigned ErrorInfoMissingFeature = 0; // Init suppresses compiler warnings.
unsigned Match1, Match2, Match3, Match4; unsigned Match[4];
Match1 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore, for (unsigned I = 0, E = array_lengthof(Match); I != E; ++I) {
MatchingInlineAsm, isParsingIntelSyntax()); Tmp.back() = Suffixes[I];
// If this returned as a missing feature failure, remember that. Match[I] = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
if (Match1 == Match_MissingFeature) MatchingInlineAsm, isParsingIntelSyntax());
ErrorInfoMissingFeature = ErrorInfoIgnore; // If this returned as a missing feature failure, remember that.
Tmp[Base.size()] = Suffixes[1]; if (Match[I] == Match_MissingFeature)
Match2 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore, ErrorInfoMissingFeature = ErrorInfoIgnore;
MatchingInlineAsm, isParsingIntelSyntax()); }
// If this returned as a missing feature failure, remember that.
if (Match2 == Match_MissingFeature)
ErrorInfoMissingFeature = ErrorInfoIgnore;
Tmp[Base.size()] = Suffixes[2];
Match3 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
MatchingInlineAsm, isParsingIntelSyntax());
// If this returned as a missing feature failure, remember that.
if (Match3 == Match_MissingFeature)
ErrorInfoMissingFeature = ErrorInfoIgnore;
Tmp[Base.size()] = Suffixes[3];
Match4 = MatchInstructionImpl(Operands, Inst, ErrorInfoIgnore,
MatchingInlineAsm, isParsingIntelSyntax());
// If this returned as a missing feature failure, remember that.
if (Match4 == Match_MissingFeature)
ErrorInfoMissingFeature = ErrorInfoIgnore;
// Restore the old token. // Restore the old token.
Op.setTokenValue(Base); Op.setTokenValue(Base);
@@ -2425,8 +2410,7 @@ bool X86AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
// instruction will already have been filled in correctly, since the failing // instruction will already have been filled in correctly, since the failing
// matches won't have modified it). // matches won't have modified it).
unsigned NumSuccessfulMatches = unsigned NumSuccessfulMatches =
(Match1 == Match_Success) + (Match2 == Match_Success) + std::count(std::begin(Match), std::end(Match), Match_Success);
(Match3 == Match_Success) + (Match4 == Match_Success);
if (NumSuccessfulMatches == 1) { if (NumSuccessfulMatches == 1) {
Inst.setLoc(IDLoc); Inst.setLoc(IDLoc);
if (!MatchingInlineAsm) if (!MatchingInlineAsm)
@@ -2442,10 +2426,9 @@ bool X86AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
if (NumSuccessfulMatches > 1) { if (NumSuccessfulMatches > 1) {
char MatchChars[4]; char MatchChars[4];
unsigned NumMatches = 0; unsigned NumMatches = 0;
if (Match1 == Match_Success) MatchChars[NumMatches++] = Suffixes[0]; for (unsigned I = 0, E = array_lengthof(Match); I != E; ++I)
if (Match2 == Match_Success) MatchChars[NumMatches++] = Suffixes[1]; if (Match[I] == Match_Success)
if (Match3 == Match_Success) MatchChars[NumMatches++] = Suffixes[2]; MatchChars[NumMatches++] = Suffixes[I];
if (Match4 == Match_Success) MatchChars[NumMatches++] = Suffixes[3];
SmallString<126> Msg; SmallString<126> Msg;
raw_svector_ostream OS(Msg); raw_svector_ostream OS(Msg);
@@ -2466,8 +2449,7 @@ bool X86AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
// If all of the instructions reported an invalid mnemonic, then the original // If all of the instructions reported an invalid mnemonic, then the original
// mnemonic was invalid. // mnemonic was invalid.
if ((Match1 == Match_MnemonicFail) && (Match2 == Match_MnemonicFail) && if (std::count(std::begin(Match), std::end(Match), Match_MnemonicFail) == 4) {
(Match3 == Match_MnemonicFail) && (Match4 == Match_MnemonicFail)) {
if (!WasOriginallyInvalidOperand) { if (!WasOriginallyInvalidOperand) {
ArrayRef<SMRange> Ranges = ArrayRef<SMRange> Ranges =
MatchingInlineAsm ? EmptyRanges : Op.getLocRange(); MatchingInlineAsm ? EmptyRanges : Op.getLocRange();
@@ -2495,8 +2477,8 @@ bool X86AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
// If one instruction matched with a missing feature, report this as a // If one instruction matched with a missing feature, report this as a
// missing feature. // missing feature.
if ((Match1 == Match_MissingFeature) + (Match2 == Match_MissingFeature) + if (std::count(std::begin(Match), std::end(Match),
(Match3 == Match_MissingFeature) + (Match4 == Match_MissingFeature) == 1){ Match_MissingFeature) == 1) {
std::string Msg = "instruction requires:"; std::string Msg = "instruction requires:";
unsigned Mask = 1; unsigned Mask = 1;
for (unsigned i = 0; i < (sizeof(ErrorInfoMissingFeature)*8-1); ++i) { for (unsigned i = 0; i < (sizeof(ErrorInfoMissingFeature)*8-1); ++i) {
@@ -2511,8 +2493,8 @@ bool X86AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
// If one instruction matched with an invalid operand, report this as an // If one instruction matched with an invalid operand, report this as an
// operand failure. // operand failure.
if ((Match1 == Match_InvalidOperand) + (Match2 == Match_InvalidOperand) + if (std::count(std::begin(Match), std::end(Match),
(Match3 == Match_InvalidOperand) + (Match4 == Match_InvalidOperand) == 1){ Match_InvalidOperand) == 1) {
Error(IDLoc, "invalid operand for instruction", EmptyRanges, Error(IDLoc, "invalid operand for instruction", EmptyRanges,
MatchingInlineAsm); MatchingInlineAsm);
return true; return true;