17d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin//===-- DiffLog.h - Difference Log Builder and accessories ------*- C++ -*-===// 27d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin// 37d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin// The LLVM Compiler Infrastructure 47d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin// 57d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin// This file is distributed under the University of Illinois Open Source 67d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin// License. See LICENSE.TXT for details. 77d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin// 87d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin//===----------------------------------------------------------------------===// 97d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin// 107d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin// This header defines the interface to the LLVM difference log builder. 117d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin// 127d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin//===----------------------------------------------------------------------===// 137d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin 147d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin#include "DiffLog.h" 157d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin#include "DiffConsumer.h" 167d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin#include "llvm/ADT/SmallVector.h" 177d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin#include "llvm/ADT/StringRef.h" 180b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instructions.h" 197d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin 207d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golinusing namespace llvm; 217d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin 227d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato GolinLogBuilder::~LogBuilder() { 23cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar if (consumer) 24cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar consumer->logf(*this); 257d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin} 267d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin 277d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato GolinStringRef LogBuilder::getFormat() const { return Format; } 287d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin 297d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golinunsigned LogBuilder::getNumArguments() const { return Arguments.size(); } 307d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato GolinValue *LogBuilder::getArgument(unsigned I) const { return Arguments[I]; } 317d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin 327d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato GolinDiffLogBuilder::~DiffLogBuilder() { consumer.logd(*this); } 337d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin 347d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golinvoid DiffLogBuilder::addMatch(Instruction *L, Instruction *R) { 357d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin Diff.push_back(DiffRecord(L, R)); 367d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin} 377d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golinvoid DiffLogBuilder::addLeft(Instruction *L) { 387d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin // HACK: VS 2010 has a bug in the stdlib that requires this. 39dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Diff.push_back(DiffRecord(L, DiffRecord::second_type(nullptr))); 407d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin} 417d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golinvoid DiffLogBuilder::addRight(Instruction *R) { 427d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin // HACK: VS 2010 has a bug in the stdlib that requires this. 43dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Diff.push_back(DiffRecord(DiffRecord::first_type(nullptr), R)); 447d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin} 457d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin 467d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golinunsigned DiffLogBuilder::getNumLines() const { return Diff.size(); } 477d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin 487d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato GolinDiffChange DiffLogBuilder::getLineKind(unsigned I) const { 497d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin return (Diff[I].first ? (Diff[I].second ? DC_match : DC_left) 507d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin : DC_right); 517d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato Golin} 527d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato GolinInstruction *DiffLogBuilder::getLeft(unsigned I) const { return Diff[I].first; } 537d4fc4fb345ee8a1de15c718a854b5f38c1e6e46Renato GolinInstruction *DiffLogBuilder::getRight(unsigned I) const { return Diff[I].second; } 54