llvm.org GIT mirror llvm / 134d93d
[MachO] Add valid architecture function Added array of valid architectures and function returning array. Modified llvm-lipo to include list of valid architectures in error message for invalid arch. Patch by Anusha Basana <anusha.basana@gmail.com> Differential Revision: https://reviews.llvm.org/D63735 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365099 91177308-0d34-0410-b5e6-96231b3b80d8 Shoaib Meenai a month ago
4 changed file(s) with 23 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
570570 const char **McpuDefault = nullptr,
571571 const char **ArchFlag = nullptr);
572572 static bool isValidArch(StringRef ArchFlag);
573 static ArrayRef getValidArchs();
573574 static Triple getHostArch();
574575
575576 bool isRelocatableObject() const override;
5555 };
5656
5757 } // end anonymous namespace
58
59 static const std::array validArchs = {
60 "i386", "x86_64", "x86_64h", "armv4t", "arm", "armv5e",
61 "armv6", "armv6m", "armv7", "armv7em", "armv7k", "armv7m",
62 "armv7s", "arm64", "arm64_32", "ppc", "ppc64",
63 };
5864
5965 static Error malformedError(const Twine &Msg) {
6066 return make_error("truncated or malformed object (" +
27172723 }
27182724
27192725 bool MachOObjectFile::isValidArch(StringRef ArchFlag) {
2720 return StringSwitch(ArchFlag)
2721 .Case("i386", true)
2722 .Case("x86_64", true)
2723 .Case("x86_64h", true)
2724 .Case("armv4t", true)
2725 .Case("arm", true)
2726 .Case("armv5e", true)
2727 .Case("armv6", true)
2728 .Case("armv6m", true)
2729 .Case("armv7", true)
2730 .Case("armv7em", true)
2731 .Case("armv7k", true)
2732 .Case("armv7m", true)
2733 .Case("armv7s", true)
2734 .Case("arm64", true)
2735 .Case("arm64_32", true)
2736 .Case("ppc", true)
2737 .Case("ppc64", true)
2738 .Default(false);
2739 }
2726 return std::find(validArchs.cbegin(), validArchs.cend(), ArchFlag) !=
2727 validArchs.cend();
2728 }
2729
2730 ArrayRef MachOObjectFile::getValidArchs() { return validArchs; }
27402731
27412732 Triple::ArchType MachOObjectFile::getArch() const {
27422733 return getArch(getCPUType(*this));
0 # RUN: yaml2obj %s > %t
11
2 # RUN: not llvm-lipo %t -thin arc -output %t.out 2>&1 | FileCheck --check-prefix=ARCH_NOT_IN_FILE %s
3 # ARCH_NOT_IN_FILE: does not contain the specified architecture arc to thin it to
2 # RUN: not llvm-lipo %t -thin arm64_32 -output %t.out 2>&1 | FileCheck --check-prefix=ARCH_NOT_IN_FILE %s
3 # ARCH_NOT_IN_FILE: does not contain the specified architecture arm64_32 to thin it to
44
55 # RUN: not llvm-lipo %t -thin aarch101 -output %t.out 2>&1 | FileCheck --check-prefix=INVALID_ARCH %s
66 # INVALID_ARCH: Invalid architecture: aarch101
9292 } // end namespace
9393
9494 static void validateArchitectureName(StringRef ArchitectureName) {
95 if (Triple(ArchitectureName).getArch() == Triple::ArchType::UnknownArch)
96 reportError("Invalid architecture: " + ArchitectureName);
95 if (!MachOObjectFile::isValidArch(ArchitectureName)) {
96 std::string Buf;
97 raw_string_ostream OS(Buf);
98 OS << "Invalid architecture: " << ArchitectureName
99 << "\nValid architecture names are:";
100 for (auto arch : MachOObjectFile::getValidArchs())
101 OS << " " << arch;
102 reportError(OS.str());
103 }
97104 }
98105
99106 static Config parseLipoOptions(ArrayRef ArgsArr) {