[llvm] r322267 - Implementation of X86Operand::print.
Andrew V. Tischenko via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 11 02:31:01 PST 2018
Author: avt77
Date: Thu Jan 11 02:31:01 2018
New Revision: 322267
URL: http://llvm.org/viewvc/llvm-project?rev=322267&view=rev
Log:
Implementation of X86Operand::print.
Differential Revision: https://reviews.llvm.org/D41610
Modified:
llvm/trunk/lib/Target/X86/AsmParser/X86Operand.h
llvm/trunk/test/MC/X86/x86_64-asm-match.s
Modified: llvm/trunk/lib/Target/X86/AsmParser/X86Operand.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86Operand.h?rev=322267&r1=322266&r2=322267&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86Operand.h (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86Operand.h Thu Jan 11 02:31:01 2018
@@ -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 MCParsedAsmOp
};
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 MCParsedAsmOp
/// 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!");
Modified: llvm/trunk/test/MC/X86/x86_64-asm-match.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/x86_64-asm-match.s?rev=322267&r1=322266&r2=322267&view=diff
==============================================================================
--- llvm/trunk/test/MC/X86/x86_64-asm-match.s (original)
+++ llvm/trunk/test/MC/X86/x86_64-asm-match.s Thu Jan 11 02:31:01 2018
@@ -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
More information about the llvm-commits
mailing list