blob: caf779bb4030bab26dec265321869e7fae5f3832 [file] [log] [blame]
Renato Golin7d4fc4f2011-03-14 22:22:46 +00001//===-- 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 Golin7d4fc4f2011-03-14 22:22:46 +000016#include "llvm/ADT/SmallVector.h"
17#include "llvm/ADT/StringRef.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000018#include "llvm/IR/Instructions.h"
Renato Golin7d4fc4f2011-03-14 22:22:46 +000019
20using namespace llvm;
21
22LogBuilder::~LogBuilder() {
23 consumer.logf(*this);
24}
25
26StringRef LogBuilder::getFormat() const { return Format; }
27
28unsigned LogBuilder::getNumArguments() const { return Arguments.size(); }
29Value *LogBuilder::getArgument(unsigned I) const { return Arguments[I]; }
30
31DiffLogBuilder::~DiffLogBuilder() { consumer.logd(*this); }
32
33void DiffLogBuilder::addMatch(Instruction *L, Instruction *R) {
34 Diff.push_back(DiffRecord(L, R));
35}
36void DiffLogBuilder::addLeft(Instruction *L) {
37 // HACK: VS 2010 has a bug in the stdlib that requires this.
38 Diff.push_back(DiffRecord(L, DiffRecord::second_type(0)));
39}
40void DiffLogBuilder::addRight(Instruction *R) {
41 // HACK: VS 2010 has a bug in the stdlib that requires this.
42 Diff.push_back(DiffRecord(DiffRecord::first_type(0), R));
43}
44
45unsigned DiffLogBuilder::getNumLines() const { return Diff.size(); }
46
47DiffChange DiffLogBuilder::getLineKind(unsigned I) const {
48 return (Diff[I].first ? (Diff[I].second ? DC_match : DC_left)
49 : DC_right);
50}
51Instruction *DiffLogBuilder::getLeft(unsigned I) const { return Diff[I].first; }
52Instruction *DiffLogBuilder::getRight(unsigned I) const { return Diff[I].second; }