2
0

DiffLog.cpp 1.8 KB

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