#ifndef LLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H
#define LLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H
#include "DiffLog.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
class Module;
class Value;
class Function;
class Consumer {
virtual void anchor();
public:
virtual void enterContext(Value *Left, Value *Right) = 0;
virtual void exitContext() = 0;
virtual void log(StringRef Text) = 0;
virtual void logf(const LogBuilder &Log) = 0;
virtual void logd(const DiffLogBuilder &Log) = 0;
protected:
virtual ~Consumer() {}
};
class DiffConsumer : public Consumer {
private:
struct DiffContext {
DiffContext(Value *L, Value *R)
: L(L), R(R), Differences(false), IsFunction(isa<Function>(L)) {}
Value *L;
Value *R;
bool Differences;
bool IsFunction;
DenseMap<Value*,unsigned> LNumbering;
DenseMap<Value*,unsigned> RNumbering;
};
raw_ostream &out;
SmallVector<DiffContext, 5> contexts;
bool Differences;
unsigned Indent;
void printValue(Value *V, bool isL);
void header();
void indent();
public:
DiffConsumer()
: out(errs()), Differences(false), Indent(0) {}
bool hadDifferences() const;
void enterContext(Value *L, Value *R) override;
void exitContext() override;
void log(StringRef text) override;
void logf(const LogBuilder &Log) override;
void logd(const DiffLogBuilder &Log) override;
};
}
#endif