2012-08-03 03:16:56 +08:00
|
|
|
//===- yaml2obj - Convert YAML to a binary object file --------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-08-03 03:16:56 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This program takes a YAML description of an object file and outputs the
|
|
|
|
// binary equivalent.
|
|
|
|
//
|
|
|
|
// This is used for writing tests that require binary files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
[yaml2obj] Move core yaml2obj code into lib and include for use in unit tests
Reviewers: jhenderson, rupprecht, MaskRay, grimar, labath
Reviewed By: rupprecht
Subscribers: gribozavr, mgrang, seiya, mgorny, sbc100, hiraditya, aheejin, jakehehrlich, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65255
llvm-svn: 368119
2019-08-07 10:44:49 +08:00
|
|
|
#include "llvm/ObjectYAML/yaml2obj.h"
|
2014-05-31 12:51:07 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2016-06-28 03:53:53 +08:00
|
|
|
#include "llvm/ObjectYAML/ObjectYAML.h"
|
2012-08-03 03:16:56 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2014-05-16 00:14:02 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2018-04-14 02:26:06 +08:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
2012-08-03 03:16:56 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2014-05-16 00:14:02 +08:00
|
|
|
#include "llvm/Support/ToolOutputFile.h"
|
[yaml2obj] Move core yaml2obj code into lib and include for use in unit tests
Reviewers: jhenderson, rupprecht, MaskRay, grimar, labath
Reviewed By: rupprecht
Subscribers: gribozavr, mgrang, seiya, mgorny, sbc100, hiraditya, aheejin, jakehehrlich, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65255
llvm-svn: 368119
2019-08-07 10:44:49 +08:00
|
|
|
#include "llvm/Support/WithColor.h"
|
2014-05-31 12:51:07 +08:00
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
2014-06-13 01:38:55 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <system_error>
|
2012-08-03 03:16:56 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
static cl::opt<std::string>
|
|
|
|
Input(cl::Positional, cl::desc("<input>"), cl::init("-"));
|
|
|
|
|
2014-05-31 12:51:07 +08:00
|
|
|
cl::opt<unsigned>
|
|
|
|
DocNum("docnum", cl::init(1),
|
|
|
|
cl::desc("Read specified document from input (default = 1)"));
|
|
|
|
|
2014-05-16 00:14:02 +08:00
|
|
|
static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
|
|
|
|
cl::value_desc("filename"));
|
2013-06-06 02:51:34 +08:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2018-04-14 02:26:06 +08:00
|
|
|
InitLLVM X(argc, argv);
|
2013-06-06 02:51:34 +08:00
|
|
|
cl::ParseCommandLineOptions(argc, argv);
|
|
|
|
|
2014-05-16 00:14:02 +08:00
|
|
|
if (OutputFilename.empty())
|
|
|
|
OutputFilename = "-";
|
|
|
|
|
2019-09-14 00:00:16 +08:00
|
|
|
auto ErrHandler = [](const Twine &Msg) {
|
|
|
|
WithColor::error(errs(), "yaml2obj") << Msg << "\n";
|
|
|
|
};
|
|
|
|
|
2014-08-26 02:16:47 +08:00
|
|
|
std::error_code EC;
|
2017-09-23 09:03:17 +08:00
|
|
|
std::unique_ptr<ToolOutputFile> Out(
|
2019-08-05 13:43:48 +08:00
|
|
|
new ToolOutputFile(OutputFilename, EC, sys::fs::OF_None));
|
2019-09-14 00:00:16 +08:00
|
|
|
if (EC) {
|
|
|
|
ErrHandler("failed to open '" + OutputFilename + "': " + EC.message());
|
|
|
|
return 1;
|
|
|
|
}
|
2014-05-16 00:14:02 +08:00
|
|
|
|
2014-07-07 01:43:13 +08:00
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf =
|
|
|
|
MemoryBuffer::getFileOrSTDIN(Input);
|
|
|
|
if (!Buf)
|
2013-06-06 02:51:34 +08:00
|
|
|
return 1;
|
2014-05-16 00:14:02 +08:00
|
|
|
|
2019-04-25 17:59:55 +08:00
|
|
|
yaml::Input YIn(Buf.get()->getBuffer());
|
2019-09-14 00:00:16 +08:00
|
|
|
if (!convertYAML(YIn, Out->os(), ErrHandler, DocNum))
|
[yaml2obj] Move core yaml2obj code into lib and include for use in unit tests
Reviewers: jhenderson, rupprecht, MaskRay, grimar, labath
Reviewed By: rupprecht
Subscribers: gribozavr, mgrang, seiya, mgorny, sbc100, hiraditya, aheejin, jakehehrlich, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65255
llvm-svn: 368119
2019-08-07 10:44:49 +08:00
|
|
|
return 1;
|
2014-05-16 00:14:02 +08:00
|
|
|
|
[yaml2obj] Move core yaml2obj code into lib and include for use in unit tests
Reviewers: jhenderson, rupprecht, MaskRay, grimar, labath
Reviewed By: rupprecht
Subscribers: gribozavr, mgrang, seiya, mgorny, sbc100, hiraditya, aheejin, jakehehrlich, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65255
llvm-svn: 368119
2019-08-07 10:44:49 +08:00
|
|
|
Out->keep();
|
2017-06-16 07:44:19 +08:00
|
|
|
Out->os().flush();
|
[yaml2obj] Move core yaml2obj code into lib and include for use in unit tests
Reviewers: jhenderson, rupprecht, MaskRay, grimar, labath
Reviewed By: rupprecht
Subscribers: gribozavr, mgrang, seiya, mgorny, sbc100, hiraditya, aheejin, jakehehrlich, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65255
llvm-svn: 368119
2019-08-07 10:44:49 +08:00
|
|
|
return 0;
|
2012-08-03 03:16:56 +08:00
|
|
|
}
|