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