]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/tools/llvm-diff/DiffLog.h
Fix a memory leak in if_delgroups() introduced in r334118.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / tools / llvm-diff / DiffLog.h
1 //===-- DiffLog.h - Difference Log Builder and accessories ------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This header defines the interface to the LLVM difference log builder.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TOOLS_LLVM_DIFF_DIFFLOG_H
14 #define LLVM_TOOLS_LLVM_DIFF_DIFFLOG_H
15
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringRef.h"
18
19 namespace llvm {
20   class Instruction;
21   class Value;
22   class Consumer;
23
24   /// Trichotomy assumption
25   enum DiffChange { DC_match, DC_left, DC_right };
26
27   /// A temporary-object class for building up log messages.
28   class LogBuilder {
29     Consumer *consumer;
30
31     /// The use of a stored StringRef here is okay because
32     /// LogBuilder should be used only as a temporary, and as a
33     /// temporary it will be destructed before whatever temporary
34     /// might be initializing this format.
35     StringRef Format;
36
37     SmallVector<Value*, 4> Arguments;
38
39   public:
40     LogBuilder(Consumer &c, StringRef Format) : consumer(&c), Format(Format) {}
41     LogBuilder(LogBuilder &&L)
42         : consumer(L.consumer), Format(L.Format),
43           Arguments(std::move(L.Arguments)) {
44       L.consumer = nullptr;
45     }
46
47     LogBuilder &operator<<(Value *V) {
48       Arguments.push_back(V);
49       return *this;
50     }
51
52     ~LogBuilder();
53
54     StringRef getFormat() const;
55     unsigned getNumArguments() const;
56     Value *getArgument(unsigned I) const;
57   };
58
59   /// A temporary-object class for building up diff messages.
60   class DiffLogBuilder {
61     typedef std::pair<Instruction*,Instruction*> DiffRecord;
62     SmallVector<DiffRecord, 20> Diff;
63
64     Consumer &consumer;
65
66   public:
67     DiffLogBuilder(Consumer &c) : consumer(c) {}
68     ~DiffLogBuilder();
69
70     void addMatch(Instruction *L, Instruction *R);
71     // HACK: VS 2010 has a bug in the stdlib that requires this.
72     void addLeft(Instruction *L);
73     void addRight(Instruction *R);
74
75     unsigned getNumLines() const;
76     DiffChange getLineKind(unsigned I) const;
77     Instruction *getLeft(unsigned I) const;
78     Instruction *getRight(unsigned I) const;
79   };
80
81 }
82
83 #endif