Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 1 | //===-- DiffConsumer.h - Difference Consumer --------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This header defines the interface to the LLVM difference Consumer |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef _LLVM_DIFFCONSUMER_H_ |
| 15 | #define _LLVM_DIFFCONSUMER_H_ |
| 16 | |
| 17 | #include "DiffLog.h" |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/DenseMap.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame^] | 19 | #include "llvm/ADT/SmallVector.h" |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringRef.h" |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Casting.h" |
Chandler Carruth | f010c46 | 2012-12-04 10:44:52 +0000 | [diff] [blame^] | 22 | #include "llvm/Support/raw_ostream.h" |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
| 25 | class Module; |
| 26 | class Value; |
| 27 | class Function; |
| 28 | |
| 29 | /// The interface for consumers of difference data. |
Francois Pichet | 875c3ff | 2011-03-14 23:07:21 +0000 | [diff] [blame] | 30 | class Consumer { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 31 | virtual void anchor(); |
Francois Pichet | 875c3ff | 2011-03-14 23:07:21 +0000 | [diff] [blame] | 32 | public: |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 33 | /// Record that a local context has been entered. Left and |
| 34 | /// Right are IR "containers" of some sort which are being |
| 35 | /// considered for structural equivalence: global variables, |
| 36 | /// functions, blocks, instructions, etc. |
| 37 | virtual void enterContext(Value *Left, Value *Right) = 0; |
| 38 | |
| 39 | /// Record that a local context has been exited. |
| 40 | virtual void exitContext() = 0; |
| 41 | |
| 42 | /// Record a difference within the current context. |
| 43 | virtual void log(StringRef Text) = 0; |
| 44 | |
| 45 | /// Record a formatted difference within the current context. |
| 46 | virtual void logf(const LogBuilder &Log) = 0; |
| 47 | |
| 48 | /// Record a line-by-line instruction diff. |
| 49 | virtual void logd(const DiffLogBuilder &Log) = 0; |
| 50 | |
| 51 | protected: |
| 52 | virtual ~Consumer() {} |
| 53 | }; |
| 54 | |
| 55 | class DiffConsumer : public Consumer { |
| 56 | private: |
| 57 | struct DiffContext { |
| 58 | DiffContext(Value *L, Value *R) |
| 59 | : L(L), R(R), Differences(false), IsFunction(isa<Function>(L)) {} |
| 60 | Value *L; |
| 61 | Value *R; |
| 62 | bool Differences; |
| 63 | bool IsFunction; |
| 64 | DenseMap<Value*,unsigned> LNumbering; |
| 65 | DenseMap<Value*,unsigned> RNumbering; |
| 66 | }; |
| 67 | |
| 68 | raw_ostream &out; |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 69 | SmallVector<DiffContext, 5> contexts; |
| 70 | bool Differences; |
| 71 | unsigned Indent; |
| 72 | |
| 73 | void printValue(Value *V, bool isL); |
| 74 | void header(); |
| 75 | void indent(); |
| 76 | |
| 77 | public: |
Benjamin Kramer | a7542d5 | 2012-06-06 18:25:08 +0000 | [diff] [blame] | 78 | DiffConsumer() |
| 79 | : out(errs()), Differences(false), Indent(0) {} |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 80 | |
| 81 | bool hadDifferences() const; |
| 82 | void enterContext(Value *L, Value *R); |
| 83 | void exitContext(); |
| 84 | void log(StringRef text); |
| 85 | void logf(const LogBuilder &Log); |
| 86 | void logd(const DiffLogBuilder &Log); |
| 87 | }; |
| 88 | } |
| 89 | |
| 90 | #endif |