[lld] r186755 - [mach-o] factor out all cputype <-> arch conversions to one table driven location
Nick Kledzik
kledzik at apple.com
Fri Jul 19 19:08:23 PDT 2013
Author: kledzik
Date: Fri Jul 19 21:08:23 2013
New Revision: 186755
URL: http://llvm.org/viewvc/llvm-project?rev=186755&view=rev
Log:
[mach-o] factor out all cputype <-> arch conversions to one table driven location
Modified:
lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h
lld/trunk/lib/Driver/DarwinLdDriver.cpp
lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp
Modified: lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h?rev=186755&r1=186754&r2=186755&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOTargetInfo.h Fri Jul 19 21:08:23 2013
@@ -74,7 +74,12 @@ public:
bool minOS(StringRef mac, StringRef iOS) const;
void setDoNothing(bool value) { _doNothing = value; }
bool doNothing() const { return _doNothing; }
-
+
+ static Arch archFromCpuType(uint32_t cputype, uint32_t cpusubtype);
+ static Arch archFromName(StringRef archName);
+ static uint32_t cpuTypeFromArch(Arch arch);
+ static uint32_t cpuSubtypeFromArch(Arch arch);
+
private:
virtual Writer &writer() const;
@@ -91,7 +96,6 @@ private:
uint32_t _value;
};
-
uint32_t _outputFileType; // e.g MH_EXECUTE
bool _outputFileTypeStatic; // Disambiguate static vs dynamic prog
bool _doNothing; // for -help and -v which just print info
Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=186755&r1=186754&r2=186755&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Fri Jul 19 21:08:23 2013
@@ -148,13 +148,13 @@ bool DarwinLdDriver::parse(int argc, con
// Handle -arch xxx
if (llvm::opt::Arg *archStr = parsedArgs->getLastArg(OPT_arch)) {
- info.setArch(llvm::StringSwitch<MachOTargetInfo::Arch>(archStr->getValue())
- .Case("x86_64", MachOTargetInfo::arch_x86_64)
- .Case("i386", MachOTargetInfo::arch_x86)
- .Case("armv6", MachOTargetInfo::arch_armv6)
- .Case("armv7", MachOTargetInfo::arch_armv7)
- .Case("armv7s", MachOTargetInfo::arch_armv7s)
- .Default(MachOTargetInfo::arch_unknown));
+ info.setArch(MachOTargetInfo::archFromName(archStr->getValue()));
+ if (info.arch() == MachOTargetInfo::arch_unknown) {
+ diagnostics << "error: unknown arch named '"
+ << archStr->getValue()
+ << "'\n";
+ return true;
+ }
}
// Handle -macosx_version_min or -ios_version_min
Modified: lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp?rev=186755&r1=186754&r2=186755&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOTargetInfo.cpp Fri Jul 19 21:08:23 2013
@@ -85,6 +85,67 @@ bool MachOTargetInfo::PackedVersion::ope
return _value == rhs._value;
}
+struct ArchInfo {
+ StringRef archName;
+ MachOTargetInfo::Arch arch;
+ uint32_t cputype;
+ uint32_t cpusubtype;
+};
+
+static ArchInfo archInfos[] = {
+ { "x86_64", MachOTargetInfo::arch_x86_64, mach_o::CPU_TYPE_X86_64,
+ mach_o::CPU_SUBTYPE_X86_64_ALL },
+ { "i386", MachOTargetInfo::arch_x86, mach_o::CPU_TYPE_I386,
+ mach_o::CPU_SUBTYPE_X86_ALL },
+ { "armv6", MachOTargetInfo::arch_armv6, mach_o::CPU_TYPE_ARM,
+ mach_o::CPU_SUBTYPE_ARM_V6 },
+ { "armv7", MachOTargetInfo::arch_armv7, mach_o::CPU_TYPE_ARM,
+ mach_o::CPU_SUBTYPE_ARM_V7 },
+ { "armv7s", MachOTargetInfo::arch_armv7s, mach_o::CPU_TYPE_ARM,
+ mach_o::CPU_SUBTYPE_ARM_V7S },
+ { StringRef(), MachOTargetInfo::arch_unknown, 0, 0 }
+
+};
+
+MachOTargetInfo::Arch
+MachOTargetInfo::archFromCpuType(uint32_t cputype, uint32_t cpusubtype) {
+ for (ArchInfo *info = archInfos; !info->archName.empty(); ++info) {
+ if ( (info->cputype == cputype) && (info->cpusubtype == cpusubtype)) {
+ return info->arch;
+ }
+ }
+ return arch_unknown;
+}
+
+MachOTargetInfo::Arch MachOTargetInfo::archFromName(StringRef archName) {
+ for (ArchInfo *info = archInfos; !info->archName.empty(); ++info) {
+ if (info->archName.equals(archName)) {
+ return info->arch;
+ }
+ }
+ return arch_unknown;
+}
+
+uint32_t MachOTargetInfo::cpuTypeFromArch(Arch arch) {
+ assert(arch != arch_unknown);
+ for (ArchInfo *info = archInfos; !info->archName.empty(); ++info) {
+ if (info->arch == arch) {
+ return info->cputype;
+ }
+ }
+ llvm_unreachable("Unknown arch type");
+}
+
+uint32_t MachOTargetInfo::cpuSubtypeFromArch(Arch arch) {
+ assert(arch != arch_unknown);
+ for (ArchInfo *info = archInfos; !info->archName.empty(); ++info) {
+ if (info->arch == arch) {
+ return info->cpusubtype;
+ }
+ }
+ llvm_unreachable("Unknown arch type");
+}
+
MachOTargetInfo::MachOTargetInfo()
: _outputFileType(mach_o::MH_EXECUTE)
@@ -102,37 +163,11 @@ MachOTargetInfo::~MachOTargetInfo() {
}
uint32_t MachOTargetInfo::getCPUType() const {
- switch (_arch) {
- case MachOTargetInfo::arch_x86:
- return mach_o::CPU_TYPE_I386;
- case MachOTargetInfo::arch_x86_64:
- return mach_o::CPU_TYPE_X86_64;
- case MachOTargetInfo::arch_armv6:
- case MachOTargetInfo::arch_armv7:
- case MachOTargetInfo::arch_armv7s:
- return mach_o::CPU_TYPE_ARM;
- case MachOTargetInfo::arch_unknown:
- break;
- }
- llvm_unreachable("Unknown arch type");
+ return cpuTypeFromArch(_arch);
}
uint32_t MachOTargetInfo::getCPUSubType() const {
- switch (_arch) {
- case MachOTargetInfo::arch_x86:
- return mach_o::CPU_SUBTYPE_X86_ALL;
- case MachOTargetInfo::arch_x86_64:
- return mach_o::CPU_SUBTYPE_X86_64_ALL;
- case MachOTargetInfo::arch_armv6:
- return mach_o::CPU_SUBTYPE_ARM_V6;
- case MachOTargetInfo::arch_armv7:
- return mach_o::CPU_SUBTYPE_ARM_V7;
- case MachOTargetInfo::arch_armv7s:
- return mach_o::CPU_SUBTYPE_ARM_V7S;
- case MachOTargetInfo::arch_unknown:
- break;
- }
- llvm_unreachable("Unknown arch type");
+ return cpuSubtypeFromArch(_arch);
}
More information about the llvm-commits
mailing list