| 1 | //===------ dxcontainer2yaml.cpp - obj2yaml conversion tool -----*- C++ -*-===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "obj2yaml.h" |
| 10 | #include "llvm/MC/DXContainerInfo.h" |
| 11 | #include "llvm/Object/DXContainer.h" |
| 12 | #include "llvm/ObjectYAML/DXContainerYAML.h" |
| 13 | #include "llvm/Support/Error.h" |
| 14 | |
| 15 | #include <algorithm> |
| 16 | |
| 17 | using namespace llvm; |
| 18 | using namespace llvm::object; |
| 19 | |
| 20 | static Expected<DXContainerYAML::Object *> |
| 21 | dumpDXContainer(MemoryBufferRef Source) { |
| 22 | assert(file_magic::dxcontainer_object == identify_magic(Source.getBuffer())); |
| 23 | |
| 24 | Expected<DXContainer> ExDXC = DXContainer::create(Object: Source); |
| 25 | if (!ExDXC) |
| 26 | return ExDXC.takeError(); |
| 27 | DXContainer Container = *ExDXC; |
| 28 | |
| 29 | auto DXCYaml = DXContainerYAML::fromDXContainer(DXC&: Container); |
| 30 | if (!DXCYaml) |
| 31 | return DXCYaml.takeError(); |
| 32 | |
| 33 | return DXCYaml.get().release(); |
| 34 | } |
| 35 | |
| 36 | llvm::Error dxcontainer2yaml(llvm::raw_ostream &Out, |
| 37 | llvm::MemoryBufferRef Source) { |
| 38 | Expected<DXContainerYAML::Object *> YAMLOrErr = dumpDXContainer(Source); |
| 39 | if (!YAMLOrErr) |
| 40 | return YAMLOrErr.takeError(); |
| 41 | |
| 42 | std::unique_ptr<DXContainerYAML::Object> YAML(YAMLOrErr.get()); |
| 43 | yaml::Output Yout(Out); |
| 44 | Yout << *YAML; |
| 45 | |
| 46 | return Error::success(); |
| 47 | } |
| 48 |