1 //===-- DiffLog.h - Difference Log Builder and accessories ------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
24 /// Trichotomy assumption
25 enum DiffChange
{ DC_match
, DC_left
, DC_right
};
27 /// A temporary-object class for building up log messages.
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.
37 SmallVector
<Value
*, 4> Arguments
;
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
)) {
47 LogBuilder
&operator<<(Value
*V
) {
48 Arguments
.push_back(V
);
54 StringRef
getFormat() const;
55 unsigned getNumArguments() const;
56 Value
*getArgument(unsigned I
) const;
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
;
67 DiffLogBuilder(Consumer
&c
) : consumer(c
) {}
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
);
75 unsigned getNumLines() const;
76 DiffChange
getLineKind(unsigned I
) const;
77 Instruction
*getLeft(unsigned I
) const;
78 Instruction
*getRight(unsigned I
) const;