DirectXShaderCompiler/tools/dsymutil/BinaryHolder.cpp

112 строки
3.6 KiB
C++
Исходник Обычный вид История

2016-12-28 22:52:27 +03:00
//===-- BinaryHolder.cpp --------------------------------------------------===//
Revert license text in banner comments to original llvm verbage (#33) Fix #30: Revert license text in banner comments to original llvm verbage This commit removes the Microsoft-specific copyright in llvm files and reverts the copyright wording to the original llvm wording. We used the following method to find the files to change: 1. Find all files in DirectXShaderCompiler that are also in llvm 3.7 2. For those files that have the Microsoft-specific copyright, revert it to the original llvm copyright as present in llvm 3.7 3. Revert the copyright in a few files that are not in llvm, but are mostly copies of files in llvm: lib\Transforms\Scalar\ScalarReplAggregatesHLSL.cpp lib\Transforms\Scalar\Reg2MemHLSL.cpp Leave the Microsoft-specific copyright header in files not present in stock llvm: include\dxc\* lib\HLSL\* lib\DxcSupport\* tools\clang\test\HLSL\* tools\clang\test\CodeGenHLSL\* tools\clang\unittests\HLSL\* tools\clang\unittests\HLSLHost\* tools\clang\tools\dxcompiler\* tools\clang\tools\dxa\* tools\clang\tools\dxc\* tools\clang\tools\dxopt\* tools\clang\tools\dxr\* tools\clang\tools\dxv\* tools\clang\tools\dotnetc\* utils\hct\* CONTRIBUTING.md COPYRIGHT LICENSE-MIT README.md cmake\modules\FindD3D12.cmake cmake\modules\FindDiaSDK.cmake cmake\modules\FindTAEF.cmake docs\DXIL.rst docs\HLSLChanges.rst docs\_themes\dxc-theme\layout.html docs\_themes\dxc-theme\theme.conf docs\_themes\dxc-theme\static\dxc-theme.css include\llvm\llvm_assert\assert.h include\llvm\llvm_assert\cassert include\llvm\Support\MSFileSystem.h include\llvm\Support\OacrIgnoreCond.h lib\MSSupport\CMakeLists.txt lib\MSSupport\MSFileSystemImpl.cpp lib\Support\assert.cpp lib\Support\MSFileSystemBasic.cpp lib\Support\Windows\MSFileSystem.inc.cpp lib\Transforms\Scalar\Reg2MemHLSL.cpp lib\Transforms\Scalar\ScalarReplAggregatesHLSL.cpp tools\clang\docs\UsingDxc.rst tools\clang\include\clang\AST\HlslTypes.h tools\clang\include\clang\Basic\BuiltinsDXIL.def tools\clang\include\clang\Basic\LangOptions.fixed.def tools\clang\include\clang\Parse\ParseHLSL.h tools\clang\include\clang\Sema\SemaHLSL.h tools\clang\lib\AST\ASTContextHLSL.cpp tools\clang\lib\AST\HlslTypes.cpp tools\clang\lib\CodeGen\CGHLSLMS.cpp tools\clang\lib\CodeGen\CGHLSLRuntime.cpp tools\clang\lib\CodeGen\CGHLSLRuntime.h tools\clang\lib\Frontend\Rewrite\FrontendActions_rewrite.cpp tools\clang\lib\Parse\HLSLRootSignature.cpp tools\clang\lib\Parse\HLSLRootSignature.h tools\clang\lib\Parse\ParseHLSL.cpp tools\clang\lib\Sema\gen_intrin_main_tables_15.h tools\clang\lib\Sema\SemaHLSL.cpp tools\clang\tools\d3dcomp\CMakeLists.txt tools\clang\tools\d3dcomp\d3dcomp.cpp tools\clang\tools\d3dcomp\d3dcomp.def tools\clang\tools\libclang\dxcisenseimpl.cpp tools\clang\tools\libclang\dxcisenseimpl.h tools\clang\tools\libclang\dxcrewriteunused.cpp tools\clang\tools\libclang\libclang.rc tools\dxexp\CMakeLists.txt tools\dxexp\dxexp.cpp tools\dxexp\LLVMBuild.txt
2017-01-25 04:54:00 +03:00
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This program is a utility that aims to be a dropin replacement for
// Darwin's dsymutil.
//
//===----------------------------------------------------------------------===//
2016-12-28 22:52:27 +03:00
#include "BinaryHolder.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
namespace dsymutil {
ErrorOr<MemoryBufferRef>
BinaryHolder::GetMemoryBufferForFile(StringRef Filename) {
if (Verbose)
outs() << "trying to open '" << Filename << "'\n";
// Try that first as it doesn't involve any filesystem access.
if (auto ErrOrArchiveMember = GetArchiveMemberBuffer(Filename))
return *ErrOrArchiveMember;
// If the name ends with a closing paren, there is a huge chance
// it is an archive member specification.
if (Filename.endswith(")"))
if (auto ErrOrArchiveMember = MapArchiveAndGetMemberBuffer(Filename))
return *ErrOrArchiveMember;
// Otherwise, just try opening a standard file. If this is an
// archive member specifiaction and any of the above didn't handle it
// (either because the archive is not there anymore, or because the
// archive doesn't contain the requested member), this will still
// provide a sensible error message.
auto ErrOrFile = MemoryBuffer::getFileOrSTDIN(Filename);
if (auto Err = ErrOrFile.getError())
return Err;
if (Verbose)
outs() << "\tloaded file.\n";
CurrentArchive.reset();
CurrentMemoryBuffer = std::move(ErrOrFile.get());
return CurrentMemoryBuffer->getMemBufferRef();
}
ErrorOr<MemoryBufferRef>
BinaryHolder::GetArchiveMemberBuffer(StringRef Filename) {
if (!CurrentArchive)
return make_error_code(errc::no_such_file_or_directory);
StringRef CurArchiveName = CurrentArchive->getFileName();
if (!Filename.startswith(Twine(CurArchiveName, "(").str()))
return make_error_code(errc::no_such_file_or_directory);
// Remove the archive name and the parens around the archive member name.
Filename = Filename.substr(CurArchiveName.size() + 1).drop_back();
for (const auto &Child : CurrentArchive->children()) {
if (auto NameOrErr = Child.getName())
if (*NameOrErr == Filename) {
if (Verbose)
outs() << "\tfound member in current archive.\n";
return Child.getMemoryBufferRef();
}
}
return make_error_code(errc::no_such_file_or_directory);
}
ErrorOr<MemoryBufferRef>
BinaryHolder::MapArchiveAndGetMemberBuffer(StringRef Filename) {
StringRef ArchiveFilename = Filename.substr(0, Filename.find('('));
auto ErrOrBuff = MemoryBuffer::getFileOrSTDIN(ArchiveFilename);
if (auto Err = ErrOrBuff.getError())
return Err;
if (Verbose)
outs() << "\topened new archive '" << ArchiveFilename << "'\n";
auto ErrOrArchive = object::Archive::create((*ErrOrBuff)->getMemBufferRef());
if (auto Err = ErrOrArchive.getError())
return Err;
CurrentArchive = std::move(*ErrOrArchive);
CurrentMemoryBuffer = std::move(*ErrOrBuff);
return GetArchiveMemberBuffer(Filename);
}
ErrorOr<const object::ObjectFile &>
BinaryHolder::GetObjectFile(StringRef Filename) {
auto ErrOrMemBufferRef = GetMemoryBufferForFile(Filename);
if (auto Err = ErrOrMemBufferRef.getError())
return Err;
auto ErrOrObjectFile =
object::ObjectFile::createObjectFile(*ErrOrMemBufferRef);
if (auto Err = ErrOrObjectFile.getError())
return Err;
CurrentObjectFile = std::move(*ErrOrObjectFile);
return *CurrentObjectFile;
}
}
}