1 //===-- DiffConsumer.h - Difference Consumer --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header defines the interface to the LLVM difference Consumer
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H
15 #define LLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/IR/Value.h"
21 #include "llvm/Support/Casting.h"
22 #include "llvm/Support/raw_ostream.h"
30 /// The interface for consumers of difference data.
32 virtual void anchor();
34 /// Record that a local context has been entered. Left and
35 /// Right are IR "containers" of some sort which are being
36 /// considered for structural equivalence: global variables,
37 /// functions, blocks, instructions, etc.
38 virtual void enterContext(Value
*Left
, Value
*Right
) = 0;
40 /// Record that a local context has been exited.
41 virtual void exitContext() = 0;
43 /// Record a difference within the current context.
44 virtual void log(StringRef Text
) = 0;
46 /// Record a formatted difference within the current context.
47 virtual void logf(const LogBuilder
&Log
) = 0;
49 /// Record a line-by-line instruction diff.
50 virtual void logd(const DiffLogBuilder
&Log
) = 0;
53 virtual ~Consumer() {}
56 class DiffConsumer
: public Consumer
{
59 DiffContext(Value
*L
, Value
*R
)
60 : L(L
), R(R
), Differences(false), IsFunction(isa
<Function
>(L
)) {}
65 DenseMap
<Value
*,unsigned> LNumbering
;
66 DenseMap
<Value
*,unsigned> RNumbering
;
70 SmallVector
<DiffContext
, 5> contexts
;
74 void printValue(Value
*V
, bool isL
);
80 : out(errs()), Differences(false), Indent(0) {}
82 bool hadDifferences() const;
83 void enterContext(Value
*L
, Value
*R
) override
;
84 void exitContext() override
;
85 void log(StringRef text
) override
;
86 void logf(const LogBuilder
&Log
) override
;
87 void logd(const DiffLogBuilder
&Log
) override
;