diff --git a/lib/Target/X86/Disassembler/X86Disassembler.cpp b/lib/Target/X86/Disassembler/X86Disassembler.cpp index 5658cf8df54..c36672578b4 100644 --- a/lib/Target/X86/Disassembler/X86Disassembler.cpp +++ b/lib/Target/X86/Disassembler/X86Disassembler.cpp @@ -787,13 +787,11 @@ static bool translateInstruction(MCInst &mcInst, mcInst.setOpcode(X86::XACQUIRE_PREFIX); } - int index; - insn.numImmediatesTranslated = 0; - for (index = 0; index < X86_MAX_OPERANDS; ++index) { - if (insn.operands[index].encoding != ENCODING_NONE) { - if (translateOperand(mcInst, insn.operands[index], insn, Dis)) { + for (const auto &Op : insn.operands) { + if (Op.encoding != ENCODING_NONE) { + if (translateOperand(mcInst, Op, insn, Dis)) { return true; } } diff --git a/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp b/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp index 918df138718..804606d917b 100644 --- a/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp +++ b/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp @@ -1663,7 +1663,6 @@ static int readMaskRegister(struct InternalInstruction* insn) { * @return - 0 if all operands could be read; nonzero otherwise. */ static int readOperands(struct InternalInstruction* insn) { - int index; int hasVVVV, needVVVV; int sawRegImm = 0; @@ -1674,8 +1673,8 @@ static int readOperands(struct InternalInstruction* insn) { hasVVVV = !readVVVV(insn); needVVVV = hasVVVV && (insn->vvvv != 0); - for (index = 0; index < X86_MAX_OPERANDS; ++index) { - switch (x86OperandSets[insn->spec->operands][index].encoding) { + for (const auto &Op : x86OperandSets[insn->spec->operands]) { + switch (Op.encoding) { case ENCODING_NONE: case ENCODING_SI: case ENCODING_DI: @@ -1684,7 +1683,7 @@ static int readOperands(struct InternalInstruction* insn) { case ENCODING_RM: if (readModRM(insn)) return -1; - if (fixupReg(insn, &x86OperandSets[insn->spec->operands][index])) + if (fixupReg(insn, &Op)) return -1; break; case ENCODING_CB: @@ -1706,14 +1705,14 @@ static int readOperands(struct InternalInstruction* insn) { } if (readImmediate(insn, 1)) return -1; - if (x86OperandSets[insn->spec->operands][index].type == TYPE_IMM3 && + if (Op.type == TYPE_IMM3 && insn->immediates[insn->numImmediatesConsumed - 1] > 7) return -1; - if (x86OperandSets[insn->spec->operands][index].type == TYPE_IMM5 && + if (Op.type == TYPE_IMM5 && insn->immediates[insn->numImmediatesConsumed - 1] > 31) return -1; - if (x86OperandSets[insn->spec->operands][index].type == TYPE_XMM128 || - x86OperandSets[insn->spec->operands][index].type == TYPE_XMM256) + if (Op.type == TYPE_XMM128 || + Op.type == TYPE_XMM256) sawRegImm = 1; break; case ENCODING_IW: @@ -1762,7 +1761,7 @@ static int readOperands(struct InternalInstruction* insn) { needVVVV = 0; /* Mark that we have found a VVVV operand. */ if (!hasVVVV) return -1; - if (fixupReg(insn, &x86OperandSets[insn->spec->operands][index])) + if (fixupReg(insn, &Op)) return -1; break; case ENCODING_WRITEMASK: @@ -1825,7 +1824,7 @@ int llvm::X86Disassembler::decodeInstruction( readOperands(insn)) return -1; - insn->operands = &x86OperandSets[insn->spec->operands][0]; + insn->operands = x86OperandSets[insn->spec->operands]; insn->length = insn->readerCursor - insn->startLocation; diff --git a/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h b/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h index 59d1862b5dd..8c45402ab5e 100644 --- a/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h +++ b/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h @@ -17,6 +17,7 @@ #define X86DISASSEMBLERDECODER_H #include "X86DisassemblerDecoderCommon.h" +#include "llvm/ADT/ArrayRef.h" namespace llvm { namespace X86Disassembler { @@ -620,7 +621,7 @@ struct InternalInstruction { uint8_t sibScale; SIBBase sibBase; - const OperandSpecifier *operands; + ArrayRef operands; }; /// \brief Decode one instruction and store the decoding results in diff --git a/lib/Target/X86/Disassembler/X86DisassemblerDecoderCommon.h b/lib/Target/X86/Disassembler/X86DisassemblerDecoderCommon.h index abe4bc2ff97..f59e0b6a8aa 100644 --- a/lib/Target/X86/Disassembler/X86DisassemblerDecoderCommon.h +++ b/lib/Target/X86/Disassembler/X86DisassemblerDecoderCommon.h @@ -481,7 +481,7 @@ enum ModifierType { }; #undef ENUM_ENTRY -static const int X86_MAX_OPERANDS = 5; +static const unsigned X86_MAX_OPERANDS = 5; /// Decoding mode for the Intel disassembler. 16-bit, 32-bit, and 64-bit mode /// are supported, and represent real mode, IA-32e, and IA-32e in 64-bit mode,