fix: options are ignored when compile

add more compiler options for sdcc
 Support text input for compiler options
This commit is contained in:
Roy Qu 2023-08-21 11:48:23 +08:00
parent 9bc5203a93
commit 6690599d60
8 changed files with 656 additions and 415 deletions

View File

@ -410,8 +410,10 @@ QString Compiler::getCCompileArguments(bool checkSyntax)
continue;
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerSet()->compilerType(), key);
if (pOption && pOption->isC && !pOption->isLinker) {
if (pOption->choices.isEmpty())
if (pOption->type == CompilerOptionType::Checkbox)
result += " " + pOption->setting;
else if (pOption->type == CompilerOptionType::Input)
result += " " + pOption->setting + " " + compileOptions[key];
else {
result += " " + pOption->setting + compileOptions[key];
}
@ -453,12 +455,15 @@ QString Compiler::getCppCompileArguments(bool checkSyntax)
continue;
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerSet()->compilerType(), key);
if (pOption && pOption->isCpp && !pOption->isLinker) {
if (pOption->choices.isEmpty())
if (pOption->type == CompilerOptionType::Checkbox)
result += " " + pOption->setting;
else
else if (pOption->type == CompilerOptionType::Input)
result += " " + pOption->setting + " " + compileOptions[key];
else {
result += " " + pOption->setting + compileOptions[key];
}
}
}
if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) {
QStringList params = textToLines(compilerSet()->customCompileParams());
foreach(const QString& param, params)
@ -560,12 +565,15 @@ QString Compiler::getLibraryArguments(FileType fileType)
continue;
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerSet()->compilerType(), key);
if (pOption && pOption->isLinker) {
if (pOption->choices.isEmpty())
if (pOption->type == CompilerOptionType::Checkbox)
result += " " + pOption->setting;
else
else if (pOption->type == CompilerOptionType::Input)
result += " " + pOption->setting + " " + compileOptions[key];
else {
result += " " + pOption->setting + compileOptions[key];
}
}
}
// Add global compiler linker extras
if (compilerSet()->useCustomLinkParams() && !compilerSet()->customLinkParams().isEmpty()) {

View File

@ -1,5 +1,6 @@
#include "compilerinfo.h"
#include <QObject>
#include <QDebug>
CompilerInfo::CompilerInfo(const QString &name):
mName(name)
@ -31,8 +32,11 @@ bool CompilerInfo::supportSyntaxCheck()
return true;
}
void CompilerInfo::addOption(const QString &key, const QString &name, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const CompileOptionChoiceList &choices)
void CompilerInfo::addOption(const QString &key, const QString &name,
const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting,
CompilerOptionType type, const CompileOptionChoiceList &choices)
{
Q_ASSERT(choices.isEmpty() || type == CompilerOptionType::Choice);
PCompilerOption pOption = std::make_shared<CompilerOption>();
pOption->key = key;
pOption->name = name;
@ -41,6 +45,7 @@ void CompilerInfo::addOption(const QString &key, const QString &name, const QStr
pOption->isCpp = isCpp;
pOption->isLinker = isLinker;
pOption->setting= setting;
pOption->type = type;
pOption->choices = choices;
mCompilerOptions.insert(key,pOption);
mCompilerOptionList.append(pOption);
@ -70,7 +75,7 @@ void CompilerInfo::prepareCompilerOptions()
sl.append(QPair<QString,QString>("Highest (-Ofast)","fast"));
sl.append(QPair<QString,QString>("Size (-Os)","s"));
sl.append(QPair<QString,QString>("Debug (-Og)","g"));
addOption(CC_CMD_OPT_OPTIMIZE, QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-O", sl);
addOption(CC_CMD_OPT_OPTIMIZE, QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-O", CompilerOptionType::Choice, sl);
// C++ Language Standards
sl.clear();
@ -86,7 +91,7 @@ void CompilerInfo::prepareCompilerOptions()
sl.append(QPair<QString,QString>("GNU C++17","gnu++17"));
sl.append(QPair<QString,QString>("GNU C++20","gnu++2a"));
sl.append(QPair<QString,QString>("GNU C++23","gnu++2b"));
addOption(CC_CMD_OPT_STD, QObject::tr("C++ Language standard (-std)"), groupName, false, true, false, "-std=", sl);
addOption(CC_CMD_OPT_STD, QObject::tr("C++ Language standard (-std)"), groupName, false, true, false, "-std=",CompilerOptionType::Choice, sl);
sl.clear();
sl.append(QPair<QString,QString>("ISO C90","c90"));
@ -97,7 +102,7 @@ void CompilerInfo::prepareCompilerOptions()
sl.append(QPair<QString,QString>("GNU C99","gnu99"));
sl.append(QPair<QString,QString>("GNU C11","gnu11"));
sl.append(QPair<QString,QString>("GNU C17","gnu17"));
addOption(C_CMD_OPT_STD, QObject::tr("C Language standard (-std)"), groupName, true, false, false, "-std=", sl);
addOption(C_CMD_OPT_STD, QObject::tr("C Language standard (-std)"), groupName, true, false, false, "-std=", CompilerOptionType::Choice, sl);
// Optimization for cpu type
// sl.clear();
@ -147,13 +152,13 @@ void CompilerInfo::prepareCompilerOptions()
sl.append(QPair<QString,QString>("FMA4","fma4"));
sl.append(QPair<QString,QString>("XOP","xop"));
sl.append(QPair<QString,QString>("AES","aes"));
addOption(CC_CMD_OPT_INSTRUCTION,QObject::tr("Enable use of specific instructions (-mx)"), groupName, true, true, false, "-m", sl);
addOption(CC_CMD_OPT_INSTRUCTION,QObject::tr("Enable use of specific instructions (-mx)"), groupName, true, true, false, "-m", CompilerOptionType::Choice, sl);
// 32bit/64bit
sl.clear();
sl.append(QPair<QString,QString>("32bit","32"));
sl.append(QPair<QString,QString>("64bit","64"));
addOption(CC_CMD_OPT_POINTER_SIZE, QObject::tr("Compile with the following pointer size (-mx)"), groupName, true, true, true, "-m", sl);
addOption(CC_CMD_OPT_POINTER_SIZE, QObject::tr("Compile with the following pointer size (-mx)"), groupName, true, true, true, "-m", CompilerOptionType::Choice, sl);
addOption(CC_CMD_OPT_DEBUG_INFO, QObject::tr("Generate debugging information (-g3)"), groupName, true, true, false, "-g3");
addOption(CC_CMD_OPT_PROFILE_INFO, QObject::tr("Generate profiling info for analysis (-pg)"), groupName, true, true, true, "-pg");
@ -171,14 +176,14 @@ void CompilerInfo::prepareCompilerOptions()
sl.append(QPair<QString,QString>("Normal"," "));
sl.append(QPair<QString,QString>("Strong","-strong"));
sl.append(QPair<QString,QString>("All","-all"));
addOption(CC_CMD_OPT_STACK_PROTECTOR , QObject::tr("Check for stack smashing attacks (-fstack-protector)"), groupName, false, false, true, "-fstack-protector",sl);
addOption(CC_CMD_OPT_STACK_PROTECTOR , QObject::tr("Check for stack smashing attacks (-fstack-protector)"), groupName, false, false, true, "-fstack-protector", CompilerOptionType::Choice, sl);
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
sl.clear();
sl.append(QPair<QString,QString>("Address","address"));
sl.append(QPair<QString,QString>("Thread","thread"));
sl.append(QPair<QString,QString>("Leak","leak"));
sl.append(QPair<QString,QString>("Undefined","undefined"));
addOption(CC_CMD_OPT_ADDRESS_SANITIZER , QObject::tr("Enable Sanitizer (-fsanitize=)"), groupName, true, true, true, "-fsanitize=",sl);
addOption(CC_CMD_OPT_ADDRESS_SANITIZER , QObject::tr("Enable Sanitizer (-fsanitize=)"), groupName, true, true, true, "-fsanitize=",CompilerOptionType::Choice,sl);
#endif
// Output
@ -425,7 +430,7 @@ void SDCCCompilerInfo::prepareCompilerOptions()
sl.append(QPair<QString,QString>("Padauk processors-13bit width memory","pdk13"));
sl.append(QPair<QString,QString>("Padauk processors-14bit width memory","pdk14"));
sl.append(QPair<QString,QString>("Padauk processors-15bit width memory","pdk15"));
addOption(SDCC_CMD_OPT_PROCESSOR, QObject::tr("Processor (-m)"), groupName, true, false, false, "-m", sl);
addOption(SDCC_CMD_OPT_PROCESSOR, QObject::tr("Processor (-m)"), groupName, true, false, false, "-m", CompilerOptionType::Choice,sl);
// C++ Language Standards
sl.clear();
@ -439,8 +444,22 @@ void SDCCCompilerInfo::prepareCompilerOptions()
sl.append(QPair<QString,QString>("SDCC C11","sdcc11"));
sl.append(QPair<QString,QString>("SDCC C17","sdcc17"));
sl.append(QPair<QString,QString>("SDCC C2x","sdcc2x"));
addOption(SDCC_CMD_OPT_STD, QObject::tr("Language standard (--std)"), groupName, true, false, false, "--std-", sl);
addOption(SDCC_CMD_OPT_STD, QObject::tr("Language standard (--std)"), groupName, true, false, false, "--std-", CompilerOptionType::Choice,sl);
addOption(SDCC_OPT_XSTACK, QObject::tr("Use external stack"),groupName,true,false,false,"--xstack");
addOption(SDCC_OPT_XRAM_MOVC, QObject::tr("Use movc instead of movx to read from external ram"),groupName,true,false,false,"--xram-movc");
addOption(SDCC_OPT_NO_XINIT_OPT, QObject::tr("Don't memcpy initialized xram from code"),groupName,true,false,false,"--no-xinit-opt");
addOption(SDCC_OPT_NOSTARTUP, QObject::tr("Don't generate startup code"),groupName,false,false,false,"nostartup");
groupName = QObject::tr("MCU Specification");
addOption(SDCC_OPT_IRAM_SIZE, QObject::tr("Internal ram size"), groupName, false, false, true, "--iram-size",CompilerOptionType::Input);
addOption(SDCC_OPT_XRAM_LOC, QObject::tr("External ram start location"), groupName, false, false, true, "--xram-loc",CompilerOptionType::Input);
addOption(SDCC_OPT_XRAM_SIZE, QObject::tr("External ram size"), groupName, false, false, true, "--xram-size",CompilerOptionType::Input);
addOption(SDCC_OPT_STACK_LOC, QObject::tr("Stack pointer initial value"), groupName, false, false, true, "--stack-loc",CompilerOptionType::Input);
addOption(SDCC_OPT_XSTACK_LOC, QObject::tr("External stack start location"), groupName, false, false, true, "--xstack-loc",CompilerOptionType::Input);
addOption(SDCC_OPT_DATA_LOC, QObject::tr("Direct data start location"), groupName, false, false, true, "--data-loc",CompilerOptionType::Input);
addOption(SDCC_OPT_CODE_LOC, QObject::tr("Code segment location"), groupName, false, false, true, "--code-loc",CompilerOptionType::Input);
addOption(SDCC_OPT_CODE_SIZE, QObject::tr("Code segment size"), groupName, false, false, true, "--code-size",CompilerOptionType::Input);
}
#endif

View File

@ -51,6 +51,19 @@
#ifdef ENABLE_SDCC
#define SDCC_CMD_OPT_PROCESSOR "sdcc_cmd_opt_processor"
#define SDCC_CMD_OPT_STD "sdcc_cmd_opt_std"
#define SDCC_OPT_XSTACK "sdcc_opt_xstack"
#define SDCC_OPT_XRAM_MOVC "sdcc_opt_xram_movc"
#define SDCC_OPT_NO_XINIT_OPT "sdcc_opt_no_xinit_opt"
#define SDCC_OPT_NOSTARTUP "sdcc_opt_nostartup"
#define SDCC_OPT_IRAM_SIZE "sdcc_opt_iram_size"
#define SDCC_OPT_XRAM_SIZE "sdcc_opt_xram_size"
#define SDCC_OPT_XRAM_LOC "sdcc_opt_xram_loc"
#define SDCC_OPT_XSTACK_LOC "sdcc_opt_xstack_loc"
#define SDCC_OPT_CODE_LOC "sdcc_opt_code_loc"
#define SDCC_OPT_CODE_SIZE "sdcc_opt_code_size"
#define SDCC_OPT_STACK_LOC "sdcc_opt_stack_loc"
#define SDCC_OPT_DATA_LOC "sdcc_opt_data_loc"
#define SDCC_OPT_NOSTARTUP "sdcc_opt_nostartup"
#endif
@ -67,6 +80,12 @@ enum class CompilerType {
Unknown
};
enum class CompilerOptionType {
Checkbox,
Choice,
Input
};
using CompileOptionChoiceList = QList<QPair<QString,QString>>;
typedef struct {
@ -77,6 +96,7 @@ typedef struct {
bool isCpp; // True (C++ option?) - can be both C and C++ option...
bool isLinker; // Is it a linker param
QString setting; // "-g3"
CompilerOptionType type;
CompileOptionChoiceList choices; // replaces "Yes/No" standard choices (max 30 different choices)
} CompilerOption;
@ -110,6 +130,7 @@ protected:
bool isCpp,
bool isLinker,
const QString& setting,
CompilerOptionType type = CompilerOptionType::Checkbox,
const CompileOptionChoiceList& choices = CompileOptionChoiceList());
virtual void prepareCompilerOptions();
protected:

View File

@ -58,7 +58,6 @@ bool SDCCFileCompiler::prepareForCompile()
mArguments += getCCompileArguments(false);
mArguments += getCIncludeArguments();
mArguments += getProjectIncludeArguments();
mArguments += getLibraryArguments(FileType::CSource);
if (!fileExists(mCompiler)) {
throw CompileError(
@ -74,14 +73,15 @@ bool SDCCFileCompiler::prepareForCompile()
mNoStartup = (val==COMPILER_OPTION_ON);
if (mNoStartup) {
mRelFilename = changeFileExt(mFilename,SDCC_REL_SUFFIX);
mArguments = QString(" -c \"%1\"").arg(mFilename);
mArguments += QString(" -c \"%1\"").arg(mFilename);
mExtraCompilersList.append(mCompiler);
QString args;
args = QString(" -o \"%1\" \"%2\" ").arg(mIhxFilename, mRelFilename);
QString args = getLibraryArguments(FileType::CSource);
args += QString(" -o \"%1\" \"%2\" ").arg(mIhxFilename, mRelFilename);
mExtraArgumentsList.append(args);
mExtraOutputFilesList.append("");
} else {
mArguments = QString(" \"%1\"").arg(mFilename);
mArguments += getLibraryArguments(FileType::CSource);
mArguments += QString(" \"%1\"").arg(mFilename);
mArguments+=QString(" -o \"%1\"").arg(mIhxFilename);
}

View File

@ -6969,6 +6969,54 @@
<source>Don&apos;t generate startup code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use external stack</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use movc instead of movx to read from external ram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Don&apos;t memcpy initialized xram from code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>MCU Specification</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Internal ram size</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>External ram start location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>External ram size</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stack pointer initial value</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>External stack start location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Direct data start location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Code segment location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Code segment size</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RegisterModel</name>

File diff suppressed because it is too large Load Diff

View File

@ -6494,6 +6494,54 @@
<source>Don&apos;t generate startup code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use external stack</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use movc instead of movx to read from external ram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Don&apos;t memcpy initialized xram from code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>MCU Specification</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Internal ram size</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>External ram start location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>External ram size</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Stack pointer initial value</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>External stack start location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Direct data start location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Code segment location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Code segment size</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RegisterModel</name>

View File

@ -20,6 +20,7 @@
#include <QComboBox>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
CompileArgumentsWidget::CompileArgumentsWidget(QWidget *parent) :
QTabWidget(parent)
@ -45,7 +46,9 @@ QMap<QString, QString> CompileArgumentsWidget::arguments( bool includeUnset) con
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(mCompilerType,key);
if (!pOption)
continue;
if (pOption->choices.isEmpty()) {
switch (pOption->type) {
case CompilerOptionType::Checkbox:
{
QCheckBox* pCheckbox = static_cast<QCheckBox *>(pLayout->itemAtPosition(j,1)->widget());
if (pCheckbox->isChecked()) {
args.insert(key,COMPILER_OPTION_ON);
@ -55,7 +58,10 @@ QMap<QString, QString> CompileArgumentsWidget::arguments( bool includeUnset) con
else
args.remove(key);
}
} else {
}
break;
case CompilerOptionType::Choice:
{
QComboBox* pCombo = static_cast<QComboBox *>(pLayout->itemAtPosition(j,2)->widget());
if (!pCombo->currentData().toString().isEmpty()) {
args.insert(key,pCombo->currentData().toString());
@ -66,6 +72,22 @@ QMap<QString, QString> CompileArgumentsWidget::arguments( bool includeUnset) con
args.remove(key);
}
}
break;
case CompilerOptionType::Input:
{
QLineEdit* pText = static_cast<QLineEdit *>(pLayout->itemAtPosition(j,2)->widget());
QString t=pText->text().trimmed();
if (!t.isEmpty())
args.insert(key,t);
else {
if (includeUnset)
args.insert(key,"");
else
args.remove(key);
}
}
break;
}
}
}
}
@ -105,12 +127,17 @@ void CompileArgumentsWidget::resetUI(Settings::PCompilerSet pSet, const QMap<QSt
QLabel* keyLabel = new QLabel(pOption->key,pWidget);
keyLabel->setVisible(false);
pLayout->addWidget(keyLabel,row,0);
if (pOption->choices.isEmpty()) {
switch(pOption->type) {
case CompilerOptionType::Checkbox:
{
QCheckBox* pCheckbox = new QCheckBox(pWidget);
pCheckbox->setText(pOption->name);
pCheckbox->setChecked(options.value(pOption->key,"")==COMPILER_OPTION_ON);
pLayout->addWidget(pCheckbox,row,1,1,2);
} else {
}
break;
case CompilerOptionType::Choice:
{
pLayout->addWidget(new QLabel(pOption->name,pWidget),row,1);
QComboBox* pCombo = new QComboBox(pWidget);
pCombo->addItem("","");
@ -122,6 +149,16 @@ void CompileArgumentsWidget::resetUI(Settings::PCompilerSet pSet, const QMap<QSt
}
pLayout->addWidget(pCombo,row,2);
}
break;
case CompilerOptionType::Input:
{
pLayout->addWidget(new QLabel(pOption->name,pWidget),row,1);
QLineEdit* pInput = new QLineEdit(pWidget);
pInput->setText(options.value(pOption->key,""));
pLayout->addWidget(pInput,row,2);
}
break;
}
}
for (int i=0;i<pTab->count();i++) {
QWidget* pWidget = pTab->widget(i);