10b57cec5SDimitry Andric //===-- DiffLog.h - Difference Log Builder and accessories ------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This header defines the interface to the LLVM difference log builder. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #include "DiffLog.h" 140b57cec5SDimitry Andric #include "DiffConsumer.h" 150b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h" 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric using namespace llvm; 180b57cec5SDimitry Andric ~LogBuilder()190b57cec5SDimitry AndricLogBuilder::~LogBuilder() { 200b57cec5SDimitry Andric if (consumer) 210b57cec5SDimitry Andric consumer->logf(*this); 220b57cec5SDimitry Andric } 230b57cec5SDimitry Andric getFormat() const240b57cec5SDimitry AndricStringRef LogBuilder::getFormat() const { return Format; } 250b57cec5SDimitry Andric getNumArguments() const260b57cec5SDimitry Andricunsigned LogBuilder::getNumArguments() const { return Arguments.size(); } getArgument(unsigned I) const27*5f7ddb14SDimitry Andricconst Value *LogBuilder::getArgument(unsigned I) const { return Arguments[I]; } 280b57cec5SDimitry Andric ~DiffLogBuilder()290b57cec5SDimitry AndricDiffLogBuilder::~DiffLogBuilder() { consumer.logd(*this); } 300b57cec5SDimitry Andric addMatch(const Instruction * L,const Instruction * R)31*5f7ddb14SDimitry Andricvoid DiffLogBuilder::addMatch(const Instruction *L, const Instruction *R) { 320b57cec5SDimitry Andric Diff.push_back(DiffRecord(L, R)); 330b57cec5SDimitry Andric } addLeft(const Instruction * L)34*5f7ddb14SDimitry Andricvoid DiffLogBuilder::addLeft(const Instruction *L) { 350b57cec5SDimitry Andric // HACK: VS 2010 has a bug in the stdlib that requires this. 360b57cec5SDimitry Andric Diff.push_back(DiffRecord(L, DiffRecord::second_type(nullptr))); 370b57cec5SDimitry Andric } addRight(const Instruction * R)38*5f7ddb14SDimitry Andricvoid DiffLogBuilder::addRight(const Instruction *R) { 390b57cec5SDimitry Andric // HACK: VS 2010 has a bug in the stdlib that requires this. 400b57cec5SDimitry Andric Diff.push_back(DiffRecord(DiffRecord::first_type(nullptr), R)); 410b57cec5SDimitry Andric } 420b57cec5SDimitry Andric getNumLines() const430b57cec5SDimitry Andricunsigned DiffLogBuilder::getNumLines() const { return Diff.size(); } 440b57cec5SDimitry Andric getLineKind(unsigned I) const450b57cec5SDimitry AndricDiffChange DiffLogBuilder::getLineKind(unsigned I) const { 460b57cec5SDimitry Andric return (Diff[I].first ? (Diff[I].second ? DC_match : DC_left) 470b57cec5SDimitry Andric : DC_right); 480b57cec5SDimitry Andric } getLeft(unsigned I) const49*5f7ddb14SDimitry Andricconst Instruction *DiffLogBuilder::getLeft(unsigned I) const { 50*5f7ddb14SDimitry Andric return Diff[I].first; 51*5f7ddb14SDimitry Andric } getRight(unsigned I) const52*5f7ddb14SDimitry Andricconst Instruction *DiffLogBuilder::getRight(unsigned I) const { 53*5f7ddb14SDimitry Andric return Diff[I].second; 54*5f7ddb14SDimitry Andric } 55