From 7353a90b117252a4765c40017666b4c6502e786c Mon Sep 17 00:00:00 2001 From: Juergen Ributzka Date: Thu, 29 Nov 2018 01:20:46 +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 llvm-svn: 347823 --- llvm/lib/TextAPI/MachO/Architecture.cpp | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 llvm/lib/TextAPI/MachO/Architecture.cpp (limited to 'llvm/lib/TextAPI/MachO/Architecture.cpp') diff --git a/llvm/lib/TextAPI/MachO/Architecture.cpp b/llvm/lib/TextAPI/MachO/Architecture.cpp new file mode 100644 index 00000000000..2e6884615fe --- /dev/null +++ b/llvm/lib/TextAPI/MachO/Architecture.cpp @@ -0,0 +1,79 @@ +//===- llvm/TextAPI/Architecture.cpp - Architecture -------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Implements the architecture helper functions. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/TextAPI/MachO/Architecture.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/BinaryFormat/MachO.h" + +namespace llvm { +namespace MachO { + +Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType) { +#define ARCHINFO(Arch, Type, Subtype) \ + if (CPUType == (Type) && \ + (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \ + return Architecture::Arch; +#include "llvm/TextAPI/MachO/Architecture.def" +#undef ARCHINFO + + return Architecture::unknown; +} + +Architecture getArchitectureFromName(StringRef Name) { + return StringSwitch(Name) +#define ARCHINFO(Arch, Type, Subtype) .Case(#Arch, Architecture::Arch) +#include "llvm/TextAPI/MachO/Architecture.def" +#undef ARCHINFO + .Default(Architecture::unknown); +} + +StringRef getArchitectureName(Architecture Arch) { + switch (Arch) { +#define ARCHINFO(Arch, Type, Subtype) \ + case Architecture::Arch: \ + return #Arch; +#include "llvm/TextAPI/MachO/Architecture.def" +#undef ARCHINFO + case Architecture::unknown: + return "unknown"; + } + + // Appease some compilers that cannot figure out that this is a fully covered + // switch statement. + return "unknown"; +} + +std::pair getCPUTypeFromArchitecture(Architecture Arch) { + switch (Arch) { +#define ARCHINFO(Arch, Type, Subtype) \ + case Architecture::Arch: \ + return std::make_pair(Type, Subtype); +#include "llvm/TextAPI/MachO/Architecture.def" +#undef ARCHINFO + case Architecture::unknown: + return std::make_pair(0, 0); + } + + // Appease some compilers that cannot figure out that this is a fully covered + // switch statement. + return std::make_pair(0, 0); +} + +raw_ostream &operator<<(raw_ostream &OS, Architecture Arch) { + OS << getArchitectureName(Arch); + return OS; +} + +} // end namespace MachO. +} // end namespace llvm. -- cgit v1.2.3