Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / tools / llvm-diff / lib / DiffLog.h
blobd8b07b971198204ae75b15472e83a4e0dddbf61a
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TOOLS_LLVM_DIFF_DIFFLOG_H
14 #define LLVM_TOOLS_LLVM_DIFF_DIFFLOG_H
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringRef.h"
19 namespace llvm {
20 class Instruction;
21 class Value;
22 class Consumer;
24 /// Trichotomy assumption
25 enum DiffChange { DC_match, DC_left, DC_right };
27 /// A temporary-object class for building up log messages.
28 class LogBuilder {
29 Consumer *consumer;
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;
37 SmallVector<const Value *, 4> Arguments;
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;
47 LogBuilder &operator<<(const Value *V) {
48 Arguments.push_back(V);
49 return *this;
52 ~LogBuilder();
54 StringRef getFormat() const;
55 unsigned getNumArguments() const;
56 const Value *getArgument(unsigned I) const;
59 /// A temporary-object class for building up diff messages.
60 class DiffLogBuilder {
61 typedef std::pair<const Instruction *, const Instruction *> DiffRecord;
62 SmallVector<DiffRecord, 20> Diff;
64 Consumer &consumer;
66 public:
67 DiffLogBuilder(Consumer &c) : consumer(c) {}
68 ~DiffLogBuilder();
70 void addMatch(const Instruction *L, const Instruction *R);
71 // HACK: VS 2010 has a bug in the stdlib that requires this.
72 void addLeft(const Instruction *L);
73 void addRight(const Instruction *R);
75 unsigned getNumLines() const;
76 DiffChange getLineKind(unsigned I) const;
77 const Instruction *getLeft(unsigned I) const;
78 const Instruction *getRight(unsigned I) const;
83 #endif