1*349cc55cSDimitry Andric //===-- DiffLog.h - Difference Log Builder and accessories ------*- C++ -*-===// 2*349cc55cSDimitry Andric // 3*349cc55cSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*349cc55cSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*349cc55cSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*349cc55cSDimitry Andric // 7*349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 8*349cc55cSDimitry Andric // 9*349cc55cSDimitry Andric // This header defines the interface to the LLVM difference log builder. 10*349cc55cSDimitry Andric // 11*349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 12*349cc55cSDimitry Andric 13*349cc55cSDimitry Andric #include "DiffLog.h" 14*349cc55cSDimitry Andric #include "DiffConsumer.h" 15*349cc55cSDimitry Andric #include "llvm/ADT/StringRef.h" 16*349cc55cSDimitry Andric 17*349cc55cSDimitry Andric using namespace llvm; 18*349cc55cSDimitry Andric ~LogBuilder()19*349cc55cSDimitry AndricLogBuilder::~LogBuilder() { 20*349cc55cSDimitry Andric if (consumer) 21*349cc55cSDimitry Andric consumer->logf(*this); 22*349cc55cSDimitry Andric } 23*349cc55cSDimitry Andric getFormat() const24*349cc55cSDimitry AndricStringRef LogBuilder::getFormat() const { return Format; } 25*349cc55cSDimitry Andric getNumArguments() const26*349cc55cSDimitry Andricunsigned LogBuilder::getNumArguments() const { return Arguments.size(); } getArgument(unsigned I) const27*349cc55cSDimitry Andricconst Value *LogBuilder::getArgument(unsigned I) const { return Arguments[I]; } 28*349cc55cSDimitry Andric ~DiffLogBuilder()29*349cc55cSDimitry AndricDiffLogBuilder::~DiffLogBuilder() { consumer.logd(*this); } 30*349cc55cSDimitry Andric addMatch(const Instruction * L,const Instruction * R)31*349cc55cSDimitry Andricvoid DiffLogBuilder::addMatch(const Instruction *L, const Instruction *R) { 32*349cc55cSDimitry Andric Diff.push_back(DiffRecord(L, R)); 33*349cc55cSDimitry Andric } addLeft(const Instruction * L)34*349cc55cSDimitry Andricvoid DiffLogBuilder::addLeft(const Instruction *L) { 35*349cc55cSDimitry Andric // HACK: VS 2010 has a bug in the stdlib that requires this. 36*349cc55cSDimitry Andric Diff.push_back(DiffRecord(L, DiffRecord::second_type(nullptr))); 37*349cc55cSDimitry Andric } addRight(const Instruction * R)38*349cc55cSDimitry Andricvoid DiffLogBuilder::addRight(const Instruction *R) { 39*349cc55cSDimitry Andric // HACK: VS 2010 has a bug in the stdlib that requires this. 40*349cc55cSDimitry Andric Diff.push_back(DiffRecord(DiffRecord::first_type(nullptr), R)); 41*349cc55cSDimitry Andric } 42*349cc55cSDimitry Andric getNumLines() const43*349cc55cSDimitry Andricunsigned DiffLogBuilder::getNumLines() const { return Diff.size(); } 44*349cc55cSDimitry Andric getLineKind(unsigned I) const45*349cc55cSDimitry AndricDiffChange DiffLogBuilder::getLineKind(unsigned I) const { 46*349cc55cSDimitry Andric return (Diff[I].first ? (Diff[I].second ? DC_match : DC_left) 47*349cc55cSDimitry Andric : DC_right); 48*349cc55cSDimitry Andric } getLeft(unsigned I) const49*349cc55cSDimitry Andricconst Instruction *DiffLogBuilder::getLeft(unsigned I) const { 50*349cc55cSDimitry Andric return Diff[I].first; 51*349cc55cSDimitry Andric } getRight(unsigned I) const52*349cc55cSDimitry Andricconst Instruction *DiffLogBuilder::getRight(unsigned I) const { 53*349cc55cSDimitry Andric return Diff[I].second; 54*349cc55cSDimitry Andric } 55