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 #include "DiffLog.h" 14*4d293f21SBill Wendling #include "DiffConsumer.h" 15*4d293f21SBill Wendling #include "llvm/ADT/StringRef.h" 16*4d293f21SBill Wendling 17*4d293f21SBill Wendling using namespace llvm; 18*4d293f21SBill Wendling ~LogBuilder()19*4d293f21SBill WendlingLogBuilder::~LogBuilder() { 20*4d293f21SBill Wendling if (consumer) 21*4d293f21SBill Wendling consumer->logf(*this); 22*4d293f21SBill Wendling } 23*4d293f21SBill Wendling getFormat() const24*4d293f21SBill WendlingStringRef LogBuilder::getFormat() const { return Format; } 25*4d293f21SBill Wendling getNumArguments() const26*4d293f21SBill Wendlingunsigned LogBuilder::getNumArguments() const { return Arguments.size(); } getArgument(unsigned I) const27*4d293f21SBill Wendlingconst Value *LogBuilder::getArgument(unsigned I) const { return Arguments[I]; } 28*4d293f21SBill Wendling ~DiffLogBuilder()29*4d293f21SBill WendlingDiffLogBuilder::~DiffLogBuilder() { consumer.logd(*this); } 30*4d293f21SBill Wendling addMatch(const Instruction * L,const Instruction * R)31*4d293f21SBill Wendlingvoid DiffLogBuilder::addMatch(const Instruction *L, const Instruction *R) { 32*4d293f21SBill Wendling Diff.push_back(DiffRecord(L, R)); 33*4d293f21SBill Wendling } addLeft(const Instruction * L)34*4d293f21SBill Wendlingvoid DiffLogBuilder::addLeft(const Instruction *L) { 35*4d293f21SBill Wendling // HACK: VS 2010 has a bug in the stdlib that requires this. 36*4d293f21SBill Wendling Diff.push_back(DiffRecord(L, DiffRecord::second_type(nullptr))); 37*4d293f21SBill Wendling } addRight(const Instruction * R)38*4d293f21SBill Wendlingvoid DiffLogBuilder::addRight(const Instruction *R) { 39*4d293f21SBill Wendling // HACK: VS 2010 has a bug in the stdlib that requires this. 40*4d293f21SBill Wendling Diff.push_back(DiffRecord(DiffRecord::first_type(nullptr), R)); 41*4d293f21SBill Wendling } 42*4d293f21SBill Wendling getNumLines() const43*4d293f21SBill Wendlingunsigned DiffLogBuilder::getNumLines() const { return Diff.size(); } 44*4d293f21SBill Wendling getLineKind(unsigned I) const45*4d293f21SBill WendlingDiffChange DiffLogBuilder::getLineKind(unsigned I) const { 46*4d293f21SBill Wendling return (Diff[I].first ? (Diff[I].second ? DC_match : DC_left) 47*4d293f21SBill Wendling : DC_right); 48*4d293f21SBill Wendling } getLeft(unsigned I) const49*4d293f21SBill Wendlingconst Instruction *DiffLogBuilder::getLeft(unsigned I) const { 50*4d293f21SBill Wendling return Diff[I].first; 51*4d293f21SBill Wendling } getRight(unsigned I) const52*4d293f21SBill Wendlingconst Instruction *DiffLogBuilder::getRight(unsigned I) const { 53*4d293f21SBill Wendling return Diff[I].second; 54*4d293f21SBill Wendling } 55