factor the print method better.

llvm-svn: 97125
This commit is contained in:
Chris Lattner 2010-02-25 06:53:39 +00:00
parent ba8ec9a9e4
commit 1f2adb6f35
2 changed files with 69 additions and 100 deletions

View File

@ -16,176 +16,148 @@
using namespace llvm;
void Matcher::dump() const {
print(errs());
print(errs(), 0);
}
void Matcher::printNext(raw_ostream &OS, unsigned indent) const {
void Matcher::print(raw_ostream &OS, unsigned indent) const {
printImpl(OS, indent);
if (Next)
return Next->print(OS, indent);
}
void ScopeMatcher::print(raw_ostream &OS, unsigned indent) const {
void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "Scope\n";
Check->print(OS, indent+2);
printNext(OS, indent);
}
void RecordMatcher::print(raw_ostream &OS, unsigned indent) const {
void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "Record\n";
printNext(OS, indent);
}
void RecordChildMatcher::print(raw_ostream &OS, unsigned indent) const {
void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
printNext(OS, indent);
}
void RecordMemRefMatcher::print(raw_ostream &OS, unsigned indent) const {
void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "RecordMemRef\n";
printNext(OS, indent);
}
void CaptureFlagInputMatcher::print(raw_ostream &OS, unsigned indent) const{
void CaptureFlagInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
OS.indent(indent) << "CaptureFlagInput\n";
printNext(OS, indent);
}
void MoveChildMatcher::print(raw_ostream &OS, unsigned indent) const {
void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "MoveChild " << ChildNo << '\n';
printNext(OS, indent);
}
void MoveParentMatcher::print(raw_ostream &OS, unsigned indent) const {
void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "MoveParent\n";
printNext(OS, indent);
}
void CheckSameMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
printNext(OS, indent);
}
void CheckPatternPredicateMatcher::
print(raw_ostream &OS, unsigned indent) const {
printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
printNext(OS, indent);
}
void CheckPredicateMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckPredicate " << PredName << '\n';
printNext(OS, indent);
}
void CheckOpcodeMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckOpcode " << OpcodeName << '\n';
printNext(OS, indent);
}
void CheckMultiOpcodeMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckMultiOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
OS.indent(indent) << "CheckMultiOpcode <todo args>\n";
printNext(OS, indent);
}
void CheckTypeMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckType " << getEnumName(Type) << '\n';
printNext(OS, indent);
}
void CheckChildTypeMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckChildType " << ChildNo << " "
<< getEnumName(Type) << '\n';
printNext(OS, indent);
}
void CheckIntegerMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckInteger " << Value << '\n';
printNext(OS, indent);
}
void CheckCondCodeMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
printNext(OS, indent);
}
void CheckValueTypeMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
printNext(OS, indent);
}
void CheckComplexPatMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
printNext(OS, indent);
}
void CheckAndImmMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckAndImm " << Value << '\n';
printNext(OS, indent);
}
void CheckOrImmMatcher::print(raw_ostream &OS, unsigned indent) const {
void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckOrImm " << Value << '\n';
printNext(OS, indent);
}
void CheckFoldableChainNodeMatcher::print(raw_ostream &OS,
void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
unsigned indent) const {
OS.indent(indent) << "CheckFoldableChainNode\n";
printNext(OS, indent);
}
void CheckChainCompatibleMatcher::print(raw_ostream &OS,
void CheckChainCompatibleMatcher::printImpl(raw_ostream &OS,
unsigned indent) const {
OS.indent(indent) << "CheckChainCompatible " << PreviousOp << "\n";
printNext(OS, indent);
}
void EmitIntegerMatcher::print(raw_ostream &OS, unsigned indent) const {
void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n';
printNext(OS, indent);
}
void EmitStringIntegerMatcher::
print(raw_ostream &OS, unsigned indent) const {
printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n';
printNext(OS, indent);
}
void EmitRegisterMatcher::print(raw_ostream &OS, unsigned indent) const {
void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "EmitRegister ";
if (Reg)
OS << Reg->getName();
else
OS << "zero_reg";
OS << " VT=" << VT << '\n';
printNext(OS, indent);
}
void EmitConvertToTargetMatcher::
print(raw_ostream &OS, unsigned indent) const {
printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
printNext(OS, indent);
}
void EmitMergeInputChainsMatcher::
print(raw_ostream &OS, unsigned indent) const {
printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
printNext(OS, indent);
}
void EmitCopyToRegMatcher::print(raw_ostream &OS, unsigned indent) const {
void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
printNext(OS, indent);
}
void EmitNodeXFormMatcher::print(raw_ostream &OS, unsigned indent) const {
void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
<< " Slot=" << Slot << '\n';
printNext(OS, indent);
}
void EmitNodeMatcher::print(raw_ostream &OS, unsigned indent) const {
void EmitNodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "EmitNode: " << OpcodeName << ": <todo flags> ";
for (unsigned i = 0, e = VTs.size(); i != e; ++i)
@ -194,19 +166,16 @@ void EmitNodeMatcher::print(raw_ostream &OS, unsigned indent) const {
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
OS << Operands[i] << ' ';
OS << ")\n";
printNext(OS, indent);
}
void MarkFlagResultsMatcher::print(raw_ostream &OS, unsigned indent) const {
void MarkFlagResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "MarkFlagResults <todo: args>\n";
printNext(OS, indent);
}
void CompleteMatchMatcher::print(raw_ostream &OS, unsigned indent) const {
void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CompleteMatch <todo args>\n";
OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
printNext(OS, indent);
}
// getHashImpl Implementation.

View File

@ -103,10 +103,10 @@ public:
return (getHashImpl() << 4) ^ getKind();
}
virtual void print(raw_ostream &OS, unsigned indent = 0) const = 0;
void print(raw_ostream &OS, unsigned indent = 0) const;
void dump() const;
protected:
void printNext(raw_ostream &OS, unsigned indent) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
virtual bool isEqualImpl(const Matcher *M) const = 0;
virtual unsigned getHashImpl() const = 0;
};
@ -132,7 +132,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return false; }
virtual unsigned getHashImpl() const { return 0; }
};
@ -153,7 +153,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return true; }
virtual unsigned getHashImpl() const { return 0; }
};
@ -179,7 +179,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo();
}
@ -196,7 +196,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return true; }
virtual unsigned getHashImpl() const { return 0; }
};
@ -213,7 +213,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return true; }
virtual unsigned getHashImpl() const { return 0; }
};
@ -232,7 +232,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo();
}
@ -250,7 +250,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return true; }
virtual unsigned getHashImpl() const { return 0; }
};
@ -271,7 +271,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber();
}
@ -294,7 +294,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate;
}
@ -316,7 +316,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckPredicateMatcher>(M)->PredName == PredName;
}
@ -339,7 +339,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckOpcodeMatcher>(M)->OpcodeName == OpcodeName;
}
@ -362,7 +362,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckMultiOpcodeMatcher>(M)->OpcodeNames == OpcodeNames;
}
@ -386,7 +386,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckTypeMatcher>(this)->Type == Type;
}
@ -410,7 +410,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
cast<CheckChildTypeMatcher>(M)->Type == Type;
@ -434,7 +434,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckIntegerMatcher>(M)->Value == Value;
}
@ -456,7 +456,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
}
@ -478,7 +478,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
}
@ -502,7 +502,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern;
}
@ -526,7 +526,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckAndImmMatcher>(M)->Value == Value;
}
@ -548,7 +548,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckOrImmMatcher>(M)->Value == Value;
}
@ -567,7 +567,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return true; }
virtual unsigned getHashImpl() const { return 0; }
};
@ -587,7 +587,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CheckChainCompatibleMatcher>(this)->PreviousOp == PreviousOp;
}
@ -610,7 +610,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<EmitIntegerMatcher>(M)->Val == Val &&
cast<EmitIntegerMatcher>(M)->VT == VT;
@ -635,7 +635,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
cast<EmitStringIntegerMatcher>(M)->VT == VT;
@ -661,7 +661,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
cast<EmitRegisterMatcher>(M)->VT == VT;
@ -687,7 +687,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
}
@ -716,7 +716,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
}
@ -741,7 +741,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
@ -770,7 +770,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
@ -826,7 +826,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const;
virtual unsigned getHashImpl() const;
};
@ -852,7 +852,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<MarkFlagResultsMatcher>(M)->FlagResultNodes == FlagResultNodes;
}
@ -880,7 +880,7 @@ public:
}
private:
virtual void print(raw_ostream &OS, unsigned indent = 0) const;
virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const {
return cast<CompleteMatchMatcher>(M)->Results == Results &&
&cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;