Deleted Added
full compact
19a20,21
> #include "DiffLog.h"
> #include "DiffConsumer.h"
35,123d36
< /// A temporary-object class for building up log messages.
< class LogBuilder {
< DifferenceEngine &Engine;
<
< /// The use of a stored StringRef here is okay because
< /// LogBuilder should be used only as a temporary, and as a
< /// temporary it will be destructed before whatever temporary
< /// might be initializing this format.
< StringRef Format;
<
< SmallVector<Value*, 4> Arguments;
<
< public:
< LogBuilder(DifferenceEngine &Engine, StringRef Format)
< : Engine(Engine), Format(Format) {}
<
< LogBuilder &operator<<(Value *V) {
< Arguments.push_back(V);
< return *this;
< }
<
< ~LogBuilder() {
< Engine.consumer.logf(*this);
< }
<
< StringRef getFormat() const { return Format; }
<
< unsigned getNumArguments() const { return Arguments.size(); }
< Value *getArgument(unsigned I) const { return Arguments[I]; }
< };
<
< enum DiffChange { DC_match, DC_left, DC_right };
<
< /// A temporary-object class for building up diff messages.
< class DiffLogBuilder {
< typedef std::pair<Instruction*,Instruction*> DiffRecord;
< SmallVector<DiffRecord, 20> Diff;
<
< DifferenceEngine &Engine;
<
< public:
< DiffLogBuilder(DifferenceEngine &Engine) : Engine(Engine) {}
< ~DiffLogBuilder() { Engine.consumer.logd(*this); }
<
< void addMatch(Instruction *L, Instruction *R) {
< Diff.push_back(DiffRecord(L, R));
< }
< void addLeft(Instruction *L) {
< // HACK: VS 2010 has a bug in the stdlib that requires this.
< Diff.push_back(DiffRecord(L, DiffRecord::second_type(0)));
< }
< void addRight(Instruction *R) {
< // HACK: VS 2010 has a bug in the stdlib that requires this.
< Diff.push_back(DiffRecord(DiffRecord::first_type(0), R));
< }
<
< unsigned getNumLines() const { return Diff.size(); }
< DiffChange getLineKind(unsigned I) const {
< return (Diff[I].first ? (Diff[I].second ? DC_match : DC_left)
< : DC_right);
< }
< Instruction *getLeft(unsigned I) const { return Diff[I].first; }
< Instruction *getRight(unsigned I) const { return Diff[I].second; }
< };
<
< /// The interface for consumers of difference data.
< struct Consumer {
< /// Record that a local context has been entered. Left and
< /// Right are IR "containers" of some sort which are being
< /// considered for structural equivalence: global variables,
< /// functions, blocks, instructions, etc.
< virtual void enterContext(Value *Left, Value *Right) = 0;
<
< /// Record that a local context has been exited.
< virtual void exitContext() = 0;
<
< /// Record a difference within the current context.
< virtual void log(StringRef Text) = 0;
<
< /// Record a formatted difference within the current context.
< virtual void logf(const LogBuilder &Log) = 0;
<
< /// Record a line-by-line instruction diff.
< virtual void logd(const DiffLogBuilder &Log) = 0;
<
< protected:
< virtual ~Consumer() {}
< };
<
152d64
<
156d67
<
158c69
< return LogBuilder(*this, text);
---
> return LogBuilder(consumer, text);
159a71
> Consumer& getConsumer() const { return consumer; }