📄 optionsdlg.cpp
字号:
//---------------------------------------------------------------------------
void __fastcall TOptDlg::BssSecBoxClick(TObject *Sender)
{
BssSection->Enabled = BssSecBox->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::HeapStartBoxClick(TObject *Sender)
{
HeapStartEd->Enabled = HeapStartBox->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::HeapEndBoxClick(TObject *Sender)
{
HeapEndEd->Enabled = HeapEndBox->Checked;
}
//---------------------------------------------------------------------------
int __fastcall TOptDlg::HexToInt (AnsiString hex)
{
int i, r;
for (i = 0, r = 0;i < hex.Length ();i++)
{
r *= 16;
if (hex[i + 1] <= '9') r += hex[i + 1] - '0';
else r += hex[i + 1] - 'A' + 10;
}
return r;
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::PartWarnClick(TObject *Sender)
{
if (PartWarn->Checked) PartBoxEnable (false);
else PartBoxEnable (true);
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::GenMapClick(TObject *Sender)
{
CRef->Enabled = GenMap->Checked;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TOptDlg::GetCompilerOptions (AnsiString fname, int out)
{
AnsiString copt, temp;
int i;
copt = "\"" + DirDlg->Bin_Dir + "avr-gcc.exe\" ";
copt += " -mmcu=" + options.MCUType;
switch (options.StdGroup)
{
case 0: copt += " -std=c89 ";
break;
case 1: copt += " -std=gnu89 ";
break;
case 2: copt += " -std=c99 ";
break;
default: copt += " -std=gnu99 ";
}
switch (out)
{
case OUTP_ASM: copt += "-S -save-temps ";
break;
default: copt += "-c ";
if (options.GenList) copt += "-Wa,-ahlms=\"" + ChangeExt (fname, ".lst") + "\"";
}
copt += " \"" + fname + "\"";
//if (out == OUTP_OBJ) "-o \"" + ChangeExt (fname, ".o") + "\"";
temp = DirDlg->Inc_Dir;
while (temp != NULL)
{
i = temp.Pos (";");
if (i == 0)
{
copt += " -I\"" + temp + "\"";
break;
}
else copt += " -I\"" + temp.SubString (1, i - 1) + "\"";
temp.Delete (1, i);
}
switch (options.DbgGroup)
{
case 1:
case 2:
case 3: copt += " -gstabs";
break;
case 4: copt += " -gdwarf-2";
break;
}
if (options.TinyStack) copt += " -mtiny-stack";
switch (options.OptimBox)
{
case 1: copt += " -O1";
break;
case 2: copt += " -O2";
break;
case 3: copt += " -O3";
break;
case 4: copt += " -Os";
}
// --------- Add Warning Parameters ------------------
if (options.NoWarn)
{
copt += " -fsyntax-only";
}
else
{
if (options.AllWarn) copt += " -W";
else
{
if (options.PartWarn) copt += " -Wall";
else
{
if (options.PedaWarn) copt += " -pedantic";
if (options.NoImpWarn) copt += " -Wno-import";
if (options.CharSubsWarn) copt += " -Wchar-subscripts";
if (options.ComWarn) copt += " -Wcomment";
if (options.FormWarn) copt += " -Wformat";
if (options.ImplWarn) copt += " -Wimplicit";
if (options.BracWarn) copt += " -Wmissing-braces";
if (options.ParWarn) copt += " -Wparentheses";
if (options.RetTypWarn) copt += " -Wreturn-type";
if (options.SwitchWarn) copt += " -Wswitch";
if (options.SwiDefWarn) copt += " -Wswitch-default";
if (options.UnusWarn) copt += " -Wunused";
if (options.UninitWarn) copt += " -Wuninitialized";
if (options.PragWarn) copt += " -Wunknown-pragmas";
}
if (options.SysHeadWarn) copt += " -Wsystem-headers";
if (options.UndefWarn) copt += " -Wundef";
if (options.EndifWarn) copt += " -Wendif-labels";
if (options.ProtWarn) copt += " -Wstrict-prototypes";
if (options.NestWarn) copt += " -Wnested-externs";
if (options.InlineWarn) copt += " -Winline";
if (options.UnreaWarn) copt += " -Wunreachable-code";
}
}
copt += " " + options.AddComp;
return copt;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TOptDlg::ChangeExt (AnsiString Source, AnsiString ext)
{
AnsiString obj;
obj = Source;
obj.Delete (obj.Pos (ExtractFileExt (obj)), 3);
obj += ext;
return obj;
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::PartBoxEnable (bool e)
{
PedaWarn->Enabled = e;
NoImpWarn->Enabled = e;
CharSubsWarn->Enabled = e;
ComWarn->Enabled = e;
FormWarn->Enabled = e;
ImplWarn->Enabled = e;
BracWarn->Enabled = e;
ParWarn->Enabled = e;
RetTypWarn->Enabled = e;
SwitchWarn->Enabled = e;
SwiDefWarn->Enabled = e;
UnusWarn->Enabled = e;
UninitWarn->Enabled = e;
PragWarn->Enabled = e;
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::AllBoxEnable (bool e)
{
if (PartWarn->Checked && e) PartBoxEnable (false);
else PartBoxEnable (e);
SysHeadWarn->Enabled = e;
UndefWarn->Enabled = e;
EndifWarn->Enabled = e;
ProtWarn->Enabled = e;
NestWarn->Enabled = e;
InlineWarn->Enabled = e;
UnreaWarn->Enabled = e;
PartWarn->Enabled = e;
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::NoBoxEnable (bool e)
{
if (AllWarn->Checked && e) AllBoxEnable (false);
else AllBoxEnable (e);
AllWarn->Enabled = e;
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::AllWarnClick(TObject *Sender)
{
if (AllWarn->Checked) AllBoxEnable (false);
else AllBoxEnable (true);
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::NoWarnClick(TObject *Sender)
{
if (NoWarn->Checked) NoBoxEnable (false);
else NoBoxEnable (true);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TOptDlg::GetLinkerOptions (TStringList *flist)
{
AnsiString lopt, temp;
int i;
lopt = "\"" + DirDlg->Bin_Dir + "avr-gcc.exe\"";
lopt += " -o \"" + OutputName + ".elf\"";
// ---------------------- Object File List --------------------
for (i = 0;i < flist->Count;i++)
{
lopt += " \"" + ChangeExt (flist->Strings[i], ".o") + "\"";
}
// ------------------------- Add MCU Type --------------------------
lopt += " -mmcu=" + options.MCUType;
// ------------------ Generate Map/CrossReference File ----------------
if (options.GenMap)
{
lopt += " -Wl,-Map=\"" + OutputName + ".map\"";
if (options.CRef) lopt += ",--cref";
}
// ------------------------ Add Math Library -----------------------
if (options.MathBox) lopt += " -lm";
// ---------------- printf/scanf version ------------------------
if (options.prntGroup != 0)
{
if (options.prntGroup == 2) lopt += " -Wl,-u,vfprintf -lprintf_flt";
else lopt += " -Wl,-u,vfprintf -lprintf_min";
}
if (options.scnGroup != 0)
{
if (options.scnGroup == 2) lopt += " -Wl,-u,vfscanf -lscanf_flt";
else lopt += " -Wl,-u,vfscanf -lscanf_min";
}
// ---------------- Additional Search Locations for Libraries --------------
temp = DirDlg->Lib_Dir;
while (temp != NULL)
{
i = temp.Pos (";");
if (i == 0)
{
lopt += " -L\"" + temp + "\"";
break;
}
else lopt += " -L\"" + temp.SubString (1, i - 1) + "\"";
temp.Delete (1, i);
}
// ------------------ Locate Memory Sections -----------------------
temp.printf (" -Wl,--section-start=.text=0x%x", TextStart);
if (RelocText) lopt += temp;
temp.printf (" -Wl,-Tdata=0x%x", DataStart);
if (RelocData) lopt += temp;
temp.printf (" -Wl,-Tbss=0x%x", BssStart);
if (RelocBss) lopt += temp;
temp.printf (" -Wl,--defsym=__heap_end=0x%x", HeapEnd);
if (DefHeapEnd) lopt += temp;
temp.printf (" -Wl,--defsym=__heap_start=0x%x", HeapStart);
if (DefHeapStart) lopt += temp;
// ------------------ Additional Linker Options --------------------
if (options.AddLink != NULL) lopt += " " + options.AddLink;
return lopt;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TOptDlg::GetObjcopyOptions (AnsiString *out, int t)
{
AnsiString ocopt, output;
switch (t)
{
case 0: ocopt = " -O " + options.OutputFormat + " \"" + OutputName + ".elf\" ";
if (options.OutputFormat == "ihex") output = OutputName + ".hex";
if (options.OutputFormat == "srec") output = OutputName + ".src";
if (options.OutputFormat == "binary") output = OutputName + ".bin";
ocopt += "\"" + output + "\"";
*out = ExtractFileName (output);
break;
case 1: ocopt = "--debugging --change-section-address .data-0x800000 ";
ocopt += "--change-section-address .bss-0x800000 ";
ocopt += "--change-section-address .noinit-0x800000 ";
ocopt += "--change-section-address .eeprom-0x810000 ";
if (options.DbgGroup == 2) ocopt += " -O coff-avr ";
else ocopt += " -O coff-ext-avr ";
ocopt += "\"" + OutputName + ".elf\" \"" + OutputName + ".cof\"";
output = OutputName + ".cof";
*out = ExtractFileName (output);
break;
case 2: ocopt = " -j .eeprom --set-section-flags=.eeprom=\"alloc,load\" ";
ocopt += "-O " + options.OutputFormat + " \"" + OutputName;
ocopt += ".elf \" \"" + OutputName + ".eep\"";
output = OutputName + ".eep";
*out = ExtractFileName (output);
break;
}
return ocopt;
}
//---------------------------------------------------------------------------
void __fastcall TOptDlg::StdButtonClick(TObject *Sender)
{
AnsiString temp;
Form1->EnvIni->WriteString ("Options", "AddCompOpt", AddComp->Text);
Form1->EnvIni->WriteString ("Options", "AddLinkOpt", AddLink->Text);
Form1->EnvIni->WriteBool ("Options", "ListFile", GenList->Checked);
switch (FormatGroup->ItemIndex)
{
case 0: temp = "binary";
break;
case 1: temp = "ihex";
break;
case 2: temp = "srec";
}
Form1->EnvIni->WriteString ("Options", "Format", temp);
Form1->EnvIni->WriteString ("Options", "MCUType", MCUBox->Items->Strings[MCUBox->ItemIndex]);
Form1->EnvIni->WriteBool ("Options", "MapFile", GenMap->Checked);
Form1->EnvIni->WriteBool ("Options", "CrossReference", CRef->Checked);
Form1->EnvIni->WriteBool ("Options", "TinyStack", TinyStack->Checked);
Form1->EnvIni->WriteInteger ("Options", "DebugOut", DbgGroup->ItemIndex);
Form1->EnvIni->WriteBool ("Options", "GenEEPROM", GenEEPROM->Checked);
Form1->EnvIni->WriteBool ("Options", "MathLib", MathBox->Checked);
Form1->EnvIni->WriteInteger ("Options", "PrintfVers", prntGroup->ItemIndex);
Form1->EnvIni->WriteInteger ("Options", "ScanfVers", scnGroup->ItemIndex);
Form1->EnvIni->WriteBool ("Options", "RelocTextStart", TexSecBox->Checked);
Form1->EnvIni->WriteInteger ("Options", "TextStart", HexToInt (TextSection->Text));
Form1->EnvIni->WriteBool ("Options", "RelocDataStart", DatSecBox->Checked);
Form1->EnvIni->WriteInteger ("Options", "DataStart", HexToInt (DataSection->Text) + 0x800000);
Form1->EnvIni->WriteBool ("Options", "RelocBssStart", BssSecBox->Checked);
Form1->EnvIni->WriteInteger ("Options", "BssStart", HexToInt (BssSection->Text) + 0x800000);
Form1->EnvIni->WriteBool ("Options", "DefHeapStart", HeapStartBox->Checked);
Form1->EnvIni->WriteInteger ("Options", "HeapStart", HexToInt (HeapStartEd->Text) + 0x800000);
Form1->EnvIni->WriteBool ("Options", "DefHeapEnd", HeapEndBox->Checked);
Form1->EnvIni->WriteInteger ("Options", "HeapEnd", HexToInt (HeapEndEd->Text) + 0x800000);
Form1->EnvIni->WriteBool ("Options", "SaveTemp", SaveTempBox->Checked);
Form1->EnvIni->WriteInteger ("Options", "CStandard", StdGroup->ItemIndex);
Form1->EnvIni->WriteBool ("Options", "WarnPedantic", PedaWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnNoImport", NoImpWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnCharSubs", CharSubsWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnComment", ComWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnFormat", FormWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnImplicit", ImplWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnMissingBrac", BracWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnParentheses", ParWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnReturnType", RetTypWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnSwitch", SwitchWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnSwitchDef", SwiDefWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnUnused", UnusWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnUnitialized", UninitWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnUnknPrag", PragWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnSysHead", SysHeadWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnUndef", UndefWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnEndif", EndifWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnStrictProt", ProtWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnNestExt", NestWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnInline", InlineWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnUnreachable", UnreaWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnAll", AllWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnPartially", PartWarn->Checked);
Form1->EnvIni->WriteBool ("Options", "WarnNo", NoWarn->Checked);
Form1->EnvIni->WriteInteger ("Options", "Optimization", OptimBox->ItemIndex);
Form1->EnvIni->WriteBool ("Options", "ExtListing", ExtLst->Checked);
Form1->EnvIni->WriteBool ("Options", "SymbolTable", SymTab->Checked);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -