@@ -119,6 +119,8 @@ class VPTStatus {
119
119
class ARMDisassembler : public MCDisassembler {
120
120
public:
121
121
std::unique_ptr<const MCInstrInfo> MCII;
122
+ mutable ITStatus ITBlock;
123
+ mutable VPTStatus VPTBlock;
122
124
123
125
ARMDisassembler (const MCSubtargetInfo &STI, MCContext &Ctx,
124
126
const MCInstrInfo *MCII)
@@ -146,10 +148,6 @@ class ARMDisassembler : public MCDisassembler {
146
148
ArrayRef<uint8_t > Bytes, uint64_t Address,
147
149
raw_ostream &CStream) const ;
148
150
149
- mutable ITStatus ITBlock;
150
- mutable VPTStatus VPTBlock;
151
-
152
- void AddThumb1SBit (MCInst &MI, bool InITBlock) const ;
153
151
bool isVectorPredicable (const MCInst &MI) const ;
154
152
DecodeStatus AddThumbPredicate (MCInst&) const ;
155
153
void UpdateThumbPredicate (DecodeStatus &S, MCInst &MI) const ;
@@ -636,6 +634,17 @@ static DecodeStatus DecodeCCOutOperand(MCInst &Inst, unsigned Val,
636
634
return MCDisassembler::Success;
637
635
}
638
636
637
+ // This overload is called when decoding `s_cc_out` operand, which is not
638
+ // encoded into instruction. It is only used in Thumb1 instructions.
639
+ static DecodeStatus DecodeCCOutOperand (MCInst &Inst,
640
+ const MCDisassembler *Decoder) {
641
+ const auto *D = static_cast <const ARMDisassembler *>(Decoder);
642
+ // Thumb1 instructions define CPSR unless they are inside an IT block.
643
+ MCRegister CCR = D->ITBlock .instrInITBlock () ? ARM::NoRegister : ARM::CPSR;
644
+ Inst.addOperand (MCOperand::createReg (CCR));
645
+ return MCDisassembler::Success;
646
+ }
647
+
639
648
static DecodeStatus DecodeSORegImmOperand (MCInst &Inst, unsigned Val,
640
649
uint64_t Address,
641
650
const MCDisassembler *Decoder) {
@@ -6130,26 +6139,6 @@ DecodeStatus ARMDisassembler::getARMInstruction(MCInst &MI, uint64_t &Size,
6130
6139
return MCDisassembler::Fail;
6131
6140
}
6132
6141
6133
- // Thumb1 instructions don't have explicit S bits. Rather, they
6134
- // implicitly set CPSR. Since it's not represented in the encoding, the
6135
- // auto-generated decoder won't inject the CPSR operand. We need to fix
6136
- // that as a post-pass.
6137
- void ARMDisassembler::AddThumb1SBit (MCInst &MI, bool InITBlock) const {
6138
- const MCInstrDesc &MCID = MCII->get (MI.getOpcode ());
6139
- MCInst::iterator I = MI.begin ();
6140
- for (unsigned i = 0 ; i < MCID.NumOperands ; ++i, ++I) {
6141
- if (I == MI.end ()) break ;
6142
- if (MCID.operands ()[i].isOptionalDef () &&
6143
- MCID.operands ()[i].RegClass == ARM::CCRRegClassID) {
6144
- if (i > 0 && MCID.operands ()[i - 1 ].isPredicate ())
6145
- continue ;
6146
- MI.insert (I,
6147
- MCOperand::createReg (InITBlock ? ARM::NoRegister : ARM::CPSR));
6148
- return ;
6149
- }
6150
- }
6151
- }
6152
-
6153
6142
bool ARMDisassembler::isVectorPredicable (const MCInst &MI) const {
6154
6143
const MCInstrDesc &MCID = MCII->get (MI.getOpcode ());
6155
6144
for (unsigned i = 0 ; i < MCID.NumOperands ; ++i) {
@@ -6343,9 +6332,7 @@ DecodeStatus ARMDisassembler::getThumbInstruction(MCInst &MI, uint64_t &Size,
6343
6332
STI);
6344
6333
if (Result) {
6345
6334
Size = 2 ;
6346
- bool InITBlock = ITBlock.instrInITBlock ();
6347
6335
Check (Result, AddThumbPredicate (MI));
6348
- AddThumb1SBit (MI, InITBlock);
6349
6336
return Result;
6350
6337
}
6351
6338
@@ -6411,9 +6398,7 @@ DecodeStatus ARMDisassembler::getThumbInstruction(MCInst &MI, uint64_t &Size,
6411
6398
decodeInstruction (DecoderTableThumb32, MI, Insn32, Address, this , STI);
6412
6399
if (Result != MCDisassembler::Fail) {
6413
6400
Size = 4 ;
6414
- bool InITBlock = ITBlock.instrInITBlock ();
6415
6401
Check (Result, AddThumbPredicate (MI));
6416
- AddThumb1SBit (MI, InITBlock);
6417
6402
return Result;
6418
6403
}
6419
6404
0 commit comments