CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
83 lines
2.6 KiB
C++
83 lines
2.6 KiB
C++
//===------ offload2yaml.cpp - obj2yaml conversion tool ---*- C++ -------*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "obj2yaml.h"
|
|
#include "llvm/BinaryFormat/Magic.h"
|
|
#include "llvm/Object/OffloadBinary.h"
|
|
#include "llvm/ObjectYAML/OffloadYAML.h"
|
|
#include "llvm/Support/StringSaver.h"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
|
|
void populateYAML(OffloadYAML::Binary &YAMLBinary,
|
|
ArrayRef<std::unique_ptr<object::OffloadBinary>> OBinaries,
|
|
UniqueStringSaver Saver) {
|
|
for (const auto &OBinaryPtr : OBinaries) {
|
|
object::OffloadBinary &OB = *OBinaryPtr;
|
|
|
|
YAMLBinary.Members.emplace_back();
|
|
auto &Member = YAMLBinary.Members.back();
|
|
Member.ImageKind = OB.getImageKind();
|
|
Member.OffloadKind = OB.getOffloadKind();
|
|
Member.Flags = OB.getFlags();
|
|
if (!OB.strings().empty()) {
|
|
Member.StringEntries = std::vector<OffloadYAML::Binary::StringEntry>();
|
|
for (const auto &StringEntry : OB.strings())
|
|
Member.StringEntries->emplace_back(OffloadYAML::Binary::StringEntry(
|
|
{Saver.save(StringEntry.first), Saver.save(StringEntry.second)}));
|
|
}
|
|
|
|
if (!OB.getImage().empty())
|
|
Member.Content = arrayRefFromStringRef(OB.getImage());
|
|
}
|
|
}
|
|
|
|
Expected<OffloadYAML::Binary *> dump(MemoryBufferRef Source,
|
|
UniqueStringSaver Saver) {
|
|
std::unique_ptr<OffloadYAML::Binary> YAMLBinary =
|
|
std::make_unique<OffloadYAML::Binary>();
|
|
|
|
YAMLBinary->Members = std::vector<OffloadYAML::Binary::Member>();
|
|
|
|
uint64_t Offset = 0;
|
|
while (Offset < Source.getBufferSize()) {
|
|
MemoryBufferRef Buffer = MemoryBufferRef(
|
|
Source.getBuffer().drop_front(Offset), Source.getBufferIdentifier());
|
|
auto BinariesOrErr = object::OffloadBinary::create(Buffer);
|
|
if (!BinariesOrErr)
|
|
return BinariesOrErr.takeError();
|
|
|
|
SmallVector<std::unique_ptr<object::OffloadBinary>> &Binaries =
|
|
*BinariesOrErr;
|
|
populateYAML(*YAMLBinary, Binaries, Saver);
|
|
|
|
Offset += Binaries[0]->getSize();
|
|
}
|
|
|
|
return YAMLBinary.release();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
Error offload2yaml(raw_ostream &Out, MemoryBufferRef Source) {
|
|
BumpPtrAllocator Alloc;
|
|
UniqueStringSaver Saver(Alloc);
|
|
|
|
Expected<OffloadYAML::Binary *> YAMLOrErr = dump(Source, Saver);
|
|
if (!YAMLOrErr)
|
|
return YAMLOrErr.takeError();
|
|
|
|
std::unique_ptr<OffloadYAML::Binary> YAML(YAMLOrErr.get());
|
|
yaml::Output Yout(Out);
|
|
Yout << *YAML;
|
|
|
|
return Error::success();
|
|
}
|