[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.
This commit is contained in:
Bertik23
2025-03-13 14:26:42 +01:00
committed by GitHub
parent 7e9802f348
commit b67379c35b

View File

@@ -14,6 +14,8 @@
#include "llvm/IR/Instructions.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -199,20 +201,23 @@ void DiffConsumer::logd(const DiffLogBuilder &Log) {
switch (Log.getLineKind(I)) {
case DC_match:
out << " ";
Log.getLeft(I)->print(dbgs()); dbgs() << '\n';
//printValue(Log.getLeft(I), true);
Log.getLeft(I)->print(dbgs());
dbgs() << '\n';
break;
case DC_left:
out << "< ";
Log.getLeft(I)->print(dbgs()); dbgs() << '\n';
//printValue(Log.getLeft(I), true);
break;
case DC_right:
out << "> ";
Log.getRight(I)->print(dbgs()); dbgs() << '\n';
//printValue(Log.getRight(I), false);
case DC_left: {
auto LeftColor = llvm::WithColor(out, raw_ostream::RED);
LeftColor << "< ";
Log.getLeft(I)->print(LeftColor);
LeftColor << '\n';
break;
}
//out << "\n";
case DC_right: {
auto RightColor = llvm::WithColor(out, raw_ostream::GREEN);
RightColor << "> ";
Log.getRight(I)->print(RightColor);
RightColor << '\n';
break;
}
}
}
}