forked from llvm/llvm-project
- Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathDiffConsumer.h
91 lines (76 loc) · 2.68 KB
/
DiffConsumer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//===-- DiffConsumer.h - Difference Consumer --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This header defines the interface to the LLVM difference Consumer
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H
#defineLLVM_TOOLS_LLVM_DIFF_DIFFCONSUMER_H
#include"DiffLog.h"
#include"llvm/ADT/DenseMap.h"
#include"llvm/ADT/SmallVector.h"
#include"llvm/IR/Value.h"
#include"llvm/Support/Casting.h"
#include"llvm/Support/raw_ostream.h"
namespacellvm {
classStringRef;
classModule;
classValue;
classFunction;
/// The interface for consumers of difference data.
classConsumer {
virtualvoidanchor();
public:
/// 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.
virtualvoidenterContext(const Value *Left, const Value *Right) = 0;
/// Record that a local context has been exited.
virtualvoidexitContext() = 0;
/// Record a difference within the current context.
virtualvoidlog(StringRef Text) = 0;
/// Record a formatted difference within the current context.
virtualvoidlogf(const LogBuilder &Log) = 0;
/// Record a line-by-line instruction diff.
virtualvoidlogd(const DiffLogBuilder &Log) = 0;
protected:
virtual~Consumer() {}
};
classDiffConsumer : publicConsumer {
private:
structDiffContext {
DiffContext(const Value *L, const Value *R)
: L(L), R(R), Differences(false), IsFunction(isa<Function>(L)) {}
const Value *L;
const Value *R;
bool Differences;
bool IsFunction;
DenseMap<const Value *, unsigned> LNumbering;
DenseMap<const Value *, unsigned> RNumbering;
};
raw_ostream &out;
SmallVector<DiffContext, 5> contexts;
bool Differences;
unsigned Indent;
voidprintValue(const Value *V, bool isL);
voidheader();
voidindent();
public:
DiffConsumer()
: out(errs()), Differences(false), Indent(0) {}
voidreset();
boolhadDifferences() const;
voidenterContext(const Value *L, const Value *R) override;
voidexitContext() override;
voidlog(StringRef text) override;
voidlogf(const LogBuilder &Log) override;
voidlogd(const DiffLogBuilder &Log) override;
};
}
#endif