diff options
author | vvvv <vvvv@ydb.tech> | 2024-02-06 20:01:22 +0300 |
---|---|---|
committer | vvvv <vvvv@ydb.tech> | 2024-02-06 20:22:16 +0300 |
commit | 0203b7a9a40828bb2bd4c32029b79ff0ea3d1f8f (patch) | |
tree | e630d0d5bd0bd29fc8c2d2842ed2cfde781b993a /contrib/libs/llvm16/tools/llvm-modextract | |
parent | ba27db76d99d12a4f1c06960b5449423218614c4 (diff) | |
download | ydb-0203b7a9a40828bb2bd4c32029b79ff0ea3d1f8f.tar.gz |
llvm16 targets
Diffstat (limited to 'contrib/libs/llvm16/tools/llvm-modextract')
-rw-r--r-- | contrib/libs/llvm16/tools/llvm-modextract/llvm-modextract.cpp | 86 | ||||
-rw-r--r-- | contrib/libs/llvm16/tools/llvm-modextract/ya.make | 48 |
2 files changed, 134 insertions, 0 deletions
diff --git a/contrib/libs/llvm16/tools/llvm-modextract/llvm-modextract.cpp b/contrib/libs/llvm16/tools/llvm-modextract/llvm-modextract.cpp new file mode 100644 index 0000000000..50f503ae0a --- /dev/null +++ b/contrib/libs/llvm16/tools/llvm-modextract/llvm-modextract.cpp @@ -0,0 +1,86 @@ +//===-- llvm-modextract.cpp - LLVM module extractor utility ---------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This program is for testing features that rely on multi-module bitcode files. +// It takes a multi-module bitcode file, extracts one of the modules and writes +// it to the output file. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Bitcode/BitcodeReader.h" +#include "llvm/Bitcode/BitcodeWriter.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/WithColor.h" + +using namespace llvm; + +static cl::OptionCategory ModextractCategory("Modextract Options"); + +static cl::opt<bool> + BinaryExtract("b", cl::desc("Whether to perform binary extraction"), + cl::cat(ModextractCategory)); + +static cl::opt<std::string> OutputFilename("o", cl::Required, + cl::desc("Output filename"), + cl::value_desc("filename"), + cl::cat(ModextractCategory)); + +static cl::opt<std::string> InputFilename(cl::Positional, + cl::desc("<input bitcode>"), + cl::init("-"), + cl::cat(ModextractCategory)); + +static cl::opt<unsigned> ModuleIndex("n", cl::Required, + cl::desc("Index of module to extract"), + cl::value_desc("index"), + cl::cat(ModextractCategory)); + +int main(int argc, char **argv) { + cl::HideUnrelatedOptions({&ModextractCategory, &getColorCategory()}); + cl::ParseCommandLineOptions(argc, argv, "Module extractor"); + + ExitOnError ExitOnErr("llvm-modextract: error: "); + + std::unique_ptr<MemoryBuffer> MB = + ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename))); + std::vector<BitcodeModule> Ms = ExitOnErr(getBitcodeModuleList(*MB)); + + LLVMContext Context; + if (ModuleIndex >= Ms.size()) { + errs() << "llvm-modextract: error: module index out of range; bitcode file " + "contains " + << Ms.size() << " module(s)\n"; + return 1; + } + + std::error_code EC; + std::unique_ptr<ToolOutputFile> Out( + new ToolOutputFile(OutputFilename, EC, sys::fs::OF_None)); + ExitOnErr(errorCodeToError(EC)); + + if (BinaryExtract) { + SmallVector<char, 0> Result; + BitcodeWriter Writer(Result); + Result.append(Ms[ModuleIndex].getBuffer().begin(), + Ms[ModuleIndex].getBuffer().end()); + Writer.copyStrtab(Ms[ModuleIndex].getStrtab()); + Out->os() << Result; + Out->keep(); + return 0; + } + + std::unique_ptr<Module> M = ExitOnErr(Ms[ModuleIndex].parseModule(Context)); + WriteBitcodeToFile(*M, Out->os()); + + Out->keep(); + return 0; +} diff --git a/contrib/libs/llvm16/tools/llvm-modextract/ya.make b/contrib/libs/llvm16/tools/llvm-modextract/ya.make new file mode 100644 index 0000000000..a736303b07 --- /dev/null +++ b/contrib/libs/llvm16/tools/llvm-modextract/ya.make @@ -0,0 +1,48 @@ +# Generated by devtools/yamaker. + +PROGRAM() + +LICENSE(Apache-2.0 WITH LLVM-exception) + +LICENSE_TEXTS(.yandex_meta/licenses.list.txt) + +PEERDIR( + contrib/libs/llvm16 + contrib/libs/llvm16/include + contrib/libs/llvm16/lib/Analysis + contrib/libs/llvm16/lib/AsmParser + contrib/libs/llvm16/lib/BinaryFormat + contrib/libs/llvm16/lib/Bitcode/Reader + contrib/libs/llvm16/lib/Bitcode/Writer + contrib/libs/llvm16/lib/Bitstream/Reader + contrib/libs/llvm16/lib/DebugInfo/CodeView + contrib/libs/llvm16/lib/DebugInfo/DWARF + contrib/libs/llvm16/lib/DebugInfo/MSF + contrib/libs/llvm16/lib/DebugInfo/PDB + contrib/libs/llvm16/lib/DebugInfo/Symbolize + contrib/libs/llvm16/lib/Demangle + contrib/libs/llvm16/lib/IR + contrib/libs/llvm16/lib/IRReader + contrib/libs/llvm16/lib/MC + contrib/libs/llvm16/lib/MC/MCParser + contrib/libs/llvm16/lib/Object + contrib/libs/llvm16/lib/ProfileData + contrib/libs/llvm16/lib/Remarks + contrib/libs/llvm16/lib/Support + contrib/libs/llvm16/lib/TargetParser + contrib/libs/llvm16/lib/TextAPI +) + +ADDINCL( + contrib/libs/llvm16/tools/llvm-modextract +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + +SRCS( + llvm-modextract.cpp +) + +END() |