[llvm] r208900 - [yaml2obj] Add "-o" command line option to specify an output file name.
Simon Atanasyan
simon at atanasyan.com
Thu May 15 09:14:02 PDT 2014
Author: atanasyan
Date: Thu May 15 11:14:02 2014
New Revision: 208900
URL: http://llvm.org/viewvc/llvm-project?rev=208900&view=rev
Log:
[yaml2obj] Add "-o" command line option to specify an output file name.
Modified:
llvm/trunk/test/Object/yaml2obj-elf-section-basic.yaml
llvm/trunk/test/Object/yaml2obj-readobj.test
llvm/trunk/tools/yaml2obj/yaml2elf.cpp
llvm/trunk/tools/yaml2obj/yaml2obj.cpp
Modified: llvm/trunk/test/Object/yaml2obj-elf-section-basic.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/yaml2obj-elf-section-basic.yaml?rev=208900&r1=208899&r2=208900&view=diff
==============================================================================
--- llvm/trunk/test/Object/yaml2obj-elf-section-basic.yaml (original)
+++ llvm/trunk/test/Object/yaml2obj-elf-section-basic.yaml Thu May 15 11:14:02 2014
@@ -1,4 +1,7 @@
# RUN: yaml2obj -format=elf %s | llvm-readobj -sections -section-data - | FileCheck %s
+# RUN: yaml2obj -format=elf -o %t %s
+# RUN: llvm-readobj -sections -section-data %t | FileCheck %s
+
!ELF
FileHeader:
Class: ELFCLASS64
Modified: llvm/trunk/test/Object/yaml2obj-readobj.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/yaml2obj-readobj.test?rev=208900&r1=208899&r2=208900&view=diff
==============================================================================
--- llvm/trunk/test/Object/yaml2obj-readobj.test (original)
+++ llvm/trunk/test/Object/yaml2obj-readobj.test Thu May 15 11:14:02 2014
@@ -1,4 +1,7 @@
RUN: yaml2obj %p/Inputs/COFF/i386.yaml | llvm-readobj -file-headers -relocations -expand-relocs - | FileCheck %s --check-prefix COFF-I386
+RUN: yaml2obj -o %t %p/Inputs/COFF/i386.yaml
+RUN: llvm-readobj -file-headers -relocations -expand-relocs %t \
+RUN: | FileCheck %s --check-prefix COFF-I386
// COFF-I386: Characteristics [ (0x200)
// COFF-I386-NEXT: IMAGE_FILE_DEBUG_STRIPPED (0x200)
Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=208900&r1=208899&r2=208900&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Thu May 15 11:14:02 2014
@@ -477,13 +477,13 @@ int yaml2elf(llvm::raw_ostream &Out, llv
typedef ELFType<support::big, 4, false> BE32;
if (is64Bit(Doc)) {
if (isLittleEndian(Doc))
- return ELFState<LE64>::writeELF(outs(), Doc);
+ return ELFState<LE64>::writeELF(Out, Doc);
else
- return ELFState<BE64>::writeELF(outs(), Doc);
+ return ELFState<BE64>::writeELF(Out, Doc);
} else {
if (isLittleEndian(Doc))
- return ELFState<LE32>::writeELF(outs(), Doc);
+ return ELFState<LE32>::writeELF(Out, Doc);
else
- return ELFState<BE32>::writeELF(outs(), Doc);
+ return ELFState<BE32>::writeELF(Out, Doc);
}
}
Modified: llvm/trunk/tools/yaml2obj/yaml2obj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2obj.cpp?rev=208900&r1=208899&r2=208900&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2obj.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2obj.cpp Thu May 15 11:14:02 2014
@@ -16,12 +16,14 @@
#include "yaml2obj.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/system_error.h"
+#include "llvm/Support/ToolOutputFile.h"
using namespace llvm;
@@ -49,6 +51,8 @@ cl::opt<YAMLObjectFormat> Format(
clEnumValN(YOF_ELF, "elf", "ELF object file format"),
clEnumValEnd));
+static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
+ cl::value_desc("filename"));
int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv);
@@ -56,15 +60,31 @@ int main(int argc, char **argv) {
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+ if (OutputFilename.empty())
+ OutputFilename = "-";
+
+ std::string ErrorInfo;
+ std::unique_ptr<tool_output_file> Out(
+ new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
+ if (!ErrorInfo.empty()) {
+ errs() << ErrorInfo << '\n';
+ return 1;
+ }
+
std::unique_ptr<MemoryBuffer> Buf;
if (MemoryBuffer::getFileOrSTDIN(Input, Buf))
return 1;
- if (Format == YOF_COFF) {
- return yaml2coff(outs(), Buf.get());
- } else if (Format == YOF_ELF) {
- return yaml2elf(outs(), Buf.get());
- } else {
+
+ int Res = 1;
+ if (Format == YOF_COFF)
+ Res = yaml2coff(Out->os(), Buf.get());
+ else if (Format == YOF_ELF)
+ Res = yaml2elf(Out->os(), Buf.get());
+ else
errs() << "Not yet implemented\n";
- return 1;
- }
+
+ if (Res == 0)
+ Out->keep();
+
+ return Res;
}
More information about the llvm-commits
mailing list