llvm.org GIT mirror llvm / 926273d
[yaml2obj] Add "-o" command line option to specify an output file name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208900 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Atanasyan 5 years ago
4 changed file(s) with 39 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
0 # RUN: yaml2obj -format=elf %s | llvm-readobj -sections -section-data - | FileCheck %s
1 # RUN: yaml2obj -format=elf -o %t %s
2 # RUN: llvm-readobj -sections -section-data %t | FileCheck %s
3
14 !ELF
25 FileHeader:
36 Class: ELFCLASS64
0 RUN: yaml2obj %p/Inputs/COFF/i386.yaml | llvm-readobj -file-headers -relocations -expand-relocs - | FileCheck %s --check-prefix COFF-I386
1 RUN: yaml2obj -o %t %p/Inputs/COFF/i386.yaml
2 RUN: llvm-readobj -file-headers -relocations -expand-relocs %t \
3 RUN: | FileCheck %s --check-prefix COFF-I386
14
25 // COFF-I386: Characteristics [ (0x200)
36 // COFF-I386-NEXT: IMAGE_FILE_DEBUG_STRIPPED (0x200)
476476 typedef ELFType BE32;
477477 if (is64Bit(Doc)) {
478478 if (isLittleEndian(Doc))
479 return ELFState::writeELF(outs(), Doc);
479 return ELFState::writeELF(Out, Doc);
480480 else
481 return ELFState::writeELF(outs(), Doc);
481 return ELFState::writeELF(Out, Doc);
482482 } else {
483483 if (isLittleEndian(Doc))
484 return ELFState::writeELF(outs(), Doc);
484 return ELFState::writeELF(Out, Doc);
485485 else
486 return ELFState::writeELF(outs(), Doc);
487 }
488 }
486 return ELFState::writeELF(Out, Doc);
487 }
488 }
1515
1616 #include "yaml2obj.h"
1717 #include "llvm/Support/CommandLine.h"
18 #include "llvm/Support/FileSystem.h"
1819 #include "llvm/Support/ManagedStatic.h"
1920 #include "llvm/Support/MemoryBuffer.h"
2021 #include "llvm/Support/PrettyStackTrace.h"
2122 #include "llvm/Support/Signals.h"
2223 #include "llvm/Support/raw_ostream.h"
2324 #include "llvm/Support/system_error.h"
25 #include "llvm/Support/ToolOutputFile.h"
2426
2527 using namespace llvm;
2628
4850 clEnumValN(YOF_ELF, "elf", "ELF object file format"),
4951 clEnumValEnd));
5052
53 static cl::opt OutputFilename("o", cl::desc("Output filename"),
54 cl::value_desc("filename"));
5155
5256 int main(int argc, char **argv) {
5357 cl::ParseCommandLineOptions(argc, argv);
5559 PrettyStackTraceProgram X(argc, argv);
5660 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
5761
62 if (OutputFilename.empty())
63 OutputFilename = "-";
64
65 std::string ErrorInfo;
66 std::unique_ptr Out(
67 new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
68 if (!ErrorInfo.empty()) {
69 errs() << ErrorInfo << '\n';
70 return 1;
71 }
72
5873 std::unique_ptr Buf;
5974 if (MemoryBuffer::getFileOrSTDIN(Input, Buf))
6075 return 1;
61 if (Format == YOF_COFF) {
62 return yaml2coff(outs(), Buf.get());
63 } else if (Format == YOF_ELF) {
64 return yaml2elf(outs(), Buf.get());
65 } else {
76
77 int Res = 1;
78 if (Format == YOF_COFF)
79 Res = yaml2coff(Out->os(), Buf.get());
80 else if (Format == YOF_ELF)
81 Res = yaml2elf(Out->os(), Buf.get());
82 else
6683 errs() << "Not yet implemented\n";
67 return 1;
68 }
84
85 if (Res == 0)
86 Out->keep();
87
88 return Res;
6989 }