DiffLog.cpp 1.8 KB

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