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 <christian.kandeler@qt.io>
This commit is contained in:
Denis Shienkov
2019-07-24 23:36:56 +03:00
parent 936e53ceff
commit 031448d596

View File

@@ -72,6 +72,8 @@ static QString compilerTargetFlag(const Abi &abi)
switch (abi.architecture()) { switch (abi.architecture()) {
case Abi::Architecture::Mcs51Architecture: case Abi::Architecture::Mcs51Architecture:
return QString("-mmcs51"); return QString("-mmcs51");
case Abi::Architecture::Stm8Architecture:
return QString("-mstm8");
default: default:
return {}; return {};
} }
@@ -169,6 +171,8 @@ static Abi::Architecture guessArchitecture(const Macros &macros)
for (const Macro &macro : macros) { for (const Macro &macro : macros) {
if (macro.key == "__SDCC_mcs51") if (macro.key == "__SDCC_mcs51")
return Abi::Architecture::Mcs51Architecture; return Abi::Architecture::Mcs51Architecture;
if (macro.key == "__SDCC_stm8")
return Abi::Architecture::Stm8Architecture;
} }
return Abi::Architecture::UnknownArchitecture; return Abi::Architecture::UnknownArchitecture;
} }
@@ -443,21 +447,41 @@ QList<ToolChain *> SdccToolChainFactory::autoDetectToolchain(
const Candidate &candidate, Core::Id language) const const Candidate &candidate, Core::Id language) const
{ {
const auto env = Environment::systemEnvironment(); const auto env = Environment::systemEnvironment();
const Macros macros = dumpPredefinedMacros(candidate.compilerPath, env.toStringList(), {});
// Table of supported ABI's by SDCC compiler.
const Abi knownAbis[] = {
{Abi::Mcs51Architecture},
{Abi::Stm8Architecture}
};
QList<ToolChain *> 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()) if (macros.isEmpty())
return {}; continue;
const Abi abi = guessAbi(macros); const Abi abi = guessAbi(macros);
if (knownAbi.architecture() != abi.architecture())
continue;
const auto tc = new SdccToolChain; const auto tc = new SdccToolChain;
tc->setDetection(ToolChain::AutoDetection); tc->setDetection(ToolChain::AutoDetection);
tc->setLanguage(language); tc->setLanguage(language);
tc->setCompilerCommand(candidate.compilerPath); tc->setCompilerCommand(candidate.compilerPath);
tc->setTargetAbi(abi); tc->setTargetAbi(abi);
tc->setDisplayName(buildDisplayName(abi.architecture(), language, candidate.compilerVersion)); tc->setDisplayName(buildDisplayName(abi.architecture(), language,
candidate.compilerVersion));
const auto languageVersion = ToolChain::languageVersion(language, macros); const auto languageVersion = ToolChain::languageVersion(language, macros);
tc->predefinedMacrosCache()->insert({}, {macros, languageVersion}); tc->predefinedMacrosCache()->insert({}, {macros, languageVersion});
return {tc};
tcs.push_back(tc);
}
return tcs;
} }
// SdccToolChainConfigWidget // SdccToolChainConfigWidget