From 84add1d08599c9b909aa258643bc1c8d1d576e80 Mon Sep 17 00:00:00 2001 From: Alex Antonov Date: Thu, 2 Dec 2021 14:35:46 +0300 Subject: [PATCH] [mapleall][driver] Dump driver options in debug print printCommandStr was used as "common driver options" string in options dump. printCommandStr was set in MplOptions::HandleGeneralOptions for each common driver option. It's bad idea to set this variable manually for each option, because you can forgot to set it for new option. To improve this logic, this commit adds all common driver options into exeOptions["all"] map. And it's used instead of printCommandStr in options dump. --- .../maple_driver/include/mpl_options.h | 6 +--- .../maple_driver/include/option_descriptor.h | 4 +++ .../maple_driver/src/maple_comb_compiler.cpp | 5 ++- src/mapleall/maple_driver/src/mpl_options.cpp | 32 ++++++++++++++----- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/mapleall/maple_driver/include/mpl_options.h b/src/mapleall/maple_driver/include/mpl_options.h index d724e7518e..6324fa8e68 100644 --- a/src/mapleall/maple_driver/include/mpl_options.h +++ b/src/mapleall/maple_driver/include/mpl_options.h @@ -336,10 +336,6 @@ class MplOptions { return selectedExes; } - const std::string &GetPrintCommandStr() const { - return printCommandStr; - } - bool HasSetDebugFlag() const { return debugFlag; } @@ -397,6 +393,7 @@ class MplOptions { std::string GetInputFileNameForPrint(const Action * const action) const; void PrintCommand(const Action * const action); void connectOptStr(std::string &optionStr, const std::string &exeName, bool &firstComb, std::string &runStr); + std::string GetCommonOptionsStr() const; void PrintDetailCommand(const Action * const action, bool isBeforeParse); inline void PrintDetailCommand(bool isBeforeParse) { PrintDetailCommand(nullptr, isBeforeParse); @@ -442,7 +439,6 @@ class MplOptions { std::vector runningExes = {}; std::vector selectedExes = {}; bool isWithIpa = false; - std::string printCommandStr; std::ostringstream printExtraOptStr; bool debugFlag = false; bool withDwarf = false; diff --git a/src/mapleall/maple_driver/include/option_descriptor.h b/src/mapleall/maple_driver/include/option_descriptor.h index 223ab308c0..f1e83553e8 100644 --- a/src/mapleall/maple_driver/include/option_descriptor.h +++ b/src/mapleall/maple_driver/include/option_descriptor.h @@ -111,6 +111,10 @@ class Option { return descriptor.type; } + const std::string &GetExeName() const { + return descriptor.exeName; + } + OptionPrefixType GetPrefixType() const { return prefixType; } diff --git a/src/mapleall/maple_driver/src/maple_comb_compiler.cpp b/src/mapleall/maple_driver/src/maple_comb_compiler.cpp index 5794a1f537..e7384c1006 100644 --- a/src/mapleall/maple_driver/src/maple_comb_compiler.cpp +++ b/src/mapleall/maple_driver/src/maple_comb_compiler.cpp @@ -94,9 +94,12 @@ void MapleCombCompiler::PrintCommand(const MplOptions &options, const Action &ac optionStr << " --" << opt.OptionKey() << connectSym << opt.Args(); } } + + std::string driverOptions = options.GetCommonOptionsStr(); + optionStr << "\""; LogInfo::MapleLogger() << "Starting:" << options.GetExeFolder() << "maple " << runStr << " " << optionStr.str() << " " - << GetInputFileName(options, action) << options.GetPrintCommandStr() << '\n'; + << driverOptions << " " << GetInputFileName(options, action) << '\n'; } ErrorCode MapleCombCompiler::MakeMeOptions(const MplOptions &options, DriverRunner &runner) { diff --git a/src/mapleall/maple_driver/src/mpl_options.cpp b/src/mapleall/maple_driver/src/mpl_options.cpp index efa8efba48..733fce8311 100644 --- a/src/mapleall/maple_driver/src/mpl_options.cpp +++ b/src/mapleall/maple_driver/src/mpl_options.cpp @@ -199,22 +199,18 @@ ErrorCode MplOptions::HandleGeneralOptions() { break; case kTimePhases: timePhases = true; - printCommandStr += " -time-phases"; break; case kGenMeMpl: genMeMpl = true; - printCommandStr += " --genmempl"; break; case kGenVtableImpl: genVtableImpl = true; - printCommandStr += " --genVtableImpl"; break; case kSaveTemps: isSaveTmps = true; genMeMpl = true; genVtableImpl = true; StringUtils::Split(opt.Args(), saveFiles, ','); - printCommandStr += " --save-temps"; break; case kOption: if (UpdateExtraOptionOpt(opt.Args()) != kErrorNoError) { @@ -317,7 +313,6 @@ ErrorCode MplOptions::DecideRunType() { break; case kGenObj: genObj = true; - printCommandStr += " -c"; break; case kMaplePhaseOnly: runMaplePhaseOnly = (opt.Type() == kEnable) ? true : false; @@ -636,6 +631,12 @@ ErrorCode MplOptions::CheckFileExits() { ErrorCode MplOptions::AddOption(const mapleOption::Option &option) { if (!option.HasExtra()) { + if (option.GetExeName() == "all") { + /* If it doesn't have extra options and it's a common option for driver, + * set this option in exeOptions as "all"" to use this info in debug print. + */ + exeOptions[option.GetExeName()].push_back(option); + } return kErrorNoError; } for (const auto &exeName : option.GetExtras()) { @@ -649,6 +650,19 @@ ErrorCode MplOptions::AddOption(const mapleOption::Option &option) { return kErrorNoError; } +std::string MplOptions::GetCommonOptionsStr() const { + std::string driverOptions; + auto it = exeOptions.find("all"); + if (it != exeOptions.end()) { + for (const mapleOption::Option &opt : it->second) { + auto connectSym = !opt.Args().empty() ? "=" : ""; + driverOptions += " --" + opt.OptionKey() + connectSym + opt.Args(); + } + } + + return driverOptions; +} + InputInfo *MplOptions::AllocateInputInfo(const std::string &inputFile) { auto inputInfo = std::make_unique(inputFile); InputInfo *ret = inputInfo.get(); @@ -885,10 +899,11 @@ void MplOptions::PrintCommand(const Action * const action) { optionStr << " -O2"; } + std::string driverOptions = GetCommonOptionsStr(); auto inputs = (action == nullptr) ? GetInputFiles() : GetInputFileNameForPrint(action); LogInfo::MapleLogger() << "Starting:" << exeFolder << "maple " << optionStr.str() << " " - << printExtraOptStr.str() << printCommandStr << " " << inputs << '\n'; + << printExtraOptStr.str() << driverOptions << " " << inputs << '\n'; } if (runMode == RunMode::kCustomRun) { PrintDetailCommand(action, true); @@ -929,14 +944,15 @@ void MplOptions::PrintDetailCommand(const Action * const action, bool isBeforePa connectOptStr(optionStr, kBinNameMplcg, firstComb, runStr); optionStr += "\""; + std::string driverOptions = GetCommonOptionsStr(); auto inputs = (action == nullptr) ? GetInputFiles() : GetInputFileNameForPrint(action); if (isBeforeParse) { LogInfo::MapleLogger() << "Starting:" << exeFolder << "maple " << runStr << " " << optionStr << " " - << printExtraOptStr.str() << printCommandStr << " " << inputs << '\n'; + << printExtraOptStr.str() << driverOptions << " " << inputs << '\n'; } else { LogInfo::MapleLogger() << "Finished:" << exeFolder << "maple " << runStr << " " << optionStr << " " - << printCommandStr << " " << inputs << '\n'; + << driverOptions << " " << inputs << '\n'; } } } // namespace maple -- Gitee