DiffLog.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifndef LLVM_TOOLS_LLVM_DIFF_DIFFLOG_H
  14. #define LLVM_TOOLS_LLVM_DIFF_DIFFLOG_H
  15. #include "llvm/ADT/SmallVector.h"
  16. #include "llvm/ADT/StringRef.h"
  17. namespace llvm {
  18. class Instruction;
  19. class Value;
  20. class Consumer;
  21. /// Trichotomy assumption
  22. enum DiffChange { DC_match, DC_left, DC_right };
  23. /// A temporary-object class for building up log messages.
  24. class LogBuilder {
  25. Consumer &consumer;
  26. /// The use of a stored StringRef here is okay because
  27. /// LogBuilder should be used only as a temporary, and as a
  28. /// temporary it will be destructed before whatever temporary
  29. /// might be initializing this format.
  30. StringRef Format;
  31. SmallVector<Value*, 4> Arguments;
  32. public:
  33. LogBuilder(Consumer &c, StringRef Format)
  34. : consumer(c), Format(Format) {}
  35. LogBuilder &operator<<(Value *V) {
  36. Arguments.push_back(V);
  37. return *this;
  38. }
  39. ~LogBuilder();
  40. StringRef getFormat() const;
  41. unsigned getNumArguments() const;
  42. Value *getArgument(unsigned I) const;
  43. };
  44. /// A temporary-object class for building up diff messages.
  45. class DiffLogBuilder {
  46. typedef std::pair<Instruction*,Instruction*> DiffRecord;
  47. SmallVector<DiffRecord, 20> Diff;
  48. Consumer &consumer;
  49. public:
  50. DiffLogBuilder(Consumer &c) : consumer(c) {}
  51. ~DiffLogBuilder();
  52. void addMatch(Instruction *L, Instruction *R);
  53. // HACK: VS 2010 has a bug in the stdlib that requires this.
  54. void addLeft(Instruction *L);
  55. void addRight(Instruction *R);
  56. unsigned getNumLines() const;
  57. DiffChange getLineKind(unsigned I) const;
  58. Instruction *getLeft(unsigned I) const;
  59. Instruction *getRight(unsigned I) const;
  60. };
  61. }
  62. #endif