From 031448d596a582603112d4928dbf71ea6230b22f Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Wed, 24 Jul 2019 23:36:56 +0300 Subject: [PATCH] BareMetal: Add STM8 architecture for SDCC toolchain Previous implementation of SDCC toolchain based on an assumption, that the default target architecture always is MCS51. But, the SDCC compiler support multiple architectures: * http://sdcc.sourceforge.net/ Since we have the new STM8 architecture in the Abi::Architecture enumeration, it is makes sense to add support for this architecture and to the SDCC compiler. Right now, the SDCC compiler will be auto-detected as two instances: * with mcs51 architecture * with stm8 architecture by analogy as it does for the MSVC compiler for multiple x86, x86_64 and so forth architectures. In case the SDCC compiler is manually added, the user can choose a desired architecture (mcs51 or stm8) from the combo-box. Change-Id: I9b7d34f9064ea34c94dab7f1a7e3b64b190f7cb0 Reviewed-by: Christian Kandeler --- src/plugins/baremetal/sdcctoolchain.cpp | 50 ++++++++++++++++++------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/plugins/baremetal/sdcctoolchain.cpp b/src/plugins/baremetal/sdcctoolchain.cpp index adc8716c1d6..199d8ef0aa6 100644 --- a/src/plugins/baremetal/sdcctoolchain.cpp +++ b/src/plugins/baremetal/sdcctoolchain.cpp @@ -72,6 +72,8 @@ static QString compilerTargetFlag(const Abi &abi) switch (abi.architecture()) { case Abi::Architecture::Mcs51Architecture: return QString("-mmcs51"); + case Abi::Architecture::Stm8Architecture: + return QString("-mstm8"); default: return {}; } @@ -169,6 +171,8 @@ static Abi::Architecture guessArchitecture(const Macros ¯os) for (const Macro ¯o : macros) { if (macro.key == "__SDCC_mcs51") return Abi::Architecture::Mcs51Architecture; + if (macro.key == "__SDCC_stm8") + return Abi::Architecture::Stm8Architecture; } return Abi::Architecture::UnknownArchitecture; } @@ -443,21 +447,41 @@ QList SdccToolChainFactory::autoDetectToolchain( const Candidate &candidate, Core::Id language) const { const auto env = Environment::systemEnvironment(); - const Macros macros = dumpPredefinedMacros(candidate.compilerPath, env.toStringList(), {}); - if (macros.isEmpty()) - return {}; - const Abi abi = guessAbi(macros); - const auto tc = new SdccToolChain; - tc->setDetection(ToolChain::AutoDetection); - tc->setLanguage(language); - tc->setCompilerCommand(candidate.compilerPath); - tc->setTargetAbi(abi); - tc->setDisplayName(buildDisplayName(abi.architecture(), language, candidate.compilerVersion)); + // Table of supported ABI's by SDCC compiler. + const Abi knownAbis[] = { + {Abi::Mcs51Architecture}, + {Abi::Stm8Architecture} + }; - const auto languageVersion = ToolChain::languageVersion(language, macros); - tc->predefinedMacrosCache()->insert({}, {macros, languageVersion}); - return {tc}; + QList tcs; + + // Probe each ABI from the table, because the SDCC compiler + // can be compiled with or without the specified architecture. + for (const auto &knownAbi : knownAbis) { + const Macros macros = dumpPredefinedMacros(candidate.compilerPath, + env.toStringList(), knownAbi); + if (macros.isEmpty()) + continue; + const Abi abi = guessAbi(macros); + if (knownAbi.architecture() != abi.architecture()) + continue; + + const auto tc = new SdccToolChain; + tc->setDetection(ToolChain::AutoDetection); + tc->setLanguage(language); + tc->setCompilerCommand(candidate.compilerPath); + tc->setTargetAbi(abi); + tc->setDisplayName(buildDisplayName(abi.architecture(), language, + candidate.compilerVersion)); + + const auto languageVersion = ToolChain::languageVersion(language, macros); + tc->predefinedMacrosCache()->insert({}, {macros, languageVersion}); + + tcs.push_back(tc); + } + + return tcs; } // SdccToolChainConfigWidget