#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;
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);
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;
}