diff options
author | Renato Golin <renato.golin@linaro.org> | 2014-11-17 14:08:57 +0000 |
---|---|---|
committer | Renato Golin <renato.golin@linaro.org> | 2014-11-17 14:08:57 +0000 |
commit | 609bf9236579a525f9446621f16e3d9bb6b2b4f6 (patch) | |
tree | 1e5111939e911a8bd6bde35962fc5407dedfc2eb /llvm/lib/Support/Triple.cpp | |
parent | 6a3fd8361fcf385d1b85813cd2fc423417182030 (diff) | |
download | bcm5719-llvm-609bf9236579a525f9446621f16e3d9bb6b2b4f6.tar.gz bcm5719-llvm-609bf9236579a525f9446621f16e3d9bb6b2b4f6.zip |
Fix ARM triple parsing
The triple parser should only accept existing architecture names
when the triple starts with armv, armebv, thumbv or thumbebv.
Patch by Gabor Ballabas.
llvm-svn: 222129
Diffstat (limited to 'llvm/lib/Support/Triple.cpp')
-rw-r--r-- | llvm/lib/Support/Triple.cpp | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp index 7a9dc39369f..4a4773e2f7e 100644 --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/lib/Support/Triple.cpp @@ -222,6 +222,50 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) { .Default(UnknownArch); } +static Triple::ArchType parseARMArch(StringRef ArchName) { + size_t offset = StringRef::npos; + Triple::ArchType arch = Triple::UnknownArch; + bool isThumb = ArchName.startswith("thumb"); + + if (ArchName.equals("arm")) + return Triple::arm; + if (ArchName.equals("armeb")) + return Triple::armeb; + if (ArchName.equals("thumb")) + return Triple::thumb; + if (ArchName.equals("thumbeb")) + return Triple::thumbeb; + if (ArchName.equals("arm64") || ArchName.equals("aarch64")) + return Triple::aarch64; + if (ArchName.equals("aarch64_be")) + return Triple::aarch64_be; + + if (ArchName.startswith("armv")) { + offset = 3; + arch = Triple::arm; + } else if (ArchName.startswith("armebv")) { + offset = 5; + arch = Triple::armeb; + } else if (ArchName.startswith("thumbv")) { + offset = 5; + arch = Triple::thumb; + } else if (ArchName.startswith("thumbebv")) { + offset = 7; + arch = Triple::thumbeb; + } + return StringSwitch<Triple::ArchType>(ArchName.substr(offset)) + .Cases("v2", "v2a", isThumb ? Triple::UnknownArch : arch) + .Cases("v3", "v3m", isThumb ? Triple::UnknownArch : arch) + .Cases("v4", "v4t", arch) + .Cases("v5", "v5e", "v5t", "v5te", "v5tej", arch) + .Cases("v6", "v6j", "v6k", "v6m", arch) + .Cases("v6t2", "v6z", "v6zk", arch) + .Cases("v7", "v7a", "v7em", "v7l", arch) + .Cases("v7m", "v7r", "v7s", arch) + .Cases("v8", "v8a", arch) + .Default(Triple::UnknownArch); +} + static Triple::ArchType parseArch(StringRef ArchName) { return StringSwitch<Triple::ArchType>(ArchName) .Cases("i386", "i486", "i586", "i686", Triple::x86) @@ -231,19 +275,10 @@ static Triple::ArchType parseArch(StringRef ArchName) { .Case("powerpc", Triple::ppc) .Cases("powerpc64", "ppu", Triple::ppc64) .Case("powerpc64le", Triple::ppc64le) - .Case("aarch64", Triple::aarch64) - .Case("aarch64_be", Triple::aarch64_be) - .Case("arm64", Triple::aarch64) - .Cases("arm", "xscale", Triple::arm) - // FIXME: It would be good to replace these with explicit names for all the - // various suffixes supported. - .StartsWith("armv", Triple::arm) - .Case("armeb", Triple::armeb) - .StartsWith("armebv", Triple::armeb) - .Case("thumb", Triple::thumb) - .StartsWith("thumbv", Triple::thumb) - .Case("thumbeb", Triple::thumbeb) - .StartsWith("thumbebv", Triple::thumbeb) + .Case("xscale", Triple::arm) + .StartsWith("arm", parseARMArch(ArchName)) + .StartsWith("thumb", parseARMArch(ArchName)) + .StartsWith("aarch64", parseARMArch(ArchName)) .Case("msp430", Triple::msp430) .Cases("mips", "mipseb", "mipsallegrex", Triple::mips) .Cases("mipsel", "mipsallegrexel", Triple::mipsel) |