Skip to content

Commit 188ef65

Browse files
authored
[libclc][remangler] Teach the remangler to emit text (#8199)
Most llvm / UNIX tools accept input on stdin and emit it to stdout by default. Most llvm tools also allow emitting textual assembly rather than bitcode. This isn't hugely important here as it's a build-time tool, but it does make debugging easier. As a side-effect of this change diagnostics go to stderr where they should always go.
1 parent 8fdc68d commit 188ef65

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

libclc/utils/libclc-remangler/LibclcRemangler.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static llvm::cl::OptionCategory
7070
static cl::opt<std::string>
7171
InputIRFilename("input-ir", cl::desc("<input bitcode>"),
7272
cl::cat(LibCLCRemanglerToolCategory));
73-
static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"));
73+
static cl::opt<std::string> OutputFilename("o", cl::init("-"),
74+
cl::desc("Output filename"));
7475
static cl::opt<SupportedLongWidth>
7576
LongWidth("long-width",
7677
cl::values(clEnumValN(SupportedLongWidth::L32, "l32",
@@ -87,6 +88,9 @@ static cl::opt<Signedness> CharSignedness(
8788
static cl::opt<bool> Verbose("v", cl::desc("Enable verbose output"),
8889
cl::init(false),
8990
cl::cat(LibCLCRemanglerToolCategory));
91+
static cl::opt<bool> TextualOut("S", cl::desc("Emit LLVM textual assembly"),
92+
cl::init(false),
93+
cl::cat(LibCLCRemanglerToolCategory));
9094
static cl::opt<bool> TestRun("t", cl::desc("Enable test run"), cl::init(false),
9195
cl::cat(LibCLCRemanglerToolCategory));
9296

@@ -842,8 +846,8 @@ class LibCLCRemangler : public ASTConsumer {
842846
Function *NewF = CloneFunction(Clonee, Dummy);
843847
NewF->setName(std::string(CloneName));
844848
} else if (Verbose) {
845-
std::cout << "Could not create copy " << CloneName.data() << " : missing "
846-
<< CloneeName.data() << std::endl;
849+
errs() << "Could not create copy " << CloneName.data() << " : missing "
850+
<< CloneeName.data() << '\n';
847851
}
848852

849853
return true;
@@ -874,16 +878,15 @@ class LibCLCRemangler : public ASTConsumer {
874878

875879
if (RemangledName != MangledName) {
876880
if (Verbose || TestRun) {
877-
std::cout << "Mangling changed:"
878-
<< "\n"
879-
<< "Original: " << MangledName << "\n"
880-
<< "New: " << RemangledName << "\n"
881-
<< std::endl;
881+
errs() << "Mangling changed:"
882+
<< "\n"
883+
<< "Original: " << MangledName << "\n"
884+
<< "New: " << RemangledName << "\n";
882885
}
883886
// In test run mode, where no substitution is made, change in mangling
884887
// name represents a failure. Report an error.
885888
if (TestRun) {
886-
std::cout << "Test run failure!" << std::endl;
889+
errs() << "Test run failure!\n";
887890
return false;
888891
}
889892
Func.setName(RemangledName);
@@ -934,12 +937,14 @@ class LibCLCRemangler : public ASTConsumer {
934937

935938
if (TestRun) {
936939
if (Verbose)
937-
std::cout << "Successfully processed: " << NumProcessed << " functions."
938-
<< std::endl;
940+
errs() << "Successfully processed: " << NumProcessed << " functions.\n";
939941
return;
940942
}
941943

942-
WriteBitcodeToFile(*M, Out->os());
944+
if (TextualOut)
945+
M->print(Out->os(), nullptr, true);
946+
else
947+
WriteBitcodeToFile(*M, Out->os());
943948

944949
// Declare success.
945950
Out->keep();

0 commit comments

Comments
 (0)