diff options
Diffstat (limited to 'llvm/lib/TextAPI')
-rw-r--r-- | llvm/lib/TextAPI/MachO/Architecture.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/TextAPI/MachO/ArchitectureSet.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/TextAPI/MachO/InterfaceFile.cpp | 28 | ||||
-rw-r--r-- | llvm/lib/TextAPI/MachO/TextAPIContext.h | 1 | ||||
-rw-r--r-- | llvm/lib/TextAPI/MachO/TextStub.cpp | 31 | ||||
-rw-r--r-- | llvm/lib/TextAPI/MachO/TextStubCommon.cpp | 14 | ||||
-rw-r--r-- | llvm/lib/TextAPI/MachO/TextStubCommon.h | 1 |
7 files changed, 66 insertions, 37 deletions
diff --git a/llvm/lib/TextAPI/MachO/Architecture.cpp b/llvm/lib/TextAPI/MachO/Architecture.cpp index 699fb5f4587a..0c5988030336 100644 --- a/llvm/lib/TextAPI/MachO/Architecture.cpp +++ b/llvm/lib/TextAPI/MachO/Architecture.cpp @@ -12,13 +12,16 @@ #include "llvm/TextAPI/MachO/Architecture.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/Triple.h" #include "llvm/BinaryFormat/MachO.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/TextAPI/MachO/ArchitectureSet.h" namespace llvm { namespace MachO { Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType) { -#define ARCHINFO(Arch, Type, Subtype) \ +#define ARCHINFO(Arch, Type, Subtype, NumBits) \ if (CPUType == (Type) && \ (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \ return AK_##Arch; @@ -30,7 +33,7 @@ Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType) { Architecture getArchitectureFromName(StringRef Name) { return StringSwitch<Architecture>(Name) -#define ARCHINFO(Arch, Type, Subtype) .Case(#Arch, AK_##Arch) +#define ARCHINFO(Arch, Type, Subtype, NumBits) .Case(#Arch, AK_##Arch) #include "llvm/TextAPI/MachO/Architecture.def" #undef ARCHINFO .Default(AK_unknown); @@ -38,7 +41,7 @@ Architecture getArchitectureFromName(StringRef Name) { StringRef getArchitectureName(Architecture Arch) { switch (Arch) { -#define ARCHINFO(Arch, Type, Subtype) \ +#define ARCHINFO(Arch, Type, Subtype, NumBits) \ case AK_##Arch: \ return #Arch; #include "llvm/TextAPI/MachO/Architecture.def" @@ -54,7 +57,7 @@ StringRef getArchitectureName(Architecture Arch) { std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch) { switch (Arch) { -#define ARCHINFO(Arch, Type, Subtype) \ +#define ARCHINFO(Arch, Type, Subtype, NumBits) \ case AK_##Arch: \ return std::make_pair(Type, Subtype); #include "llvm/TextAPI/MachO/Architecture.def" @@ -72,6 +75,20 @@ Architecture mapToArchitecture(const Triple &Target) { return getArchitectureFromName(Target.getArchName()); } +bool is64Bit(Architecture Arch) { + switch (Arch) { +#define ARCHINFO(Arch, Type, Subtype, NumBits) \ + case AK_##Arch: \ + return NumBits == 64; +#include "llvm/TextAPI/MachO/Architecture.def" +#undef ARCHINFO + case AK_unknown: + return false; + } + + llvm_unreachable("Fully handled switch case above."); +} + raw_ostream &operator<<(raw_ostream &OS, Architecture Arch) { OS << getArchitectureName(Arch); return OS; diff --git a/llvm/lib/TextAPI/MachO/ArchitectureSet.cpp b/llvm/lib/TextAPI/MachO/ArchitectureSet.cpp index c589671199b7..f665706fad81 100644 --- a/llvm/lib/TextAPI/MachO/ArchitectureSet.cpp +++ b/llvm/lib/TextAPI/MachO/ArchitectureSet.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "llvm/TextAPI/MachO/ArchitectureSet.h" +#include "llvm/Support/raw_ostream.h" namespace llvm { namespace MachO { @@ -40,7 +41,7 @@ ArchitectureSet::operator std::string() const { std::string result; auto size = count(); for (auto arch : *this) { - result.append(getArchitectureName(arch)); + result.append(std::string(getArchitectureName(arch))); size -= 1; if (size) result.append(" "); diff --git a/llvm/lib/TextAPI/MachO/InterfaceFile.cpp b/llvm/lib/TextAPI/MachO/InterfaceFile.cpp index c40a952a6a8b..64d2c3e865ab 100644 --- a/llvm/lib/TextAPI/MachO/InterfaceFile.cpp +++ b/llvm/lib/TextAPI/MachO/InterfaceFile.cpp @@ -14,9 +14,10 @@ #include <iomanip> #include <sstream> -namespace llvm { -namespace MachO { -namespace detail { +using namespace llvm; +using namespace llvm::MachO; + +namespace { template <typename C> typename C::iterator addEntry(C &Container, StringRef InstallName) { auto I = partition_point(Container, [=](const InterfaceFileRef &O) { @@ -39,21 +40,21 @@ typename C::iterator addEntry(C &Container, const Target &Target_) { return Container.insert(Iter, Target_); } -} // end namespace detail. +} // end namespace void InterfaceFileRef::addTarget(const Target &Target) { - detail::addEntry(Targets, Target); + addEntry(Targets, Target); } void InterfaceFile::addAllowableClient(StringRef InstallName, const Target &Target) { - auto Client = detail::addEntry(AllowableClients, InstallName); + auto Client = addEntry(AllowableClients, InstallName); Client->addTarget(Target); } void InterfaceFile::addReexportedLibrary(StringRef InstallName, const Target &Target) { - auto Lib = detail::addEntry(ReexportedLibraries, InstallName); + auto Lib = addEntry(ReexportedLibraries, InstallName); Lib->addTarget(Target); } @@ -63,11 +64,11 @@ void InterfaceFile::addParentUmbrella(const Target &Target_, StringRef Parent) { Target RHS) { return LHS.first < RHS; }); if ((Iter != ParentUmbrellas.end()) && !(Target_ < Iter->first)) { - Iter->second = Parent; + Iter->second = std::string(Parent); return; } - ParentUmbrellas.emplace(Iter, Target_, Parent); + ParentUmbrellas.emplace(Iter, Target_, std::string(Parent)); return; } @@ -77,11 +78,11 @@ void InterfaceFile::addUUID(const Target &Target_, StringRef UUID) { Target RHS) { return LHS.first < RHS; }); if ((Iter != UUIDs.end()) && !(Target_ < Iter->first)) { - Iter->second = UUID; + Iter->second = std::string(UUID); return; } - UUIDs.emplace(Iter, Target_, UUID); + UUIDs.emplace(Iter, Target_, std::string(UUID)); return; } @@ -97,7 +98,7 @@ void InterfaceFile::addUUID(const Target &Target, uint8_t UUID[16]) { } void InterfaceFile::addTarget(const Target &Target) { - detail::addEntry(Targets, Target); + addEntry(Targets, Target); } InterfaceFile::const_filtered_target_range @@ -118,6 +119,3 @@ void InterfaceFile::addSymbol(SymbolKind Kind, StringRef Name, for (const auto &Target : Targets) result.first->second->addTarget(Target); } - -} // end namespace MachO. -} // end namespace llvm. diff --git a/llvm/lib/TextAPI/MachO/TextAPIContext.h b/llvm/lib/TextAPI/MachO/TextAPIContext.h index 3df40f09f7f7..217d1f5400ee 100644 --- a/llvm/lib/TextAPI/MachO/TextAPIContext.h +++ b/llvm/lib/TextAPI/MachO/TextAPIContext.h @@ -13,7 +13,6 @@ #ifndef LLVM_TEXTAPI_MACHO_CONTEXT_H #define LLVM_TEXTAPI_MACHO_CONTEXT_H -#include "llvm/Support/MemoryBuffer.h" #include <string> namespace llvm { diff --git a/llvm/lib/TextAPI/MachO/TextStub.cpp b/llvm/lib/TextAPI/MachO/TextStub.cpp index 0584e43d5893..141f897fb564 100644 --- a/llvm/lib/TextAPI/MachO/TextStub.cpp +++ b/llvm/lib/TextAPI/MachO/TextStub.cpp @@ -412,8 +412,10 @@ template <> struct ScalarTraits<Target> { static StringRef input(StringRef Scalar, void *, Target &Value) { auto Result = Target::create(Scalar); - if (!Result) - return toString(Result.takeError()); + if (!Result) { + consumeError(Result.takeError()); + return "unparsable target"; + } Value = *Result; if (Value.Arch == AK_unknown) @@ -450,10 +452,8 @@ template <> struct MappingTraits<const InterfaceFile *> { if (File->isInstallAPI()) Flags |= TBDFlags::InstallAPI; - for (const auto &Iter : File->umbrellas()) { - ParentUmbrella = Iter.second; - break; - } + if (!File->umbrellas().empty()) + ParentUmbrella = File->umbrellas().begin()->second; std::set<ArchitectureSet> ArchSet; for (const auto &Library : File->allowableClients()) @@ -959,7 +959,8 @@ template <> struct MappingTraits<const InterfaceFile *> { for (auto &sym : CurrentSection.WeakSymbols) File->addSymbol(SymbolKind::GlobalSymbol, sym, - CurrentSection.Targets); + CurrentSection.Targets, SymbolFlags::WeakDefined); + for (auto &sym : CurrentSection.TlvSymbols) File->addSymbol(SymbolKind::GlobalSymbol, sym, CurrentSection.Targets, @@ -1088,8 +1089,8 @@ struct DocumentListTraits<std::vector<const MachO::InterfaceFile *>> { }; } // end namespace yaml. +} // namespace llvm -namespace MachO { static void DiagHandler(const SMDiagnostic &Diag, void *Context) { auto *File = static_cast<TextAPIContext *>(Context); SmallString<1024> Message; @@ -1107,7 +1108,7 @@ static void DiagHandler(const SMDiagnostic &Diag, void *Context) { Expected<std::unique_ptr<InterfaceFile>> TextAPIReader::get(MemoryBufferRef InputBuffer) { TextAPIContext Ctx; - Ctx.Path = InputBuffer.getBufferIdentifier(); + Ctx.Path = std::string(InputBuffer.getBufferIdentifier()); yaml::Input YAMLIn(InputBuffer.getBuffer(), &Ctx, DiagHandler, &Ctx); // Fill vector with interface file objects created by parsing the YAML file. @@ -1119,6 +1120,10 @@ TextAPIReader::get(MemoryBufferRef InputBuffer) { auto File = std::unique_ptr<InterfaceFile>( const_cast<InterfaceFile *>(Files.front())); + for (auto Iter = std::next(Files.begin()); Iter != Files.end(); ++Iter) + File->addDocument( + std::shared_ptr<InterfaceFile>(const_cast<InterfaceFile *>(*Iter))); + if (YAMLIn.error()) return make_error<StringError>(Ctx.ErrorMessage, YAMLIn.error()); @@ -1127,18 +1132,18 @@ TextAPIReader::get(MemoryBufferRef InputBuffer) { Error TextAPIWriter::writeToStream(raw_ostream &OS, const InterfaceFile &File) { TextAPIContext Ctx; - Ctx.Path = File.getPath(); + Ctx.Path = std::string(File.getPath()); Ctx.FileKind = File.getFileType(); llvm::yaml::Output YAMLOut(OS, &Ctx, /*WrapColumn=*/80); std::vector<const InterfaceFile *> Files; Files.emplace_back(&File); + for (auto Document : File.documents()) + Files.emplace_back(Document.get()); + // Stream out yaml. YAMLOut << Files; return Error::success(); } - -} // end namespace MachO. -} // end namespace llvm. diff --git a/llvm/lib/TextAPI/MachO/TextStubCommon.cpp b/llvm/lib/TextAPI/MachO/TextStubCommon.cpp index 183c5d5a93b0..4a82df6beac1 100644 --- a/llvm/lib/TextAPI/MachO/TextStubCommon.cpp +++ b/llvm/lib/TextAPI/MachO/TextStubCommon.cpp @@ -12,6 +12,7 @@ #include "TextStubCommon.h" #include "TextAPIContext.h" +#include "llvm/ADT/StringSwitch.h" using namespace llvm::MachO; @@ -62,18 +63,27 @@ void ScalarTraits<PlatformSet>::output(const PlatformSet &Values, void *IO, case PlatformKind::macOS: OS << "macosx"; break; + case PlatformKind::iOSSimulator: + LLVM_FALLTHROUGH; case PlatformKind::iOS: OS << "ios"; break; + case PlatformKind::watchOSSimulator: + LLVM_FALLTHROUGH; case PlatformKind::watchOS: OS << "watchos"; break; + case PlatformKind::tvOSSimulator: + LLVM_FALLTHROUGH; case PlatformKind::tvOS: OS << "tvos"; break; case PlatformKind::bridgeOS: OS << "bridgeos"; break; + case PlatformKind::macCatalyst: + OS << "iosmac"; + break; } } @@ -119,7 +129,7 @@ QuotingType ScalarTraits<PlatformSet>::mustQuote(StringRef) { void ScalarBitSetTraits<ArchitectureSet>::bitset(IO &IO, ArchitectureSet &Archs) { -#define ARCHINFO(arch, type, subtype) \ +#define ARCHINFO(arch, type, subtype, numbits) \ IO.bitSetCase(Archs, #arch, 1U << static_cast<int>(AK_##arch)); #include "llvm/TextAPI/MachO/Architecture.def" #undef ARCHINFO @@ -212,7 +222,7 @@ StringRef ScalarTraits<UUID>::input(StringRef Scalar, void *, UUID &Value) { auto UUID = Split.second.trim(); if (UUID.empty()) return "invalid uuid string pair"; - Value.second = UUID; + Value.second = std::string(UUID); Value.first = Target{getArchitectureFromName(Arch), PlatformKind::unknown}; return {}; } diff --git a/llvm/lib/TextAPI/MachO/TextStubCommon.h b/llvm/lib/TextAPI/MachO/TextStubCommon.h index a558cbcec9fb..f2cda50e297d 100644 --- a/llvm/lib/TextAPI/MachO/TextStubCommon.h +++ b/llvm/lib/TextAPI/MachO/TextStubCommon.h @@ -14,7 +14,6 @@ #define LLVM_TEXTAPI_TEXT_STUB_COMMON_H #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/StringSwitch.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/TextAPI/MachO/Architecture.h" #include "llvm/TextAPI/MachO/ArchitectureSet.h" |