DiffLog.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "DiffLog.h"
  14. #include "DiffConsumer.h"
  15. #include "llvm/ADT/StringRef.h"
  16. using namespace llvm;
  17. LogBuilder::~LogBuilder() {
  18. if (consumer)
  19. consumer->logf(*this);
  20. }
  21. StringRef LogBuilder::getFormat() const { return Format; }
  22. unsigned LogBuilder::getNumArguments() const { return Arguments.size(); }
  23. Value *LogBuilder::getArgument(unsigned I) const { return Arguments[I]; }
  24. DiffLogBuilder::~DiffLogBuilder() { consumer.logd(*this); }
  25. void DiffLogBuilder::addMatch(Instruction *L, Instruction *R) {
  26. Diff.push_back(DiffRecord(L, R));
  27. }
  28. void DiffLogBuilder::addLeft(Instruction *L) {
  29. // HACK: VS 2010 has a bug in the stdlib that requires this.
  30. Diff.push_back(DiffRecord(L, DiffRecord::second_type(nullptr)));
  31. }
  32. void DiffLogBuilder::addRight(Instruction *R) {
  33. // HACK: VS 2010 has a bug in the stdlib that requires this.
  34. Diff.push_back(DiffRecord(DiffRecord::first_type(nullptr), R));
  35. }
  36. unsigned DiffLogBuilder::getNumLines() const { return Diff.size(); }
  37. DiffChange DiffLogBuilder::getLineKind(unsigned I) const {
  38. return (Diff[I].first ? (Diff[I].second ? DC_match : DC_left)
  39. : DC_right);
  40. }
  41. Instruction *DiffLogBuilder::getLeft(unsigned I) const { return Diff[I].first; }
  42. Instruction *DiffLogBuilder::getRight(unsigned I) const { return Diff[I].second; }