Skip to content

Commit b67379c

Browse files
authored
[llvm-diff] Add colorful output to diff (#131012)
Adds colorful output when when possible to the diff. Adds a use to the `--color` option llvm-diff has.
1 parent 7e9802f commit b67379c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

llvm/tools/llvm-diff/lib/DiffConsumer.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "llvm/IR/Instructions.h"
1515
#include "llvm/Support/Debug.h"
1616
#include "llvm/Support/ErrorHandling.h"
17+
#include "llvm/Support/WithColor.h"
18+
#include "llvm/Support/raw_ostream.h"
1719

1820
using namespace llvm;
1921

@@ -199,20 +201,23 @@ void DiffConsumer::logd(const DiffLogBuilder &Log) {
199201
switch (Log.getLineKind(I)) {
200202
case DC_match:
201203
out << " ";
202-
Log.getLeft(I)->print(dbgs()); dbgs() << '\n';
203-
//printValue(Log.getLeft(I), true);
204+
Log.getLeft(I)->print(dbgs());
205+
dbgs() << '\n';
204206
break;
205-
case DC_left:
206-
out << "< ";
207-
Log.getLeft(I)->print(dbgs()); dbgs() << '\n';
208-
//printValue(Log.getLeft(I), true);
207+
case DC_left: {
208+
auto LeftColor = llvm::WithColor(out, raw_ostream::RED);
209+
LeftColor << "< ";
210+
Log.getLeft(I)->print(LeftColor);
211+
LeftColor << '\n';
209212
break;
210-
case DC_right:
211-
out << "> ";
212-
Log.getRight(I)->print(dbgs()); dbgs() << '\n';
213-
//printValue(Log.getRight(I), false);
213+
}
214+
case DC_right: {
215+
auto RightColor = llvm::WithColor(out, raw_ostream::GREEN);
216+
RightColor << "> ";
217+
Log.getRight(I)->print(RightColor);
218+
RightColor << '\n';
214219
break;
215220
}
216-
//out << "\n";
221+
}
217222
}
218223
}

0 commit comments

Comments
 (0)