mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 22:16:06 +00:00
[TextAPI] Refactor BinaryAttrs to InterfaceFile assignment (#81551)
Create a helper method for this operation, so it can be reused in multiple places. Additonally move FileType enum into its own header to avoid include cycles.
This commit is contained in:
parent
644ac2a018
commit
3a080a0195
49
llvm/include/llvm/TextAPI/FileTypes.h
Normal file
49
llvm/include/llvm/TextAPI/FileTypes.h
Normal file
@ -0,0 +1,49 @@
|
||||
//===- llvm/TextAPI/FileTypes.h - TAPI Interface File -----------*- 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TEXTAPI_FILETYPES_H
|
||||
#define LLVM_TEXTAPI_FILETYPES_H
|
||||
|
||||
#include "llvm/ADT/BitmaskEnum.h"
|
||||
namespace llvm::MachO {
|
||||
/// Defines the file type TextAPI files can represent.
|
||||
enum FileType : unsigned {
|
||||
/// Invalid file type.
|
||||
Invalid = 0U,
|
||||
|
||||
/// \brief MachO Dynamic Library file.
|
||||
MachO_DynamicLibrary = 1U << 0,
|
||||
|
||||
/// \brief MachO Dynamic Library Stub file.
|
||||
MachO_DynamicLibrary_Stub = 1U << 1,
|
||||
|
||||
/// \brief MachO Bundle file.
|
||||
MachO_Bundle = 1U << 2,
|
||||
|
||||
/// Text-based stub file (.tbd) version 1.0
|
||||
TBD_V1 = 1U << 3,
|
||||
|
||||
/// Text-based stub file (.tbd) version 2.0
|
||||
TBD_V2 = 1U << 4,
|
||||
|
||||
/// Text-based stub file (.tbd) version 3.0
|
||||
TBD_V3 = 1U << 5,
|
||||
|
||||
/// Text-based stub file (.tbd) version 4.0
|
||||
TBD_V4 = 1U << 6,
|
||||
|
||||
/// Text-based stub file (.tbd) version 5.0
|
||||
TBD_V5 = 1U << 7,
|
||||
|
||||
All = ~0U,
|
||||
|
||||
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/All),
|
||||
};
|
||||
|
||||
} // namespace llvm::MachO
|
||||
#endif // LLVM_TEXTAPI_FILETYPES_H
|
@ -14,14 +14,15 @@
|
||||
#ifndef LLVM_TEXTAPI_INTERFACEFILE_H
|
||||
#define LLVM_TEXTAPI_INTERFACEFILE_H
|
||||
|
||||
#include "llvm/ADT/BitmaskEnum.h"
|
||||
#include "llvm/ADT/Hashing.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/iterator.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/TextAPI/ArchitectureSet.h"
|
||||
#include "llvm/TextAPI/FileTypes.h"
|
||||
#include "llvm/TextAPI/PackedVersion.h"
|
||||
#include "llvm/TextAPI/Platform.h"
|
||||
#include "llvm/TextAPI/RecordsSlice.h"
|
||||
#include "llvm/TextAPI/Symbol.h"
|
||||
#include "llvm/TextAPI/SymbolSet.h"
|
||||
#include "llvm/TextAPI/Target.h"
|
||||
@ -47,44 +48,6 @@ enum class ObjCConstraintType : unsigned {
|
||||
GC = 4,
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
|
||||
/// Defines the file type this file represents.
|
||||
enum FileType : unsigned {
|
||||
/// Invalid file type.
|
||||
Invalid = 0U,
|
||||
|
||||
/// \brief MachO Dynamic Library file.
|
||||
MachO_DynamicLibrary = 1U << 0,
|
||||
|
||||
/// \brief MachO Dynamic Library Stub file.
|
||||
MachO_DynamicLibrary_Stub = 1U << 1,
|
||||
|
||||
/// \brief MachO Bundle file.
|
||||
MachO_Bundle = 1U << 2,
|
||||
|
||||
/// Text-based stub file (.tbd) version 1.0
|
||||
TBD_V1 = 1U << 3,
|
||||
|
||||
/// Text-based stub file (.tbd) version 2.0
|
||||
TBD_V2 = 1U << 4,
|
||||
|
||||
/// Text-based stub file (.tbd) version 3.0
|
||||
TBD_V3 = 1U << 5,
|
||||
|
||||
/// Text-based stub file (.tbd) version 4.0
|
||||
TBD_V4 = 1U << 6,
|
||||
|
||||
/// Text-based stub file (.tbd) version 5.0
|
||||
TBD_V5 = 1U << 7,
|
||||
|
||||
All = ~0U,
|
||||
|
||||
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/All),
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
|
||||
/// Reference to an interface file.
|
||||
class InterfaceFileRef {
|
||||
public:
|
||||
@ -437,6 +400,14 @@ public:
|
||||
void inlineLibrary(std::shared_ptr<InterfaceFile> Library,
|
||||
bool Overwrite = false);
|
||||
|
||||
/// Set InterfaceFile properties from pre-gathered binary attributes,
|
||||
/// if they are not set already.
|
||||
///
|
||||
/// \param BA Attributes typically represented in load commands.
|
||||
/// \param Targ MachO Target slice to add attributes to.
|
||||
void setFromBinaryAttrs(const RecordsSlice::BinaryAttrs &BA,
|
||||
const Target &Targ);
|
||||
|
||||
/// The equality is determined by attributes that impact linking
|
||||
/// compatibilities. Path, & FileKind are irrelevant since these by
|
||||
/// itself should not impact linking.
|
||||
|
@ -15,7 +15,7 @@
|
||||
#define LLVM_TEXTAPI_RECORDSLICE_H
|
||||
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/TextAPI/InterfaceFile.h"
|
||||
#include "llvm/TextAPI/FileTypes.h"
|
||||
#include "llvm/TextAPI/PackedVersion.h"
|
||||
#include "llvm/TextAPI/Record.h"
|
||||
#include "llvm/TextAPI/RecordVisitor.h"
|
||||
@ -191,6 +191,7 @@ private:
|
||||
};
|
||||
|
||||
using Records = llvm::SmallVector<std::shared_ptr<RecordsSlice>, 4>;
|
||||
class InterfaceFile;
|
||||
std::unique_ptr<InterfaceFile> convertToInterfaceFile(const Records &Slices);
|
||||
|
||||
} // namespace MachO
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "llvm/Object/MachOUniversal.h"
|
||||
#include "llvm/Support/Endian.h"
|
||||
#include "llvm/TargetParser/Triple.h"
|
||||
#include "llvm/TextAPI/InterfaceFile.h"
|
||||
#include "llvm/TextAPI/RecordsSlice.h"
|
||||
#include "llvm/TextAPI/TextAPIError.h"
|
||||
#include <iomanip>
|
||||
|
@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/TextAPI/InterfaceFile.h"
|
||||
#include "llvm/TextAPI/RecordsSlice.h"
|
||||
#include "llvm/TextAPI/TextAPIError.h"
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
@ -351,6 +352,34 @@ InterfaceFile::extract(Architecture Arch) const {
|
||||
return std::move(IF);
|
||||
}
|
||||
|
||||
void InterfaceFile::setFromBinaryAttrs(const RecordsSlice::BinaryAttrs &BA,
|
||||
const Target &Targ) {
|
||||
if (getFileType() != BA.File)
|
||||
setFileType(BA.File);
|
||||
if (getInstallName().empty())
|
||||
setInstallName(BA.InstallName);
|
||||
if (BA.AppExtensionSafe && !isApplicationExtensionSafe())
|
||||
setApplicationExtensionSafe();
|
||||
if (BA.TwoLevelNamespace && !isTwoLevelNamespace())
|
||||
setTwoLevelNamespace();
|
||||
if (BA.OSLibNotForSharedCache && !isOSLibNotForSharedCache())
|
||||
setOSLibNotForSharedCache();
|
||||
if (getCurrentVersion().empty())
|
||||
setCurrentVersion(BA.CurrentVersion);
|
||||
if (getCompatibilityVersion().empty())
|
||||
setCompatibilityVersion(BA.CompatVersion);
|
||||
if (getSwiftABIVersion() == 0)
|
||||
setSwiftABIVersion(BA.SwiftABI);
|
||||
if (getPath().empty())
|
||||
setPath(BA.Path);
|
||||
if (!BA.ParentUmbrella.empty())
|
||||
addParentUmbrella(Targ, BA.ParentUmbrella);
|
||||
for (const auto &Client : BA.AllowableClients)
|
||||
addAllowableClient(Client, Targ);
|
||||
for (const auto &Lib : BA.RexportedLibraries)
|
||||
addReexportedLibrary(Lib, Targ);
|
||||
}
|
||||
|
||||
static bool isYAMLTextStub(const FileType &Kind) {
|
||||
return (Kind >= FileType::TBD_V1) && (Kind < FileType::TBD_V5);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "llvm/TextAPI/RecordsSlice.h"
|
||||
#include "llvm/ADT/SetVector.h"
|
||||
#include "llvm/TextAPI/InterfaceFile.h"
|
||||
#include "llvm/TextAPI/Record.h"
|
||||
#include "llvm/TextAPI/Symbol.h"
|
||||
#include <utility>
|
||||
@ -325,28 +326,7 @@ createInterfaceFile(const Records &Slices, StringRef InstallName) {
|
||||
continue;
|
||||
const Target &Targ = S->getTarget();
|
||||
File->addTarget(Targ);
|
||||
if (File->getFileType() == FileType::Invalid)
|
||||
File->setFileType(BA.File);
|
||||
if (BA.AppExtensionSafe && !File->isApplicationExtensionSafe())
|
||||
File->setApplicationExtensionSafe();
|
||||
if (BA.TwoLevelNamespace && !File->isTwoLevelNamespace())
|
||||
File->setTwoLevelNamespace();
|
||||
if (BA.OSLibNotForSharedCache && !File->isOSLibNotForSharedCache())
|
||||
File->setOSLibNotForSharedCache();
|
||||
if (File->getCurrentVersion().empty())
|
||||
File->setCurrentVersion(BA.CurrentVersion);
|
||||
if (File->getCompatibilityVersion().empty())
|
||||
File->setCompatibilityVersion(BA.CompatVersion);
|
||||
if (File->getSwiftABIVersion() == 0)
|
||||
File->setSwiftABIVersion(BA.SwiftABI);
|
||||
if (File->getPath().empty())
|
||||
File->setPath(BA.Path);
|
||||
if (!BA.ParentUmbrella.empty())
|
||||
File->addParentUmbrella(Targ, BA.ParentUmbrella);
|
||||
for (const auto &Client : BA.AllowableClients)
|
||||
File->addAllowableClient(Client, Targ);
|
||||
for (const auto &Lib : BA.RexportedLibraries)
|
||||
File->addReexportedLibrary(Lib, Targ);
|
||||
File->setFromBinaryAttrs(BA, Targ);
|
||||
}
|
||||
|
||||
return File;
|
||||
|
@ -13,13 +13,12 @@
|
||||
#ifndef LLVM_TEXTAPI_MACHO_CONTEXT_H
|
||||
#define LLVM_TEXTAPI_MACHO_CONTEXT_H
|
||||
|
||||
#include "llvm/TextAPI/FileTypes.h"
|
||||
#include <string>
|
||||
|
||||
namespace llvm {
|
||||
namespace MachO {
|
||||
|
||||
enum FileType : unsigned;
|
||||
|
||||
struct TextAPIContext {
|
||||
std::string ErrorMessage;
|
||||
std::string Path;
|
||||
|
@ -13,6 +13,7 @@
|
||||
#ifndef LLVM_TEXTAPI_TEXT_STUB_COMMON_H
|
||||
#define LLVM_TEXTAPI_TEXT_STUB_COMMON_H
|
||||
|
||||
#include "llvm/ADT/BitmaskEnum.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/YAMLTraits.h"
|
||||
#include "llvm/TextAPI/Architecture.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user