Skip to content

Commit

Permalink
neater matching
Browse files Browse the repository at this point in the history
  • Loading branch information
alecmocatta authored and aidanhs committed Jan 12, 2017
1 parent 49356d3 commit daf38d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
37 changes: 14 additions & 23 deletions lib/Target/X86/MCTargetDesc/X86MCHadeanMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,43 +80,34 @@ bool HadeanMatcher::matches(const MCOperand &ref, const MCOperand &provided) con
return false;
}

HadeanMatcher::HadeanMatcher(const Triple &_triple) : triple(_triple) {
HadeanMatcher::HadeanMatcher(const Triple &_triple) : triple(_triple), progress(0) {
std::string error;

const Target *target = TargetRegistry::lookupTarget(triple.getTriple(), error);
assert(target != nullptr);
const Target *target = TargetRegistry::lookupTarget(triple.getTriple(), error); assert(target != nullptr);

MCRegisterInfo *MRI = target->createMCRegInfo(triple.getTriple());
assert(MRI != nullptr);
MCRegisterInfo *MRI = target->createMCRegInfo(triple.getTriple()); assert(MRI != nullptr);

MCAsmInfo *MAI = target->createMCAsmInfo(*MRI, triple.getTriple());
assert(MAI != nullptr);
MCAsmInfo *MAI = target->createMCAsmInfo(*MRI, triple.getTriple()); assert(MAI != nullptr);

MCContext *context = new MCContext(MAI, MRI, nullptr);
assert(context != nullptr);
MCContext *context = new MCContext(MAI, MRI, nullptr); assert(context != nullptr);

holder.reset(new Holder(context));
HadeanExpander expander;
expander.emitValidatedJump(*holder);
assert(holder->numInstructions() != 0);
}

void HadeanMatcher::feedInstruction(const MCInst &instr) {
current.push_back(instr);

if (current.size() > holder->numInstructions())
current.pop_front();
}

bool HadeanMatcher::isValidatedJump() const {
if (current.size() == holder->numInstructions()) {
for(size_t i = 0; i < current.size(); ++i) {
if (!matches(holder->getInstruction(i), current[i]))
return false;
enum HadeanMatcherState HadeanMatcher::feedInstruction(const MCInst &instr) {
if (matches(holder->getInstruction(progress), instr)) {
progress++;
if (progress == holder->numInstructions()) {
progress = 0;
return HadeanMatcherStateValid;
}
return true;
return HadeanMatcherStateUnknown;
} else {
return false;
progress = 0;
return HadeanMatcherStateInvalid;
}
}

Expand Down
11 changes: 8 additions & 3 deletions lib/Target/X86/MCTargetDesc/X86MCHadeanMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@ class Holder : public MCOutputTarget {

}

enum HadeanMatcherState {
HadeanMatcherStateUnknown,
HadeanMatcherStateInvalid,
HadeanMatcherStateValid
};

class HadeanMatcher {
private:
Triple triple;
std::unique_ptr<Holder> holder;
std::deque<MCInst> current;
size_t progress;
bool matches(const MCInst &ref, const MCInst &provided) const;
bool matches(const MCOperand &ref, const MCOperand &provided) const;

public:
HadeanMatcher(const Triple& triple);
void feedInstruction(const MCInst &instr);
bool isValidatedJump() const;
enum HadeanMatcherState feedInstruction(const MCInst &instr);
};

}
Expand Down

0 comments on commit daf38d7

Please sign in to comment.