From 32cb594177df24e0a17e049848425dd2c54ba98b Mon Sep 17 00:00:00 2001 From: Juergen Ributzka Date: Fri, 22 Mar 2019 22:46:52 +0000 Subject: [TextAPI] TBD Reader/Writer Add basic infrastructure for reading and writting TBD files (version 1 - 3). The TextAPI library is not used by anything yet (besides the unit tests). Tool support will be added in a separate commit. The TBD format is currently documented in the implementation file (TextStub.cpp). https://reviews.llvm.org/D53945 Update: This contains changes to fix issues discovered by the bots: - add parentheses to silence warnings. - rename variables - use PlatformType from BinaryFormat - Trying if switching from a vector to an array will appeas the bots. - Replace the tuple with a struct to work around an explicit constructor bug. - This fixes an issue where we were leaking the YAML document if there was a parsing error. Updated the license information in all files. llvm-svn: 356820 --- llvm/lib/TextAPI/MachO/TextStubCommon.cpp | 178 ++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 llvm/lib/TextAPI/MachO/TextStubCommon.cpp (limited to 'llvm/lib/TextAPI/MachO/TextStubCommon.cpp') diff --git a/llvm/lib/TextAPI/MachO/TextStubCommon.cpp b/llvm/lib/TextAPI/MachO/TextStubCommon.cpp new file mode 100644 index 00000000000..805a9000512 --- /dev/null +++ b/llvm/lib/TextAPI/MachO/TextStubCommon.cpp @@ -0,0 +1,178 @@ +//===- TextStubCommon.cpp -------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// Implememts common Text Stub YAML mappings. +// +//===----------------------------------------------------------------------===// + +#include "TextStubCommon.h" +#include "TextAPIContext.h" + +using namespace llvm::MachO; + +namespace llvm { +namespace yaml { + +void ScalarTraits::output(const FlowStringRef &Value, void *Ctx, + raw_ostream &OS) { + ScalarTraits::output(Value, Ctx, OS); +} +StringRef ScalarTraits::input(StringRef Value, void *Ctx, + FlowStringRef &Out) { + return ScalarTraits::input(Value, Ctx, Out.value); +} +QuotingType ScalarTraits::mustQuote(StringRef Name) { + return ScalarTraits::mustQuote(Name); +} + +void ScalarEnumerationTraits::enumeration( + IO &IO, ObjCConstraintType &Constraint) { + IO.enumCase(Constraint, "none", ObjCConstraintType::None); + IO.enumCase(Constraint, "retain_release", ObjCConstraintType::Retain_Release); + IO.enumCase(Constraint, "retain_release_for_simulator", + ObjCConstraintType::Retain_Release_For_Simulator); + IO.enumCase(Constraint, "retain_release_or_gc", + ObjCConstraintType::Retain_Release_Or_GC); + IO.enumCase(Constraint, "gc", ObjCConstraintType::GC); +} + +void ScalarTraits::output(const PlatformKind &Value, void *, + raw_ostream &OS) { + switch (Value) { + default: + llvm_unreachable("unexpected platform"); + break; + case PlatformKind::macOS: + OS << "macosx"; + break; + case PlatformKind::iOS: + OS << "ios"; + break; + case PlatformKind::watchOS: + OS << "watchos"; + break; + case PlatformKind::tvOS: + OS << "tvos"; + break; + case PlatformKind::bridgeOS: + OS << "bridgeos"; + break; + } +} +StringRef ScalarTraits::input(StringRef Scalar, void *, + PlatformKind &Value) { + Value = StringSwitch(Scalar) + .Case("macosx", PlatformKind::macOS) + .Case("ios", PlatformKind::iOS) + .Case("watchos", PlatformKind::watchOS) + .Case("tvos", PlatformKind::tvOS) + .Case("bridgeos", PlatformKind::bridgeOS) + .Default(PlatformKind::unknown); + + if (Value == PlatformKind::unknown) + return "unknown platform"; + return {}; +} +QuotingType ScalarTraits::mustQuote(StringRef) { + return QuotingType::None; +} + +void ScalarBitSetTraits::bitset(IO &IO, + ArchitectureSet &Archs) { +#define ARCHINFO(arch, type, subtype) \ + IO.bitSetCase(Archs, #arch, 1U << static_cast(Architecture::arch)); +#include "llvm/TextAPI/MachO/Architecture.def" +#undef ARCHINFO +} + +void ScalarTraits::output(const Architecture &Value, void *, + raw_ostream &OS) { + OS << Value; +} +StringRef ScalarTraits::input(StringRef Scalar, void *, + Architecture &Value) { + Value = getArchitectureFromName(Scalar); + return {}; +} +QuotingType ScalarTraits::mustQuote(StringRef) { + return QuotingType::None; +} + +void ScalarTraits::output(const PackedVersion &Value, void *, + raw_ostream &OS) { + OS << Value; +} +StringRef ScalarTraits::input(StringRef Scalar, void *, + PackedVersion &Value) { + if (!Value.parse32(Scalar)) + return "invalid packed version string."; + return {}; +} +QuotingType ScalarTraits::mustQuote(StringRef) { + return QuotingType::None; +} + +void ScalarTraits::output(const SwiftVersion &Value, void *, + raw_ostream &OS) { + switch (Value) { + case 1: + OS << "1.0"; + break; + case 2: + OS << "1.1"; + break; + case 3: + OS << "2.0"; + break; + case 4: + OS << "3.0"; + break; + default: + OS << (unsigned)Value; + break; + } +} +StringRef ScalarTraits::input(StringRef Scalar, void *, + SwiftVersion &Value) { + Value = StringSwitch(Scalar) + .Case("1.0", 1) + .Case("1.1", 2) + .Case("2.0", 3) + .Case("3.0", 4) + .Default(0); + if (Value != SwiftVersion(0)) + return {}; + + if (Scalar.getAsInteger(10, Value)) + return "invalid Swift ABI version."; + + return StringRef(); +} +QuotingType ScalarTraits::mustQuote(StringRef) { + return QuotingType::None; +} + +void ScalarTraits::output(const UUID &Value, void *, raw_ostream &OS) { + OS << Value.first << ": " << Value.second; +} +StringRef ScalarTraits::input(StringRef Scalar, void *, UUID &Value) { + auto Split = Scalar.split(':'); + auto Arch = Split.first.trim(); + auto UUID = Split.second.trim(); + if (UUID.empty()) + return "invalid uuid string pair"; + Value.first = getArchitectureFromName(Arch); + Value.second = UUID; + return {}; +} +QuotingType ScalarTraits::mustQuote(StringRef) { + return QuotingType::Single; +} + +} // end namespace yaml. +} // end namespace llvm. -- cgit v1.2.3