From d00af6b0dcc1a567c29ebb46bc30368886663555 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Mon, 1 Feb 2021 21:38:46 +0300 Subject: baremetal: Add support for HCS08 architectures to SDCC toolchain This patch adds the HCS08 architectures, provided by Freescale Semiconductor: * https://en.wikipedia.org/wiki/Motorola_S08 Change-Id: I0a08c6433041eb8a00cb3705c5e65857188f4830 Reviewed-by: Ivan Komissarov --- share/qbs/modules/cpp/sdcc.js | 8 ++++++++ src/app/qbs-setup-toolchains/sdccprobe.cpp | 29 +++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/share/qbs/modules/cpp/sdcc.js b/share/qbs/modules/cpp/sdcc.js index 1fa5f0472..fb37b801f 100644 --- a/share/qbs/modules/cpp/sdcc.js +++ b/share/qbs/modules/cpp/sdcc.js @@ -50,6 +50,8 @@ function assemblerName(qbs) { return "sdas8051"; case "stm8": return "sdasstm8"; + case "hcs8": + return "sdas6808"; } throw "Unable to deduce assembler name for unsupported architecture: '" + qbs.architecture + "'"; @@ -61,6 +63,8 @@ function linkerName(qbs) { return "sdld"; case "stm8": return "sdldstm8"; + case "hcs8": + return "sdld6808"; } throw "Unable to deduce linker name for unsupported architecture: '" + qbs.architecture + "'"; @@ -75,6 +79,8 @@ function targetArchitectureFlag(architecture) { return "-mmcs51"; if (architecture === "stm8") return "-mstm8"; + if (architecture === "hcs8") + return "-mhc08"; } function guessArchitecture(macros) { @@ -82,6 +88,8 @@ function guessArchitecture(macros) { return "mcs51"; if (macros["__SDCC_stm8"] === "1") return "stm8"; + if (macros["__SDCC_hc08"] === "1") + return "hcs8"; } function guessEndianness(macros) { diff --git a/src/app/qbs-setup-toolchains/sdccprobe.cpp b/src/app/qbs-setup-toolchains/sdccprobe.cpp index 9c68d0c0f..a8a27fb96 100644 --- a/src/app/qbs-setup-toolchains/sdccprobe.cpp +++ b/src/app/qbs-setup-toolchains/sdccprobe.cpp @@ -89,13 +89,12 @@ static QByteArray dumpSdccMacros(const QFileInfo &compiler, return p.readAllStandardOutput(); } -static QString dumpSdccArchitecture(const QFileInfo &compiler, - const QString &arch) +static bool supportsSdccArchitecture(const QFileInfo &compiler, QStringView flag) { - const auto targetFlag = QStringLiteral("-m%1").arg(arch); - const auto token = QStringLiteral("__SDCC_%1").arg(arch); + const auto targetFlag = QStringLiteral("-m%1").arg(flag); const auto macros = dumpSdccMacros(compiler, targetFlag); - return macros.contains(token.toLatin1()) ? arch : QString(); + const auto token = QStringLiteral("__SDCC_%1").arg(flag); + return macros.contains(token.toLatin1()); } static std::vector createSdccProfileHelper( @@ -107,13 +106,15 @@ static std::vector createSdccProfileHelper( std::vector profiles; - const char *knownArchs[] = {"mcs51", "stm8"}; + static constexpr struct KnownArch { + QStringView architecture; + QStringView flag; + } knownArchs[] = {{u"mcs51", u"mcs51"}, {u"stm8", u"stm8"}, {u"hcs8", u"hc08"}}; + for (const auto &knownArch : knownArchs) { - const auto actualArch = dumpSdccArchitecture( - compiler, QString::fromLatin1(knownArch)); // Don't create a profile in case the compiler does // not support the proposed architecture. - if (actualArch != QString::fromLatin1(knownArch)) + if (!supportsSdccArchitecture(compiler, knownArch.flag)) continue; QString fullProfileName; @@ -122,18 +123,18 @@ static std::vector createSdccProfileHelper( // in auto-detecting mode. if (!info.compilerVersion.isValid()) { fullProfileName = QStringLiteral("sdcc-unknown-%1") - .arg(actualArch); + .arg(knownArch.architecture); } else { const QString version = info.compilerVersion.toString( QLatin1Char('_'), QLatin1Char('_')); fullProfileName = QStringLiteral("sdcc-%1-%2").arg( - version, actualArch); + version, knownArch.architecture); } } else { // Append the detected actual architecture name // to the proposed profile name. fullProfileName = QStringLiteral("%1-%2").arg( - profileName, actualArch); + profileName, knownArch.architecture); } Profile profile(fullProfileName, settings); @@ -141,8 +142,8 @@ static std::vector createSdccProfileHelper( compiler.absolutePath()); profile.setValue(QStringLiteral("qbs.toolchainType"), QStringLiteral("sdcc")); - if (!actualArch.isEmpty()) - profile.setValue(QStringLiteral("qbs.architecture"), actualArch); + profile.setValue(QStringLiteral("qbs.architecture"), + knownArch.architecture.toString()); qbsInfo() << Tr::tr("Profile '%1' created for '%2'.").arg( profile.name(), compiler.absoluteFilePath()); -- cgit v1.2.3