mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:23:11 +01:00
Allow llvm-dis to disassemble multiple files
Differential Revision: https://reviews.llvm.org/D101110
This commit is contained in:
parent
ce786f30a4
commit
89fdd0e3a1
10
test/tools/llvm-dis/multiple-files.ll
Normal file
10
test/tools/llvm-dis/multiple-files.ll
Normal file
@ -0,0 +1,10 @@
|
||||
; RUN: llvm-as -o %t0 %s
|
||||
; RUN: cp %t0 %t1
|
||||
; RUN: not llvm-dis -o %t2 %t0 %t1 2>&1 | FileCheck %s --check-prefix ERROR
|
||||
; RUN: llvm-dis %t0 %t1
|
||||
; RUN: FileCheck %s < %t0.ll
|
||||
; RUN: FileCheck %s < %t1.ll
|
||||
; ERROR: error: output file name cannot be set for multiple input files
|
||||
|
||||
; CHECK: declare void @foo
|
||||
declare void @foo()
|
@ -35,8 +35,8 @@
|
||||
#include <system_error>
|
||||
using namespace llvm;
|
||||
|
||||
static cl::opt<std::string>
|
||||
InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
|
||||
static cl::list<std::string> InputFilenames(cl::Positional, cl::ZeroOrMore,
|
||||
cl::desc("[input bitcode]..."));
|
||||
|
||||
static cl::opt<std::string>
|
||||
OutputFilename("o", cl::desc("Override output filename"),
|
||||
@ -156,8 +156,17 @@ int main(int argc, char **argv) {
|
||||
std::make_unique<LLVMDisDiagnosticHandler>(argv[0]));
|
||||
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
|
||||
|
||||
std::unique_ptr<MemoryBuffer> MB =
|
||||
ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename)));
|
||||
if (InputFilenames.size() < 1) {
|
||||
InputFilenames.push_back("-");
|
||||
} else if (InputFilenames.size() > 1 && !OutputFilename.empty()) {
|
||||
errs()
|
||||
<< "error: output file name cannot be set for multiple input files\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (std::string InputFilename : InputFilenames) {
|
||||
std::unique_ptr<MemoryBuffer> MB = ExitOnErr(
|
||||
errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename)));
|
||||
|
||||
BitcodeFileContents IF = ExitOnErr(llvm::getBitcodeFileContents(*MB));
|
||||
|
||||
@ -166,10 +175,10 @@ int main(int argc, char **argv) {
|
||||
if (OutputFilename == "-" && N > 1)
|
||||
errs() << "only single module bitcode files can be written to stdout\n";
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
BitcodeModule MB = IF.Mods[i];
|
||||
std::unique_ptr<Module> M = ExitOnErr(MB.getLazyModule(Context, MaterializeMetadata,
|
||||
SetImporting));
|
||||
for (size_t I = 0; I < N; ++I) {
|
||||
BitcodeModule MB = IF.Mods[I];
|
||||
std::unique_ptr<Module> M = ExitOnErr(
|
||||
MB.getLazyModule(Context, MaterializeMetadata, SetImporting));
|
||||
if (MaterializeMetadata)
|
||||
ExitOnErr(M->materializeMetadata());
|
||||
else
|
||||
@ -193,12 +202,12 @@ int main(int argc, char **argv) {
|
||||
StringRef IFN = InputFilename;
|
||||
FinalFilename = (IFN.endswith(".bc") ? IFN.drop_back(3) : IFN).str();
|
||||
if (N > 1)
|
||||
FinalFilename += std::string(".") + std::to_string(i);
|
||||
FinalFilename += std::string(".") + std::to_string(I);
|
||||
FinalFilename += ".ll";
|
||||
}
|
||||
} else {
|
||||
if (N > 1)
|
||||
FinalFilename += std::string(".") + std::to_string(i);
|
||||
FinalFilename += std::string(".") + std::to_string(I);
|
||||
}
|
||||
|
||||
std::error_code EC;
|
||||
@ -223,6 +232,7 @@ int main(int argc, char **argv) {
|
||||
// Declare success.
|
||||
Out->keep();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user