Skip to content

Commit daf38d7

Browse files
alecmocattaaidanhs
authored andcommitted
neater matching
1 parent 49356d3 commit daf38d7

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

lib/Target/X86/MCTargetDesc/X86MCHadeanMatcher.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,43 +80,34 @@ bool HadeanMatcher::matches(const MCOperand &ref, const MCOperand &provided) con
8080
return false;
8181
}
8282

83-
HadeanMatcher::HadeanMatcher(const Triple &_triple) : triple(_triple) {
83+
HadeanMatcher::HadeanMatcher(const Triple &_triple) : triple(_triple), progress(0) {
8484
std::string error;
8585

86-
const Target *target = TargetRegistry::lookupTarget(triple.getTriple(), error);
87-
assert(target != nullptr);
86+
const Target *target = TargetRegistry::lookupTarget(triple.getTriple(), error); assert(target != nullptr);
8887

89-
MCRegisterInfo *MRI = target->createMCRegInfo(triple.getTriple());
90-
assert(MRI != nullptr);
88+
MCRegisterInfo *MRI = target->createMCRegInfo(triple.getTriple()); assert(MRI != nullptr);
9189

92-
MCAsmInfo *MAI = target->createMCAsmInfo(*MRI, triple.getTriple());
93-
assert(MAI != nullptr);
90+
MCAsmInfo *MAI = target->createMCAsmInfo(*MRI, triple.getTriple()); assert(MAI != nullptr);
9491

95-
MCContext *context = new MCContext(MAI, MRI, nullptr);
96-
assert(context != nullptr);
92+
MCContext *context = new MCContext(MAI, MRI, nullptr); assert(context != nullptr);
9793

9894
holder.reset(new Holder(context));
9995
HadeanExpander expander;
10096
expander.emitValidatedJump(*holder);
10197
assert(holder->numInstructions() != 0);
10298
}
10399

104-
void HadeanMatcher::feedInstruction(const MCInst &instr) {
105-
current.push_back(instr);
106-
107-
if (current.size() > holder->numInstructions())
108-
current.pop_front();
109-
}
110-
111-
bool HadeanMatcher::isValidatedJump() const {
112-
if (current.size() == holder->numInstructions()) {
113-
for(size_t i = 0; i < current.size(); ++i) {
114-
if (!matches(holder->getInstruction(i), current[i]))
115-
return false;
100+
enum HadeanMatcherState HadeanMatcher::feedInstruction(const MCInst &instr) {
101+
if (matches(holder->getInstruction(progress), instr)) {
102+
progress++;
103+
if (progress == holder->numInstructions()) {
104+
progress = 0;
105+
return HadeanMatcherStateValid;
116106
}
117-
return true;
107+
return HadeanMatcherStateUnknown;
118108
} else {
119-
return false;
109+
progress = 0;
110+
return HadeanMatcherStateInvalid;
120111
}
121112
}
122113

lib/Target/X86/MCTargetDesc/X86MCHadeanMatcher.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,23 @@ class Holder : public MCOutputTarget {
2727

2828
}
2929

30+
enum HadeanMatcherState {
31+
HadeanMatcherStateUnknown,
32+
HadeanMatcherStateInvalid,
33+
HadeanMatcherStateValid
34+
};
35+
3036
class HadeanMatcher {
3137
private:
3238
Triple triple;
3339
std::unique_ptr<Holder> holder;
34-
std::deque<MCInst> current;
40+
size_t progress;
3541
bool matches(const MCInst &ref, const MCInst &provided) const;
3642
bool matches(const MCOperand &ref, const MCOperand &provided) const;
3743

3844
public:
3945
HadeanMatcher(const Triple& triple);
40-
void feedInstruction(const MCInst &instr);
41-
bool isValidatedJump() const;
46+
enum HadeanMatcherState feedInstruction(const MCInst &instr);
4247
};
4348

4449
}

0 commit comments

Comments
 (0)