verify-di: split out VerifierSupport

Split out assertion and output helpers from Verifier in preparation for
writing the DebugInfoVerifier.

<rdar://problem/15500563>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206299 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2014-04-15 16:27:32 +00:00
parent 3549f3cf19
commit abf483ba52

View File

@ -79,11 +79,68 @@ using namespace llvm;
static cl::opt<bool> VerifyDebugInfo("verify-debug-info", cl::init(false));
namespace {
class Verifier : public InstVisitor<Verifier> {
friend class InstVisitor<Verifier>;
struct VerifierSupport {
raw_ostream &OS;
const Module *M;
/// \brief Track the brokenness of the module while recursively visiting.
bool Broken;
explicit VerifierSupport(raw_ostream &OS)
: OS(OS), M(nullptr), Broken(false) {}
void WriteValue(const Value *V) {
if (!V)
return;
if (isa<Instruction>(V)) {
OS << *V << '\n';
} else {
V->printAsOperand(OS, true, M);
OS << '\n';
}
}
void WriteType(Type *T) {
if (!T)
return;
OS << ' ' << *T;
}
// CheckFailed - A check failed, so print out the condition and the message
// that failed. This provides a nice place to put a breakpoint if you want
// to see why something is not correct.
void CheckFailed(const Twine &Message, const Value *V1 = nullptr,
const Value *V2 = nullptr, const Value *V3 = nullptr,
const Value *V4 = nullptr) {
OS << Message.str() << "\n";
WriteValue(V1);
WriteValue(V2);
WriteValue(V3);
WriteValue(V4);
Broken = true;
}
void CheckFailed(const Twine &Message, const Value *V1, Type *T2,
const Value *V3 = nullptr) {
OS << Message.str() << "\n";
WriteValue(V1);
WriteType(T2);
WriteValue(V3);
Broken = true;
}
void CheckFailed(const Twine &Message, Type *T1, Type *T2 = nullptr,
Type *T3 = nullptr) {
OS << Message.str() << "\n";
WriteType(T1);
WriteType(T2);
WriteType(T3);
Broken = true;
}
};
class Verifier : public InstVisitor<Verifier>, VerifierSupport {
friend class InstVisitor<Verifier>;
LLVMContext *Context;
const DataLayout *DL;
DominatorTree DT;
@ -106,13 +163,10 @@ class Verifier : public InstVisitor<Verifier> {
/// \brief Finder keeps track of all debug info MDNodes in a Module.
DebugInfoFinder Finder;
/// \brief Track the brokenness of the module while recursively visiting.
bool Broken;
public:
explicit Verifier(raw_ostream &OS = dbgs())
: OS(OS), M(nullptr), Context(nullptr), DL(nullptr),
PersonalityFn(nullptr), Broken(false) {}
: VerifierSupport(OS), Context(nullptr), DL(nullptr),
PersonalityFn(nullptr) {}
bool verify(const Function &F) {
M = F.getParent();
@ -280,55 +334,6 @@ private:
void VerifyConstantExprBitcastType(const ConstantExpr *CE);
void verifyDebugInfo();
void WriteValue(const Value *V) {
if (!V)
return;
if (isa<Instruction>(V)) {
OS << *V << '\n';
} else {
V->printAsOperand(OS, true, M);
OS << '\n';
}
}
void WriteType(Type *T) {
if (!T)
return;
OS << ' ' << *T;
}
// CheckFailed - A check failed, so print out the condition and the message
// that failed. This provides a nice place to put a breakpoint if you want
// to see why something is not correct.
void CheckFailed(const Twine &Message, const Value *V1 = nullptr,
const Value *V2 = nullptr, const Value *V3 = nullptr,
const Value *V4 = nullptr) {
OS << Message.str() << "\n";
WriteValue(V1);
WriteValue(V2);
WriteValue(V3);
WriteValue(V4);
Broken = true;
}
void CheckFailed(const Twine &Message, const Value *V1, Type *T2,
const Value *V3 = nullptr) {
OS << Message.str() << "\n";
WriteValue(V1);
WriteType(T2);
WriteValue(V3);
Broken = true;
}
void CheckFailed(const Twine &Message, Type *T1, Type *T2 = nullptr,
Type *T3 = nullptr) {
OS << Message.str() << "\n";
WriteType(T1);
WriteType(T2);
WriteType(T3);
Broken = true;
}
};
} // End anonymous namespace