Revert "Revert "llvm-strings: support printing the filename""

Change the dynamic files to static in the hope that it will actually fix the
transient errors that Ive been unable to reproduce.

llvm-svn: 286891
This commit is contained in:
Saleem Abdulrasool 2016-11-14 21:10:41 +00:00
parent 1cdd87adfd
commit f10a871419
6 changed files with 35 additions and 7 deletions

View File

@ -0,0 +1 @@
abcd

View File

@ -0,0 +1,9 @@
RUN: rm -f %T/archive.a
RUN: llvm-ar -format gnu crs %T/archive.a %S/Inputs/abcd
RUN: llvm-strings -f %T/archive.a | FileCheck %s
RUN: llvm-strings --print-file-name %T/archive.a | FileCheck %s
CHECK: archive.a: !<arch>
CHECK: archive.a: abcd/ 0 0 0 644 4 `
CHECK: archive.a: abcd

View File

@ -0,0 +1,3 @@
RUN: llvm-strings -f %S/Inputs/abcd | FileCheck %s
RUN: llvm-strings --print-file-name %S/Inputs/abcd | FileCheck %s
CHECK: {{[\\/]}}abcd: abcd

View File

@ -1,8 +1,7 @@
RUN: echo -n abcd > %T/abcd
RUN: rm -f %T/inner.ar
RUN: llvm-ar crs %T/inner.a %T/abcd
RUN: llvm-ar -format gnu crs %T/inner.a %S/Inputs/abcd
RUN: rm -f %T/outer.ar
RUN: llvm-ar crs %T/outer.a %T/inner.a
RUN: llvm-ar -format gnu crs %T/outer.a %T/inner.a
RUN: llvm-strings %T/outer.a | FileCheck %s
CHECK: !<arch>

View File

@ -0,0 +1,3 @@
RUN: echo abcd | llvm-strings -f - | FileCheck %s
RUN: echo abcd | llvm-strings --print-file-name - | FileCheck %s
CHECK: {standard input}: abcd

View File

@ -29,7 +29,19 @@ static cl::list<std::string> InputFileNames(cl::Positional,
cl::desc("<input object files>"),
cl::ZeroOrMore);
static void strings(raw_ostream &OS, StringRef Contents) {
static cl::opt<bool>
PrintFileName("print-file-name",
cl::desc("Print the name of the file before each string"));
static cl::alias PrintFileNameShort("f", cl::desc(""),
cl::aliasopt(PrintFileName));
static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) {
auto print = [&OS, FileName](StringRef L) {
if (PrintFileName)
OS << FileName << ": ";
OS << L << '\n';
};
const char *P = nullptr, *E = nullptr, *S = nullptr;
for (P = Contents.begin(), E = Contents.end(); P < E; ++P) {
if (std::isgraph(*P) || std::isblank(*P)) {
@ -37,12 +49,12 @@ static void strings(raw_ostream &OS, StringRef Contents) {
S = P;
} else if (S) {
if (P - S > 3)
OS << StringRef(S, P - S) << '\n';
print(StringRef(S, P - S));
S = nullptr;
}
}
if (S && E - S > 3)
OS << StringRef(S, E - S) << '\n';
print(StringRef(S, E - S));
}
int main(int argc, char **argv) {
@ -60,7 +72,8 @@ int main(int argc, char **argv) {
if (std::error_code EC = Buffer.getError())
errs() << File << ": " << EC.message() << '\n';
else
strings(llvm::outs(), Buffer.get()->getMemBufferRef().getBuffer());
strings(llvm::outs(), File == "-" ? "{standard input}" : File,
Buffer.get()->getMemBufferRef().getBuffer());
}
return EXIT_SUCCESS;