Implementation of X86Operand::print.

Differential Revision: https://reviews.llvm.org/D41610

llvm-svn: 322267
This commit is contained in:
Andrew V. Tischenko 2018-01-11 10:31:01 +00:00
parent 5481c2176e
commit d037b1446b
2 changed files with 87 additions and 42 deletions

View File

@ -10,6 +10,7 @@
#ifndef LLVM_LIB_TARGET_X86_ASMPARSER_X86OPERAND_H
#define LLVM_LIB_TARGET_X86_ASMPARSER_X86OPERAND_H
#include "InstPrinter/X86IntelInstPrinter.h"
#include "MCTargetDesc/X86MCTargetDesc.h"
#include "X86AsmParserCommon.h"
#include "llvm/ADT/STLExtras.h"
@ -77,7 +78,7 @@ struct X86Operand : public MCParsedAsmOperand {
};
X86Operand(KindTy K, SMLoc Start, SMLoc End)
: Kind(K), StartLoc(Start), EndLoc(End) {}
: Kind(K), StartLoc(Start), EndLoc(End) {}
StringRef getSymName() override { return SymName; }
void *getOpDecl() override { return OpDecl; }
@ -95,7 +96,52 @@ struct X86Operand : public MCParsedAsmOperand {
/// getOffsetOfLoc - Get the location of the offset operator.
SMLoc getOffsetOfLoc() const override { return OffsetOfLoc; }
void print(raw_ostream &OS) const override {}
void print(raw_ostream &OS) const override {
auto PrintImmValue = [&](const MCExpr *Val, const char *VName) {
if (Val->getKind() == MCExpr::Constant) {
if (auto Imm = cast<MCConstantExpr>(Val)->getValue())
OS << VName << Imm;
} else if (Val->getKind() == MCExpr::SymbolRef) {
if (auto *SRE = dyn_cast<MCSymbolRefExpr>(Val)) {
const MCSymbol &Sym = SRE->getSymbol();
if (auto SymName = Sym.getName().data())
OS << VName << SymName;
}
}
};
switch (Kind) {
case Token:
OS << Tok.Data;
break;
case Register:
OS << "Reg:" << X86IntelInstPrinter::getRegisterName(Reg.RegNo);
break;
case Immediate:
PrintImmValue(Imm.Val, "Imm:");
break;
case Prefix:
OS << "Prefix:" << Pref.Prefixes;
break;
case Memory:
OS << "Memory: ModeSize=" << Mem.ModeSize;
if (Mem.Size)
OS << ",Size=" << Mem.Size;
if (Mem.BaseReg)
OS << ",BaseReg=" << X86IntelInstPrinter::getRegisterName(Mem.BaseReg);
if (Mem.IndexReg)
OS << ",IndexReg="
<< X86IntelInstPrinter::getRegisterName(Mem.IndexReg);
if (Mem.Scale)
OS << ",Scale=" << Mem.Scale;
if (Mem.Disp)
PrintImmValue(Mem.Disp, ",Disp=");
if (Mem.SegReg)
OS << ",SegReg=" << X86IntelInstPrinter::getRegisterName(Mem.SegReg);
break;
}
}
StringRef getToken() const {
assert(Kind == Token && "Invalid access!");

View File

@ -2,46 +2,45 @@
// REQUIRES: asserts
// CHECK: AsmMatcher: found 4 encodings with mnemonic 'pshufb'
// CHECK:Trying to match opcode MMX_PSHUFBrr64
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 1 (): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK:Trying to match opcode PSHUFBrr
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 1 (): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK:Trying to match opcode PSHUFBrm
// CHECK: Matching formal operand class MCK_Mem128 against actual operand at index 1 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 2 (): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 3: actual operand index out of range Opcode result: complete match, selecting this opcode
// CHECK:AsmMatcher: found 2 encodings with mnemonic 'sha1rnds4'
// CHECK:Trying to match opcode SHA1RNDS4rri
// CHECK: Matching formal operand class MCK_ImmUnsignedi8 against actual operand at index 1 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 2 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 3 (): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 4: actual operand index out of range Opcode result: complete match, selecting this opcode
// CHECK:AsmMatcher: found 4 encodings with mnemonic 'pinsrw'
// CHECK:Trying to match opcode MMX_PINSRWirri
// CHECK: Matching formal operand class MCK_ImmUnsignedi8 against actual operand at index 1 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_GR32orGR64 against actual operand at index 2 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 3 (): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK:Trying to match opcode PINSRWrri
// CHECK: Matching formal operand class MCK_ImmUnsignedi8 against actual operand at index 1 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_GR32orGR64 against actual operand at index 2 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 3 (): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 4: actual operand index out of range Opcode result: complete match, selecting this opcode
// CHECK:AsmMatcher: found 2 encodings with mnemonic 'crc32l'
// CHECK:Trying to match opcode CRC32r32r32
// CHECK: Matching formal operand class MCK_GR32 against actual operand at index 1 (): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK:Trying to match opcode CRC32r32m32
// CHECK: Matching formal operand class MCK_Mem32 against actual operand at index 1 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_GR32 against actual operand at index 2 (): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 3: actual operand index out of range Opcode result: complete match, selecting this opcode
// CHECK:AsmMatcher: found 4 encodings with mnemonic 'punpcklbw'
// CHECK:Trying to match opcode MMX_PUNPCKLBWirr
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 1 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 2 (): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK:Trying to match opcode MMX_PUNPCKLBWirm
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 1 (): match success using generic matcher
// CHECK: Matching formal operand class MCK_Mem32 against actual operand at index 2 (): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 3: actual operand index out of range Opcode result: complete match, selecting this opcode
// CHECK: Trying to match opcode MMX_PSHUFBrr64
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 1 (Memory: ModeSize=64,BaseReg=rip,Scale=1,Disp=CPI1_0): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK: Trying to match opcode PSHUFBrr
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 1 (Memory: ModeSize=64,BaseReg=rip,Scale=1,Disp=CPI1_0): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK: Trying to match opcode PSHUFBrm
// CHECK: Matching formal operand class MCK_Mem128 against actual operand at index 1 (Memory: ModeSize=64,BaseReg=rip,Scale=1,Disp=CPI1_0): match success using generic matcher
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 2 (Reg:xmm1): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 3: actual operand index out of range Opcode result: complete match, selecting this opcode
// CHECK: AsmMatcher: found 2 encodings with mnemonic 'sha1rnds4'
// CHECK: Trying to match opcode SHA1RNDS4rri
// CHECK: Matching formal operand class MCK_ImmUnsignedi8 against actual operand at index 1 (Imm:1): match success using generic matcher
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 2 (Reg:xmm1): match success using generic matcher
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 3 (Reg:xmm2): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 4: actual operand index out of range Opcode result: complete match, selecting this opcode
// CHECK: AsmMatcher: found 4 encodings with mnemonic 'pinsrw'
// CHECK: Trying to match opcode MMX_PINSRWirri
// CHECK: Matching formal operand class MCK_ImmUnsignedi8 against actual operand at index 1 (Imm:3): match success using generic matcher
// CHECK: Matching formal operand class MCK_GR32orGR64 against actual operand at index 2 (Reg:ecx): match success using generic matcher
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 3 (Reg:xmm5): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK: Trying to match opcode PINSRWrri
// CHECK: Matching formal operand class MCK_ImmUnsignedi8 against actual operand at index 1 (Imm:3): match success using generic matcher
// CHECK: Matching formal operand class MCK_GR32orGR64 against actual operand at index 2 (Reg:ecx): match success using generic matcher
// CHECK: Matching formal operand class MCK_FR32 against actual operand at index 3 (Reg:xmm5): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 4: actual operand index out of range Opcode result: complete match, selecting this opcode
// CHECK: AsmMatcher: found 2 encodings with mnemonic 'crc32l'
// CHECK: Trying to match opcode CRC32r32r32
// CHECK: Matching formal operand class MCK_GR32 against actual operand at index 1 (Memory: ModeSize=64,BaseReg=rbx,IndexReg=rcx,Scale=8,Disp=3735928559,SegReg=gs): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK: Trying to match opcode CRC32r32m32
// CHECK: Matching formal operand class MCK_Mem32 against actual operand at index 1 (Memory: ModeSize=64,BaseReg=rbx,IndexReg=rcx,Scale=8,Disp=3735928559,SegReg=gs): match success using generic matcher
// CHECK: Matching formal operand class MCK_GR32 against actual operand at index 2 (Reg:ecx): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 3: actual operand index out of range Opcode result: complete match, selecting this opcode
// CHECK: AsmMatcher: found 4 encodings with mnemonic 'punpcklbw'
// CHECK: Trying to match opcode MMX_PUNPCKLBWirr
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 1 (Reg:mm0): match success using generic matcher
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 2 (Memory: ModeSize=64,Size=32,BaseReg=rsp,Scale=1): Opcode result: multiple operand mismatches, ignoring this opcode
// CHECK: Trying to match opcode MMX_PUNPCKLBWirm
// CHECK: Matching formal operand class MCK_VR64 against actual operand at index 1 (Reg:mm0): match success using generic matcher
// CHECK: Matching formal operand class MCK_Mem32 against actual operand at index 2 (Memory: ModeSize=64,Size=32,BaseReg=rsp,Scale=1): match success using generic matcher
// CHECK: Matching formal operand class InvalidMatchClass against actual operand at index 3: actual operand index out of range Opcode result: complete match, selecting this opcode
pshufb CPI1_0(%rip), %xmm1
sha1rnds4 $1, %xmm1, %xmm2