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