From 1983efdd2f1457ebdc84450f0d18980513b879b0 Mon Sep 17 00:00:00 2001 From: Cyano Hao Date: Sat, 10 Dec 2022 12:00:57 +0800 Subject: [PATCH 1/2] handle non-x86 64-bit targets --- RedPandaIDE/settings.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index ebbe7da2..768a2c7a 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -2072,12 +2072,10 @@ void Settings::CompilerSet::setProperties(const QString &binDir, const QString& int delimPos2 = delimPos1; while (delimPos2name(); QString platformName; - if (baseSet->target() == "x86_64") { + if (baseSet->target().contains("64") || baseSet->target() == "s390x") { if (baseName.startsWith("TDM-GCC ")) { PCompilerSet set= addSet(baseSet); platformName = "32-bit"; From 23af39395ec0e64fdc88d5121f68d3a9c5a87a96 Mon Sep 17 00:00:00 2001 From: Cyano Hao Date: Sun, 11 Dec 2022 18:22:44 +0800 Subject: [PATCH 2/2] check 64-bit by comparing with a specific list --- RedPandaIDE/settings.cpp | 48 +++++++++++++++++++++++++++++++++++++++- RedPandaIDE/settings.h | 1 + 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 768a2c7a..620c1ff0 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef Q_OS_LINUX #include #endif @@ -2658,7 +2659,7 @@ bool Settings::CompilerSets::addSets(const QString &folder, const QString& cc_pr return false; QString baseName = baseSet->name(); QString platformName; - if (baseSet->target().contains("64") || baseSet->target() == "s390x") { + if (isTarget64Bit(baseSet->target())) { if (baseName.startsWith("TDM-GCC ")) { PCompilerSet set= addSet(baseSet); platformName = "32-bit"; @@ -3144,6 +3145,51 @@ QString Settings::CompilerSets::getKeyFromCompilerCompatibleIndex(int idx) const return mCompilerCompatibleIndex[idx]; } +bool Settings::CompilerSets::isTarget64Bit(const QString &target) +{ + static const auto generateSortedTargets = []() -> decltype(auto) { + /* Fetched from LLVM 15.0.6's arch parser, + * `Triple::ArchType parseArch(StringRef ArchName)` + * in `llvm/lib/Support/Triple.cpp`. + * The following non-CPU targets are not included: + * nvptx64, le64, amdil64, hsail64, spir64, spirv64, renderscript64. + */ + static QString targets[] = { + // x86_64 + "amd64", "x86_64", "x86_64h", + // ppc64 + "powerpc64", "ppu", "ppc64", + // ppc64le + "powerpc64le", "ppc64le", + // aarch64 + "aarch64", "arm64", "arm64e", + // aarch64_be + "aarch64_be", + // aarch64_32 + "aarch64_32", "arm64_32", + // mips64 + "mips64", "mips64eb", "mipsn32", "mipsisa64r6", "mips64r6", "mipsn32r6", + // mips64el + "mips64el", "mipsn32el", "mipsisa64r6el", "mips64r6el", "mipsn32r6el", + // riscv64 + "riscv64", + // systemz + "s390x", "systemz", + // sparcv9 + "sparcv9", "sparc64", + // wasm64 + "wasm64", + // loongarch64 + "loongarch64", + }; + std::sort(std::begin(targets), std::end(targets)); + return (targets); // parentheses required for type deduction + }; + static const auto &common64BitTargets = generateSortedTargets(); + bool is64Bit = std::binary_search(std::begin(common64BitTargets), std::end(common64BitTargets), target); + return is64Bit; +} + Settings::Environment::Environment(Settings *settings):_Base(settings, SETTING_ENVIRONMENT) { diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index e461aa1f..c42bde7c 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -1430,6 +1430,7 @@ public: void loadPathList(const QString& name, QStringList& list); PCompilerSet loadSet(int index); void prepareCompatibleIndex(); + static bool isTarget64Bit(const QString &target); private: CompilerSetList mList; int mDefaultIndex;