[LLVM][Alignment] Introduce Alignment In Attributes
[llvm-core.git] / tools / llvm-diff / DiffLog.h
blob0c8952496155046efaac8b2a0f65a593a5a89626
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<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<<(Value *V) {
48 Arguments.push_back(V);
49 return *this;
52 ~LogBuilder();
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;
64 Consumer &consumer;
66 public:
67 DiffLogBuilder(Consumer &c) : consumer(c) {}
68 ~DiffLogBuilder();
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;
83 #endif