Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 1 | //===-- DiffLog.h - Difference Log Builder and accessories ------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This header defines the interface to the LLVM difference log builder. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "DiffLog.h" |
| 15 | #include "DiffConsumer.h" |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringRef.h" |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace llvm; |
| 19 | |
| 20 | LogBuilder::~LogBuilder() { |
David Blaikie | 0caff99 | 2015-08-05 21:06:50 +0000 | [diff] [blame] | 21 | if (consumer) |
| 22 | consumer->logf(*this); |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | StringRef LogBuilder::getFormat() const { return Format; } |
| 26 | |
| 27 | unsigned LogBuilder::getNumArguments() const { return Arguments.size(); } |
| 28 | Value *LogBuilder::getArgument(unsigned I) const { return Arguments[I]; } |
| 29 | |
| 30 | DiffLogBuilder::~DiffLogBuilder() { consumer.logd(*this); } |
| 31 | |
| 32 | void DiffLogBuilder::addMatch(Instruction *L, Instruction *R) { |
| 33 | Diff.push_back(DiffRecord(L, R)); |
| 34 | } |
| 35 | void DiffLogBuilder::addLeft(Instruction *L) { |
| 36 | // HACK: VS 2010 has a bug in the stdlib that requires this. |
Craig Topper | 573faec | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 37 | Diff.push_back(DiffRecord(L, DiffRecord::second_type(nullptr))); |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 38 | } |
| 39 | void DiffLogBuilder::addRight(Instruction *R) { |
| 40 | // HACK: VS 2010 has a bug in the stdlib that requires this. |
Craig Topper | 573faec | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 41 | Diff.push_back(DiffRecord(DiffRecord::first_type(nullptr), R)); |
Renato Golin | 7d4fc4f | 2011-03-14 22:22:46 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | unsigned DiffLogBuilder::getNumLines() const { return Diff.size(); } |
| 45 | |
| 46 | DiffChange DiffLogBuilder::getLineKind(unsigned I) const { |
| 47 | return (Diff[I].first ? (Diff[I].second ? DC_match : DC_left) |
| 48 | : DC_right); |
| 49 | } |
| 50 | Instruction *DiffLogBuilder::getLeft(unsigned I) const { return Diff[I].first; } |
| 51 | Instruction *DiffLogBuilder::getRight(unsigned I) const { return Diff[I].second; } |