2011-03-14 23:22:46 +01:00
|
|
|
//===-- DiffConsumer.h - Difference Consumer --------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This header defines the interface to the LLVM difference Consumer
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 18:26:38 +02:00
|
|
|
#ifndef LLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H
|
|
|
|
#define LLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H
|
2011-03-14 23:22:46 +01:00
|
|
|
|
|
|
|
#include "DiffLog.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2012-12-04 11:44:52 +01:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2011-03-14 23:22:46 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
2012-12-04 11:44:52 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-03-14 23:22:46 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Module;
|
|
|
|
class Value;
|
|
|
|
class Function;
|
|
|
|
|
|
|
|
/// The interface for consumers of difference data.
|
2011-03-15 00:07:21 +01:00
|
|
|
class Consumer {
|
2011-12-20 03:50:00 +01:00
|
|
|
virtual void anchor();
|
2011-03-15 00:07:21 +01:00
|
|
|
public:
|
2011-03-14 23:22:46 +01:00
|
|
|
/// 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() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
2012-06-06 20:25:08 +02:00
|
|
|
DiffConsumer()
|
|
|
|
: out(errs()), Differences(false), Indent(0) {}
|
2011-03-14 23:22:46 +01:00
|
|
|
|
|
|
|
bool hadDifferences() const;
|
2014-03-08 09:27:28 +01:00
|
|
|
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;
|
2011-03-14 23:22:46 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|