blob: 8f28461afddea1db1d8b44f537dec90c01bdedc4 [file] [log] [blame]
Renato Golin7d4fc4f2011-03-14 22:22:46 +00001//===-- DiffLog.h - Difference Log Builder and accessories ------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This header defines the interface to the LLVM difference log builder.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer00e08fc2014-08-13 16:26:38 +000014#ifndef LLVM_TOOLS_LLVM_DIFF_DIFFLOG_H
15#define LLVM_TOOLS_LLVM_DIFF_DIFFLOG_H
Renato Golin7d4fc4f2011-03-14 22:22:46 +000016
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringRef.h"
19
20namespace llvm {
21 class Instruction;
22 class Value;
23 class Consumer;
24
25 /// Trichotomy assumption
26 enum DiffChange { DC_match, DC_left, DC_right };
27
28 /// A temporary-object class for building up log messages.
29 class LogBuilder {
David Blaikie0caff992015-08-05 21:06:50 +000030 Consumer *consumer;
Renato Golin7d4fc4f2011-03-14 22:22:46 +000031
32 /// The use of a stored StringRef here is okay because
33 /// LogBuilder should be used only as a temporary, and as a
34 /// temporary it will be destructed before whatever temporary
35 /// might be initializing this format.
36 StringRef Format;
37
38 SmallVector<Value*, 4> Arguments;
39
40 public:
David Blaikie0caff992015-08-05 21:06:50 +000041 LogBuilder(Consumer &c, StringRef Format) : consumer(&c), Format(Format) {}
42 LogBuilder(LogBuilder &&L)
43 : consumer(L.consumer), Format(L.Format),
44 Arguments(std::move(L.Arguments)) {
45 L.consumer = nullptr;
46 }
Renato Golin7d4fc4f2011-03-14 22:22:46 +000047
48 LogBuilder &operator<<(Value *V) {
49 Arguments.push_back(V);
50 return *this;
51 }
52
53 ~LogBuilder();
54
55 StringRef getFormat() const;
56 unsigned getNumArguments() const;
57 Value *getArgument(unsigned I) const;
58 };
59
60 /// A temporary-object class for building up diff messages.
61 class DiffLogBuilder {
62 typedef std::pair<Instruction*,Instruction*> DiffRecord;
63 SmallVector<DiffRecord, 20> Diff;
64
65 Consumer &consumer;
66
67 public:
68 DiffLogBuilder(Consumer &c) : consumer(c) {}
69 ~DiffLogBuilder();
70
71 void addMatch(Instruction *L, Instruction *R);
72 // HACK: VS 2010 has a bug in the stdlib that requires this.
73 void addLeft(Instruction *L);
74 void addRight(Instruction *R);
75
76 unsigned getNumLines() const;
77 DiffChange getLineKind(unsigned I) const;
78 Instruction *getLeft(unsigned I) const;
79 Instruction *getRight(unsigned I) const;
80 };
81
82}
83
84#endif